I am wanting to submit a form to different places based on selections made in the form. I had originally been planning to to send all to a central file/location and have it determine where to go next. However, I would like to do without this extra step if I could.
If the user wants to create/edit/delete elements go to page 1.
If the user wants to group/attach elements go to page 3.
I am trying to write a form builder. You can create/edit/delete forms, questions, and answers. I have everything for creating, editing, and deleting done. Those functions are performed without leaving the page, but now I am looking to assign answers to specific questions. The questions page and the answers page are separate. I am wanting to select a group of answers and submit an array of answer Ids (selected check boxes) to the question page where those Ids will then be assigned to a question. So basically the create, edit, and delete functions are on without leaving the page, but the assign function would be performed on a different page.
if(empty($delRowID) || empty(updateRowID) || empty($groupRows)) {
qInsert();
}else{
if(!empty($delRowID)) qDelete($delRowID);
if(!empty(updateRowID)) qUpdate($updateRowID);
if(!empty($groupRows)) {
submit $groupRows to Question.php;
}
}
If I was looking at doing this I would pass a vaule of what you want doing by POST.
Then check that value against a set of functions and each function will do a different thing based on it selection
No, a form has only one action.
But you have options:
Javascript
However, you may change the action attribute with javascript:
together with a little javascript:
See also
Multiple forms
If javascript is not an option for you, you may consider multiple forms in your page.
No problems with javascript disabled clients, and standards compliant.
Multiple submit buttons - server side
Or you may handle the distinction of editing or deleting on the server side. No javascript needed.
Add multiple submit buttons to your form and give them the same name but a different value:
You then can retrieve the value of the button which has been clicked. In php, the following should do the job:
See http://www.chami.com/tips/internet/042599I.html for an example with classic asp.
Just send them to a central location and use logic to send them somewhere else depending on what they selected.
eg:
(obviously needs some input filtering and default values)
EDIT: as pointed out by Col. Shrapnel below, using
header()
for this is pretty pointless as it'll then wipe out your $_POST array - useinclude()
instead, but be careful to only allow your own files and never let the user name the file which will be included (eg using a form field value to pick the included file).No, you can't have multiple actions just in the html, but you can use javascript to switch up the action depending on what button is hit.
I would do something like this (in pseudo-mootools)
No, it can't (at least not without depending on JavaScript).
Submit to one URI, and have a dispatch routine pass the data off to different functions depending on which radio button (or whatever) is selected.
on Submit page you can call CURL and give all Get or post variables to that url.