Click here to Skip to main content
12,511,665 members (49,340 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PHP
Dear Friends,
I have this simple form

<table  align="left" cellpadding="3" cellspacing="0" width="550" border="0">
          <form action="" name="WebToLeadForm" method="post" id="WebToLeadForm" onsubmit="javascript: return form_validation();">

<tr>
                <td colspan="2" ><strong>What digital printing equipment do you have? </strong></td>
              </tr>
              <tr>
                <td >HP: </td>
                <td ><input id="printerhp_c" name="printerhp_c" type="checkbox" value="HP" value="<?php echo htmlentities($hp) ?>" />
                </td>
              </tr>
              <tr>
                <td >Xerox: </td>
                <td ><input id="printerxerox_c" name="printerxerox_c" type="checkbox" value="Xerox" value="<?php echo htmlentities($xerox) ?>" />
                </td>
              </tr>
              <tr>
                <td >Konica Minolta: </td>
                <td style="font-weight: normal;"><input id="printer_konicam_c" name="printer_konicam_c" type="checkbox" value="Konica Minolta" value="<?php echo htmlentities($km) ?>"/>
                </td>
              </tr>
              <tr>
                <td >Canon: </td>
                <td ><input id="printercanon_c" name="printercanon_c" type="checkbox" value="Canon"  value="<?php echo htmlentities($canon) ?>" />
                </td>
              </tr>
              <tr>
                <td >Kodak<span sugar="slot">: </span></td>
                <td ><input id="printerkodak_c" name="printerkodak_c" type="checkbox" value="Kodak"  value="<?php echo htmlentities($kodak) ?>"/>
                </td>
              </tr>
              <tr>
                <td >Ricoh: </td>
                <td ><input id="printerricoh_c" name="printerricoh_c" type="checkbox" value="Ricoh"  value="<?php echo htmlentities($ricoh) ?>" />
                </td>
              </tr>
              <tr>
                <td >Oc&eacute;: </td>
                <td ><input id="printeroce_c" name="printeroce_c" type="checkbox" value="Océ"   value="<?php echo htmlentities($oce) ?>"/>
                </td>
              </tr>
              <tr>
                <td >Other: </td>
                <td ><input id="printerother_c" name="printerother_c" type="checkbox" value="Other"  value="<?php echo htmlentities($other) ?>" />
                </td>
              </tr>

</form>


I just want that when i submit the form and code went wrong and page refresh/redirect all checkbox remain checked.

Thannks in
advance.
With Regards
Rajesh
Posted 30-Jun-12 0:43am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

if you use CHECKED KEY word to set a checkbox selected. example below:

if($value)//previously selected
{
 $checked="CHECKED";
}
else $checked="";
?>
  Permalink  
Comments
Rajeshkrathor 30-Jun-12 7:34am
   
This i should put for every checkbox?
Rajeshkrathor 30-Jun-12 7:36am
   
did not get the exact solution or what u want to tell can you pls give a full example for atleast 2 checkboxes..

tanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

In php post
$check=$_POST['check'];


In html
<input id="check" name="check" type="checkbox" value="Other" <?php echo empty($_POST['check']) ? '' : ' checked="checked" '; ??> />
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 25 Feb 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100