Jump to content


Check Box Status

  • Please log in to reply
4 replies to this topic

#1 Mirek

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 September 2006 - 12:48 AM

Hi all,

How does one get a status of a check box from a form via the $_POST[] variable and the assign that same status in a check box of a form on the new page?

i.e if a form has been submited with a check box 'checked' I want to be able to 'check' a box on a different form.


if ($_POST['checkbox1']){




thx in advance

#2 LegendBreath

  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationNew Brunswick, Canada

Posted 08 September 2006 - 01:24 AM

Here is a quick example:


echo('<input type="checkbox" name="anothercheckbox"');
if($_POST['checkbox'] == "SomeValue"){
    echo(' checked');


So now on the first form, the checkbox would have the value "SomeValue".
I think this is how you do that

#3 SharkBait

  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 08 September 2006 - 01:27 AM


Is the other form a seperate page altogether? Does it do any of the processing of the previous form?

If it is a seperate form and does not do any of the previous form's processing then you might have to pass the status of the checkbox via the URL and obtain it with $_GET['value'].

To see if box is checked:
if (isset($_POST['checkbox1'])) {

If it is not checked, then it's like it doesnt exist.

Now in the next form, if you want to have a box already checked then its something similar to:

// Get value from URL of the checkbox
$checked = $_GET['checkbox1'];
<!-- HTML HERE-->
<input type="checkbox" name="checkbox2" <?php if (isset($checked)) echo "checked=\"checked\"";?> /> Checkbox 2

#4 Mirek

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 September 2006 - 01:38 AM

Thanks to you both,

I did forget to mention that the actual script runs from an external include file and I was hoping to not to have to fiddle with every form on several pages but have a global script to adjust what I need.

I guess what I seek is something similar to the javascript :: document.form.textfield.value etc

I cant seem to find reference to similar in PHP.

Your solution is good and it works great, its what I use atm but I am hoping for something more like above.

#5 MarioRossi

  • Members
  • PipPip
  • Member
  • 25 posts

Posted 08 September 2006 - 02:03 AM

You do not have to use $_GET you can simply use....

<input type="checkbox" name="checkbox2" value="1" <?php if ($_POST['checkbox2'] == "1") echo "checked=\"checked\"";?> /> Checkbox 2

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users