Jump to content

Multiple Buttons in a form


NathanLedet

Recommended Posts

So I have a form with a load of check boxes.  User can select 1 or all of the check boxes, and then at the bottom of the form, there are two submit buttons.

 

<input type="submit" name="remove" id="remove" value="Remove" />
<input type="submit" name="modify" id="modify" value="Modify" />

 

So, when I choose one of those submit buttons, my form action posts to something like "decision.php"

 

My array of selections is then posted to that php file - and based on what was pushed (modify or delete), that array of data is then pushed on to a new file (modify.php or remove.php) that then processes it. 

 

Is this logic correct? or is there a simpler way? 

 

If this logic is correct, then I'm not sure how to again post my data on to modify or remove...

Link to comment
Share on other sites

you can't push it to a new page, both the modify/delete code has to be handled by the decision.php script. this is easy enough though...you can either put all the code in one file, or create a function for each and just call the appropriate function

Link to comment
Share on other sites

I think the "deleting" portion can be handled quite easily by calling a delete function into "decision.php"

 

However, "modify.php" contains forms and that sort of thing that would require a bit more.

 

Would it be bad practice to set those checkbox values into an array in a session? and as soon as that's done - destroy the session?

Link to comment
Share on other sites

um...it's not "bad"...just be careful to clear those out

 

you can also pass the items to be modified in a GET variable when forwarding to modify.php:

$keys = array(1,4,6,7,9);
header('Location: modify.php?keys='.implode('|',$keys));
exit;

the just explode the values on modify.php to know which ones you are modifying

Link to comment
Share on other sites

Personally, I would use similar logic to what you first described - execept that the initial processing page will first validate the submitted data. If validation fails I will redisplay the form with the values the user entered already populated/selected. If validation passes I will detemine the correct process to perform and include() the appropriate processing file. That way all of the GET/POST values are still available to the processing script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.