[FX.php List] One Button, two forms/scripts?

Kevin Futter kfutter at sbc.melb.catholic.edu.au
Sun Oct 9 17:02:14 MDT 2005


On 7/10/05 9:15 PM, "Marisa Smith" <marisa at datasmithconsulting.net> wrote:

> Jonathan - you can also use Javascript to submit the form and switch the php
> response page by passing a different action parameter to the form.
> 
> In this case, you would only have ONE form on your page (Note the name value
> I added to make it easier to refer to in the javascript- you can use
> whatever you want here, just be sure to pass it in the link below):
> 
> <form method="post" action="edit_response.php" name="myform">
> <input type="hidden" name="recid" value="<?php echo $recid; ?>">
> <input type="image" name="refresh"  src="images/refresh.gif">
> </form>
> 
> 
> Your buttons (I usually use links) would look like this:
> <a href="javascript: goSave(document.myform, 'edit_response.php');">Save &
> Refresh</a>
> 
> <a href="javascript: goSave(document.myform, 'approve.php');">Save &
> Continue</a>

Just be aware that the javascript: pseudo protocol is invalid, and that this
method will fail completely for any user with JavaScript disabled. You
should always give a complete and valid URI for the HREF attribute, and then
return false on the JavaScript statement. Eg:

<a href="approve.php" onclick="goSave(document.myform,'approve.php'); return
false;">Save &amp; Continue</a>

You'll also notice from the example that you should encode your ampersands
with the corresponding entity.

-- 
Kevin Futter
Webmaster, St. Bernard's College
http://www.sbc.melb.catholic.edu.au/





More information about the FX.php_List mailing list