Checkbox and textfield in a form + php_script ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Checkbox and textfield in a form + php_script ??

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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;
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

if you have more than one checkbox on your page name them like this

Code: Select all

<input type="text" name="music&#1111;]" value="somevalue">
<input type="text" name="music&#1111;]" value="somevalue">
<input type="text" name="music&#1111;]" value="somevalue">
Then, all the checked values will be available in an array called music.

Mark
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Was I so ambiguous :)

Post 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 ?!?! :?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply