I have included an additional Submit button within my form which I am going to use like so.
- User selects item
- User hits “Add another item” Submit button on form.
- Form POSTS to itself and reloads the page so user can add another item
- Once user has added several items the user hits “Finished” Submit button.
- The form posts to another file with all the accumulated items.
I have a uneasy feeling that this might not be achievable with PHP/HTML alone and that I might have to use some Javascript to modify the form action before the form starts to POST data?
Thoughts and ideas?
Thanks
You can use JavaScript to modify the form based on which button is clicked, or you can check server side (i.e. using PHP) which button was clicked and act accordingly.
A submit-button is a form-input just like any other, i.e. you can give it a name and a value, which you can check for server side.
On client side (i.e. using JavaScript) you would bind a handler to the button’s click-event, modify the form’s action-attribute and submit it to the new address.
Here’s a client side example:
Just for sake of completeness, here’s a jQuery-example of the same: