General discussion


Handling multiple submits in a single form with PHP

By RexWorld ·
article root

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Anyone used this alternate approach?

by RexWorld In reply to Handling multiple submits ...

One possible alternative way of dealing with multiple-button forms is to attach an onClick() event handler to each button that changes the form <action> through JavaScript. So instead of using a single PHP script, you could actually have different scripts for different actions, with JavaScript taking care of changing the form action using code like this:

<input type="submit" onClick="document.forms[0].action='action1.php'">
<input type="submit" onClick="document.forms[0].action='action2.php'">

and so on. Has anyone tried this, and what were the results?

Collapse -

RE:Alternate Approach

by billc In reply to Anyone used this alternat ...

If javascript is disabled, the fail-over method would require you to handle both of the submit buttons in the form's action url anyway.

Related Discussions

Related Forums