|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
POST/GET variables
I was wondering what the best way to deal with checkboxes was... I think i've figured out a way that works, but to be honest i'm not pleased. I'm hoping there was a better way.
The checkbox is a response to a yes/no question (hence Y/N). Here's the code I've used: PHP Code:
|
|
#2
|
|||
|
|||
|
Well, any way you feel is best and can understand better is always the best way. Me, I would do this in this particular scenerio ->
PHP Code:
Now, the above would obviously be for seven questions. On my form or the questionaire, my checkboxes would be set as '0' for no and '1' for yes. empty() returns true or empty if the value is '( int ) 0' - so if the value of the $_POST['var'] comes in with an empty() value (or 0), the script would make no changes to the initialized variable as it is already set at '0', or false. If the value comes in as !empty() or '1', I set the variable to true. Now, after that the checking is trivial -> PHP Code:
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#3
|
||||
|
||||
|
thanks, that's pretty much exactly what i was looking for =)
it also answers a couple more questions that i never asked much appreciation, thanks! |
|
#4
|
|||
|
|||
|
Use it as an array
<form>
<input type="checkbox" name="check[]" value="1">1 <input type="checkbox" name="check[]" value="2">2 <input type="checkbox" name="check[]" value="3">3 <input type="submit" name="submit"> </form> the php code: for($i = 0; $i < sizeof($check); $i++) { print $check[$i]; }
__________________
Regards, Ramiro Varandas Jr. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > POST/GET variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|