Page 1 of 1
Checkbox and textfield in a form + php_script ??
Posted: Mon Jan 26, 2004 2:25 am
by Calimero
In a form there is a textfield and a checkbox, what is the code for treating checkboxes in php script to which the form was submited (of course only when its checked), and is it the same for more than 3 checkboxes in the form
And what part of tag is important for declaring a variable ?
input type="checkbox" name="chk1" value="check",
I deleted <,> just in case not to show actual checkbox, but line of code
Thanks ahead
Posted: Mon Jan 26, 2004 10:26 am
by ol4pr0
Dont know what you mean exacly however does this make any sence?
Code: Select all
echo <<<FORM
<input type="text" name="music" value="" .$row['music']. "";
FORM;
Posted: Mon Jan 26, 2004 10:32 am
by pickle
Not sure what you're asking inthe first part of your question, but I can tell you that the "name" is important when declaring your variable. In the example you gave, the checkbox will be represented in the $_POST array by the variable $_POST['chk1']. I should mention also, that the checkbox variable will only be present if the box was checked, if it isn't it won't show up in $_POST.
Posted: Mon Jan 26, 2004 10:39 am
by JayBird
if you have more than one checkbox on your page name them like this
Code: Select all
<input type="text" name="musicї]" value="somevalue">
<input type="text" name="musicї]" value="somevalue">
<input type="text" name="musicї]" value="somevalue">
Then, all the checked values will be available in an array called music.
Mark
Was I so ambiguous :)
Posted: Mon Jan 26, 2004 5:34 pm
by Calimero
Ok,
Thanks for the replies, I will surely find them useful,
BUT this one makes my brain hearing funy noises

Bech100 wrote: Then, all the checked values will be available in an array called music,
So do I need to declare that array in the php script I submit form to, and do I need to "explode" it, to make out separately to see which checkboxes were ticked and which not ??
Please help abput this one ?!?!

Posted: Mon Jan 26, 2004 5:46 pm
by pickle
You don't need to declare it per se, but it will be in the $_POST variables. $php_music_array = $_POST[music] will get you that array. $php_music_array[0] will then have the first checkbox that was checked. Fortunately (or unfortunately depending on the position), unchecked boxes will not be sent, so the only values in $php_music_array will of those checkboxes that were checked.