Jump to content

Carry Checkbox to second form page


NoDoze

Recommended Posts

I have an html check box that is on form page 1, and I need this info carried over onto form page 2... How do I do this?

 

I am using php to carry the data from form page one to form page two.

So far I am using:

value="<?php echo $variable;?>

to carry the data from form page one to form page two.

 

How do I do the same thing, but for checkboxes?

 

Thanks!

Link to comment
Share on other sites

If it doesn't need to be displayed, just use hidden inputs.  If it needs to be displayed, there's more work, looping through the checkbox array you passed and outputting the code basically as you're already doing.  If there isn't a practical reason for the user to see the information though, just use hidden inputs.

Link to comment
Share on other sites

form page one:

<input name="solesource" type="checkbox" value="yes">

 

Form page 2:

value="<?php echo $solesource;?>"

 

Only on form page 2, the check does not appear...?

 

i don't understand. you need to give more information.

 

the checkbox doesn't appear at all? or it doesn't appear to be checked?? post more code.

Link to comment
Share on other sites

When the check box is check on form one, and the variables from form one are posted via this method: ?php echo $solesource;? the check box does not appear checked on the second form page. When checked again on the second form page, then submited finally, then the data "yes" appears correctly in the database. I don't know what showing more code would help explain, but here ya go...

 

From form 1

<FORM METHOD="POST" ACTION="form2.php">
<input name="solesource" type="radio" value="yes">
<input name="" type="reset">
     
<input name="add" type="submit" id="add" value="Verify Info">
</form>

 

From form 2

<form action="/process/formprocess.php" method="post" name="form" class="form-class">
<input name="solesource" type="radio" value="<?php echo $solesource;?>">
<input type=button value="Reset" onClick="history.go(-1)">
     
<input name="add" type="submit" id="add" value="Submit">
</form>

 

Just need to know how to keep the check box checked on the second form page?

 

Thanks.

Link to comment
Share on other sites

you have to use the $_POST method, as i've mentioned before. btw... you can't change up the code on us like that... either keep it checkbox, or keep it radio... how are we supposed to help you if you keep changing the problem?

 

<input name="solesource" type="radio" value="<?php echo $_POST['solesource'] ;?>">

 

 

Link to comment
Share on other sites

if you want the checkbox to be check on the second page this code needs to be included:

 

<input name="solesource" type="radio" value="<?php echo $_POST['solesource'] ;?>" <?php if(isset($_POST['solesource'])){ echo 'selected="selected"';}?>>
// the if(isset($_POST['solesource'])) statement will cause the checkbox to be checked if it was checked in the previous page.

Link to comment
Share on other sites

if you want the checkbox to be check on the second page this code needs to be included:

 

<input name="solesource" type="radio" value="<?php echo $_POST['solesource'] ;?>" <?php if(isset($_POST['solesource'])){ echo 'selected="selected"';}?>>
// the if(isset($_POST['solesource'])) statement will cause the checkbox to be checked if it was checked in the previous page.

 

your code is flawed. the $_POST['solesource'] variable will be set because it exists. that doesn't mean it will have a value. you need to check to see if it has a value, not if it is set.

Link to comment
Share on other sites

Hmmm...didn't work.

 

Form #1

<FORM METHOD="POST" ACTION="form2.php">
<input name="solesource" type="checkbox" value="yes">
<input name="" type="reset">
     
<input name="add" type="submit" id="add" value="Verify Info">
</form>

 

Form #2

<form action="/process/formprocess.php" method="post" name="form" class="form-class">
<input name="solesource" type="checkbox" value="<?php echo $_POST['solesource'] ;?>">
<input type=button value="Reset" onClick="history.go(-1)">
     
<input name="add" type="submit" id="add" value="Submit">
</form>

 

Any ideas?

Link to comment
Share on other sites

yeah my bad on the selected=selected part.  i've been working with select boxes

 

<input name="solesource" type="radio" value="<?php echo $_POST['solesource'] ;?>" <?php if(isset($_POST['solesource'])){ echo 'checked="checked"';}?>>

 

my code is just testing to see if the check box has been checked.  if you have multiple check boxes then you would then test the value of $_POST['solesource'].  basically just trying to give a push in the right direction, not trying to give the absolute code.

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.