Jump to content

Check Box Status


Mirek

Recommended Posts

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.

[code]
<?php

if ($_POST['checkbox1']){

      ???;

}

?>
[/code]

thx in advance
Mirek
Link to comment
Share on other sites

Hrm

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:
[code=php:0] if (isset($_POST['checkbox1'])) { [/code]

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:
[code]
<?php

// 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

[/code]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.