Jump to content


Photo

um inputes quick question


  • Please log in to reply
2 replies to this topic

#1 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 30 July 2006 - 07:15 AM

so um you know how you have button inputs and you can do a check with if statement

if(isset($buttonname)){
//do somthen
}else{
//do somthen

can you do this for radio buttons? and how does it work with check boxes?

the isset check
Dont Piss me Off today

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 30 July 2006 - 09:40 AM

ok here you go

a simple form with three check boxes with the isset submit
<?php
if (isset(submit) {
    if (!$test) { //the name of the checkbox
       echo "You did not check a box";
       exit;
    }
//do something
} 
?>
<form method="POST" action="whatever.php">
<input type="checkbox" name="test" value="test"> test<br>
<input type="checkbox" name="test" value="test2"> test2<br>
<input type="checkbox" name="test" value="test3"> test3<br>
<p><input type="submit" value="Submit" name="submit"></p>
</form>

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 30 July 2006 - 10:27 AM

Actually, you need to give the checkboxes different names, otherwise you will only get the value of the last one, unless you call them "test[]" for example, then you get an array with their values. With radio buttons, you give each radio button in the set the same name but different values, and the variable with the corresponding name will have the value of whichever one is selected.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users