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!

Posted under Coding, Internet, Programming, Software, Space, Uncategorized

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!

Posted under Coding, Internet, Programming, Software

This post was written by drknuth on February 18, 2009

Tags:

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.

Posted under Coding, Internet, Programming, Software, Solutions

This post was written by drknuth on February 14, 2009

Tags:

MATLAB Packages for the NXT

Brickengineer announces MATLAB packages for the LEGO NXT Robotics system:

There are now several MATLAB packages for robotics, and specifically for the NXT. One paradigm is to run the code on a PC and have it communicate direct commands to the NXT Brick via Bluetooth or USB. I have found this paradigm to be a bit dangerous since in the event of a MATLAB crash or a miscommunication, the NXT Brick will continue with its last command until ordered to stop. This has the potential to destroy your robot. The paradigm that I prefer to use is to write several programs that run on the brick. These programs take commands from files on the brick that can be uploaded rapidly from the PC. The MATLAB code then is in charge of sending the command files and starting and stopping programs. In the event of a MATLAB crash or communication failure, the software running on the NXT Brick can be designed to terminate gracefully.

Here are the MATLAB packages that I know of. The first two are specifically geared toward the NXT; whereas the last is a general robotics package.

* LEGO MINDSTORMS NXT Toolkit for MATLAB and Simulink
http://www.mathworks.com/programs/mindstorms/
* Robotics Toolbox for MATLAB (Release 7.1) (P.I. Corke)
http://petercorke.com/Robotics%20Toolbox.html
* RWTH Mindstorms NXT Toolbox for Matlab
http://www.mindstorms.rwth-aachen.de/

Posted under Lego, Programming, Research, Robotics, Software

This post was written by drknuth on February 11, 2009

Tags: , , , ,

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

This is a note on an error that I have gotten several times when writing php scripts with mySQL.

The error is:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

The offending code snippet essentially looks like this:

$result = mysql_query(”$query_STRING” );
if (mysql_num_rows($result) > 0)
{

which then continues on…

Note that $query_STRING is a string variable that contains the mySQL query.

The problem with this error message is that it is typically due to a problem in the query itself, and there can be many causes.  To catch the cause, change the line that performs the query to:

$result = mysql_query(”$query_STRING” ) or die(mysql_error());

The statement die(mysql_error()) will catch the true error and with luck give you a more meaningful error message.

Posted under Programming, Software

This post was written by drknuth on January 31, 2009

Tags: , , ,