Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

How Handle Sending Back Multiple Checkboxes

Recommended Posts

I know how to send back the check-boxes, so that's not the issue.I have a form that contains a group of 5 check-boxes.The user could select none, one, all, or any combination in between.I'm working on form validation right now and am doing most of it server side. The validation is set so that if the user has to go back all their data is retained.I'm using case statements, which work wonderfully, but in this circumstance I don't know what would be the best method that allows for a multitude of combinations. I think there is a possibility of something like 120 different combinations.What I want is for the check-boxes that were selected to be checked when it's sent back to the form.Would it be better to just send each box as its own separate entity and evaluate it that way?Thanks!kvarnerexpress

Share this post


Link to post
Share on other sites

I know how to send back the check-boxes, so that's not the issue.

 

I have a form that contains a group of 5 check-boxes.

 

The user could select none, one, all, or any combination in between.

 

I'm working on form validation right now and am doing most of it server side. The validation is set so that if the user has to go back all their data is retained.

 

I'm using case statements, which work wonderfully, but in this circumstance I don't know what would be the best method that allows for a multitude of combinations. I think there is a possibility of something like 120 different combinations.

 

What I want is for the check-boxes that were selected to be checked when it's sent back to the form.

 

Would it be better to just send each box as its own separate entity and evaluate it that way?

 

Thanks!

kvarnerexpress

178754[/snapback]

I'd try something like the following :

...<?php  $postvars = $_POST;  if ( ServerSideValidate ( $postvars ) == okay )//do your server side validation here.    redirect to a nice 'thankyou for filling in our form' page. Not sure how to do this right now.  else    proceed to the next bit.?><form method="post" action="<?php $_SERVER['PHP_SELF']?>">//the php_self bit makes it so the form submits to itself, so the code above can validate and either pass the user on or give them another try at the form.  <input method="checkbox" name="cb1" value="<?php if ( isset ($postvars['cb1'] ) ) print $postvars['cb1']; else print "";?>">  // What this does is check if the cb1 variable is filled from a previous try at the form. If it is, the value is put back in, else nothing is printed.  ... and so on for cb2, cb3, cb4, cb5.  </input></form>

What that does is :

- If the user is seeing the form for the first time, no POST variables will exist, and so the form is in a default state.

- When the user submits, the form submits to itself. At the top of the code is your validation code, and if the data passes you redirect the user to your nice little 'thanks' page. Otherwise, continue to the juicy bit.

- IF the user doesn pass your validation, then the next bit comes in. The user's already submitted some postdata, so it's there in the $_POST global. What the bit of code inside the 'value' attribute does is put the data back.

 

Should work : i haven't checked it and you may need to tweak to taste, but that's the basic method.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.