This is Part II in a discussion on how to incorporate multiple submit buttons on html forms.
Part I focused on having multiple submit buttons that performed completely different actions, such as going to different web pages. Here we consider multiple submit buttons that launch the same php application, but take different actions within that application.
Here we have a simple form with three submit buttons:
<form name=”categories” method=”get” action=”action.php”>
<input type=”submit” name=”Submit_1″ value=”Submit”>
<input type=”submit” name=”Submit_2″ value=”Submit”>
<input type=”submit” name=”Submit_3″ value=”Submit”>
I am using the get method so that you can see what actually gets sent along with the url.
When you click on Submit_1 you see this URL:
You can see that it is passing the name of the Submit button as a parameter. To use this information, one simply needs to identify which parameter is being passed. We can do this in the php code in action.php. Here is a php snippet:
// Test is Submit_1 is defined
$button = 1;
// Test is Submit_2 is defined
$button = 2;
// Test is Submit_3 is defined
$button = 3;
Of course the code above can be simplified using else statements.
But the point is to demonstrate that we can determine which button was pressed by figuring out which button’s name has been passed along as a parameter.
From here you can go on to perform different functions based on which submit button was pressed.
It seems that I am always banging my head against the CSS wall screaming “What is wrong with my CSS code?” and “Why doesn’t it work?” Today I came across the blog CSSNewbie and they had a nice article on the top five reasons why CSS doesn’t work.
The basic reasons are:
- Missing bracket
- Missing semicolon
- Misspelled Class or ID
- Misspelled Properties or Value
- Bad CSS Value
Guess which one haunted me?
#1 of course!
What I didn’t know is that CSS loads until there is an error and then it stops. I had a CSS file that I linked to in the <head> section of my page and after it I had some style tags with some additional CSS definitions. I saw that half of my CSS stylesheet worked and the other half didn’t, but the commands listed after the included stylesheet worked. So I was very confused.
It turns out that the CSS stylesheet stopped loading after the parse error, so only the commands defined in the beginning worked. But when it got to the new style tags, it read those just fine.
To find the error, I used a CSS Validator.
Specifically, I went to:
W3C CSS Validation Service
and gave it the URI to my CSS stylesheet.
They found the error.
I recently encountered the challenge of including multiple submit buttons on an html form. Wading through the noise on various blogs and help sites was painful. I finally found the following solution that works, and decided to post this little tutorial…
<form name=myFORM type=post action=default.html>
<input type=’submit’ value=’Open Default Site’ onclick=”this.form.target=’_blank';return true;”>
<input type=’submit’ value=’Open Special Site’ onclick=”myFORM.action=’special.html'; return true;”> </form>
Note that the default action of the form is defined in the first line by:
Both buttons are of type Submit, but they have different values, which reflect what the buttons actually say.
The command in the first button
instructs it to follow the default action, which is to open default.html in a new window (indicated by target=’_blank’).
The command in the second button
onclick=”myFORM.action=’special.html'; return true;”
instructs it to take on a new action, which is to open special.html
You can keep adding additional submit buttons this way.
Looking back, I am surprised at how electronics has quietly advanced to the point where we can buy small programmable computers on chips for a dollar or two. These are microcontrollers of course, and in my lab we are working on programming them to handle the tedious tasks in our robotics projects.
At makezine.com, I stumbled on this gem of a book titled “Making Things Talk”
It is packed with 26 electronics projects that involve getting these tiny computers to talk to each other and the internet over both wired and wireless connections. I have ordered all the requisite parts, and when purchased, they amount to around $280. I am looking forward to summer vacation when I get to go through each of these projects one-by-one:
- Making a computer “mouse” out of a stuffed animal monkey and flex sensors.
- Making the monkey wireless
- Negotiating in Bluetooth with the BlueSMiRF module
- Setting up a networked webcam
- Connecting a microcontroller to the internet without a computer
- Networked Air Quality Meter
- Networked Games
- Infrared Communication
- Radio Communication
- Duplex Radio Communication
- Bluetooth Communication
- Broadcasting Messaging
- Directed Messaging
- Infrared Rangefinding
- Ultrasonic Rangefinding
- Reading Signal Strength with XBee Radios
- Reading Signal Strength with Bluetooth Radios
- Reading the GPS Serial Protocol
- Heading with a Digital Compass
- Attitude with an Accelerometer
- Color Recognition with a Webcam
- 2D Barcode Recognition with a Webcam
- Reading RFID Tags
- RFID and Home Automation
- IP Geocoding
- Email from RFID
OK, I wont be making each of these. I will get an idea halfway through and take off and work on that. But it should be fun!
I have just submitted my first Google Gadget.
It is called Bird of the Day, and it simply presents a photo of a new bird species each day. The photo is a public domain image from Wikipedia, and I link back to it so that you can get more information.
Here it is:
You can put it on your iGoogle page by clicking here…
I am going to write a few other versions that will complement my BirdPlanner.com site. The first will be a modification of the above where the user can enter their latitude and longitude to get birds that are present in that locale. That way people can prepare for their birdwatching trips.
I will also try writing one which is a Bird Identification Quiz. It will be a multiple choice quiz. I can vary the difficulty by sampling from birds of the same genus, from the same family, or from the whole set of birds.
This is a fun way for me to become familiar with the computational technology. The google gadget is just an XML file. The tag <Module> identifies it as a Google Gadget.
The remaining XML has three parts:
- <ModulePrefs>, which encodes the properties of the gadget.
- <UserPref>, which encodes the user information.
- <Content>, which encodes the content.
My gadget is pretty straightforward. There are no User Preferences, so I just have the first and last sections.
You can look at the xml code here. You will see that the workhorse of the content section is a php file that emits an html file. In this case the gadget simply holds a simple web page.
In the future, I will write more details about how all of this works.