Category Archives: Coding


   

Multiple Submit Buttons on Forms: Part II

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”>
</form>

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:

http://www.urlkazoo.com/action.php?Submit_1=Submit

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
if (isset($_REQUEST["Submit_1"]))
{
$button = 1;
}
// Test is Submit_2 is defined
if (isset($_REQUEST["Submit_2"]))
{
$button = 2;
}
// Test is Submit_3 is defined
if (isset($_REQUEST["Submit_3"]))
{
$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.

Good Luck!


   

Why doesn’t my CSS work?

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:

  1. Missing bracket
  2. Missing semicolon
  3. Misspelled Class or ID
  4. Misspelled Properties or Value
  5. 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
http://jigsaw.w3.org/css-validator/

and gave it the URI to my CSS stylesheet.
They found the error.

Good Luck!

Multiple Submit Buttons on Forms

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:
action=default.html
Both buttons are of type Submit, but they have different values, which reflect what the buttons actually say.

The command in the first button
onclick=”this.form.target=’_blank’;return true;”
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.

Making Things Talk

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:

  1. Making a computer “mouse” out of a stuffed animal monkey and flex sensors.
  2. Making the monkey wireless
  3. Negotiating in Bluetooth with the BlueSMiRF module
  4. Setting up a networked webcam
  5. Connecting a microcontroller to the internet without a computer
  6. Networked Air Quality Meter
  7. Networked Games
  8. Infrared Communication
  9. Radio Communication
  10. Duplex Radio Communication
  11. Bluetooth Communication
  12. Broadcasting Messaging
  13. Directed Messaging
  14. Infrared Rangefinding
  15. Ultrasonic Rangefinding
  16. Reading Signal Strength with XBee Radios
  17. Reading Signal Strength with Bluetooth Radios
  18. Reading the GPS Serial Protocol
  19. Heading with a Digital Compass
  20. Attitude with an Accelerometer
  21. Color Recognition with a Webcam
  22. 2D Barcode Recognition with a Webcam
  23. Reading RFID Tags
  24. RFID and Home Automation
  25. IP Geocoding
  26. 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!

Kevin Knuth
Albany NY
 

My First Google Gadget

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:

  1. <ModulePrefs>, which encodes the properties of the gadget.
  2. <UserPref>, which encodes the user information.
  3. <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.

Kevin Knuth
Albany NY