Forum Moderators: coopster

Message Too Old, No Replies

Combine Checkbox and Textarea and send it to database

checkbox textarea

         

ceglieseus

5:00 am on Mar 28, 2009 (gmt 0)

10+ Year Member



Here is my scenario:

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!

rocknbil

7:51 pm on Mar 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard ceglieseus! Did you try concatenation?

if(isset($_POST['value'])) {
$checkboxes=$_POST['value'] . ' ' . $_POST['textareavalue'];
}

ceglieseus

8:28 pm on Mar 28, 2009 (gmt 0)

10+ Year Member



rocknbil - thanks a lot for your reply! Unfortunately, it does not seem to work.

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.

rocknbil

4:12 pm on Mar 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can read about implode() at [php.net...]

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.