Mirek Posted September 8, 2006 Share Posted September 8, 2006 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]<?phpif ($_POST['checkbox1']){ ???;}?>[/code]thx in advanceMirek Quote Link to comment Share on other sites More sharing options...
LegendBreath Posted September 8, 2006 Share Posted September 8, 2006 Here is a quick example:<?phpecho('<input type="checkbox" name="anothercheckbox"');if($_POST['checkbox'] == "SomeValue"){ echo(' checked');}echo('>');?>So now on the first form, the checkbox would have the value "SomeValue".I think this is how you do that Quote Link to comment Share on other sites More sharing options...
SharkBait Posted September 8, 2006 Share Posted September 8, 2006 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] Quote Link to comment Share on other sites More sharing options...
Mirek Posted September 8, 2006 Author Share Posted September 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
MarioRossi Posted September 8, 2006 Share Posted September 8, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.