Forum Moderators: coopster
I have several checkboxes and some of these checkboxes have textareas right next to them to add more info.
How do I combine the data from the checkbox and textarea into one single string?
Right now I use this code to get all the value of the checkboxes into one array and send it to the db. However, I would like to add the value of the text areas right next to some checkboxes. let me know if you need more info.
where value is the name of all the checkboxes (value[])
CODE:
if(isset($_POST['value'])) {
$checkboxes=$_POST['value'];
}
$todatabase=mysql_real_escape_string(implode($checkboxes,","));
Thanks a lot guys!
Let's say I have these checkboxes and textboxs:
<input type="checkbox" name="value[]" value="I play"/>
<input name="text" type="text" size="60" />
<input type="checkbox" name="value[]" value="I cook">
<input type="hidden" name="value[]" value="I listen to music ">
How would I be able to concatenate the value of the textbox to the first checkbox?
I think I am having trouble understanding the function implode too.
Any example around? Thank you.
Verify something:
<input type="checkbox" name="value[]" value="I cook">
.... that the actual name is being set and sent. Check the box, submit, and add something like this (temporarily) to the top of your programming:
header("content-type:text/html\n\n");
var_dump($_POST); // or $_GET, if the method of the form is not set to post
exit;
The reason: if the "name" is not set for the checkbox it may not be in the values you're sending. With checkboxes, it will only be in $_POST (or $_GET, or $REQUEST) if the box is checked.