I am trying to figure out how to default the "table stored" values of a group of checkboxes to a form, both when the form is initially displayed and after the form is submitted.
I've tried this doing the checkboxes as both arrays and non array "name=" attributes.
The snippits of attached code actually work just fine as far as writing the values to the database table correctly, based on the values that are entered into form prior to submitting it. But once the form is submitted, the form values vanish. Also, I'd like to get the values from the database table to populate the form once the page is initially displayed so that the user knows what they chose in a prior session.
Here is the form code:
Code: Select all
<form name="pform" id="pform" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"; >
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="3" class="bluebox">
<tr>
<td >
<input type="checkbox" name="votingalerts" value="va">
<?php echo $votingalertsval; ?>
Voting Alerts (don't miss your call to vote on your
project)<br>
<input type="checkbox" name="miscmail" value="mm" >
Ad-hoc urgent news, Sprout Notices, New Sponsorships<br>
<input type="checkbox" name="monthlyprojectupdates" value="mpu">
Monthly Project Updates<br>
<input type="checkbox" name="quarterlyecogeenews" value="qen">
Quarterly ecogee news<br>
<input type="checkbox" name="annualreport" value="ar">
Annual Report <br>
<input type="checkbox" name="optout" value="oo">
Opt-out of all notifications<br>
</td>
</tr>
<tr>
<td >
<div align="left">
<input name="doUpdate" type="submit" id="doUpdate" value="Update">
</div>
</td>
</tr>
</table>
</form>Code: Select all
$votingalertsval = 0;
$miscmailval = 0;
$monthlyprojectupdatesval = 0;
$quarterlyecogeenewsval = 0;
$annualreportval = 0;
$optoutval = 0;
if (isset($_POST['votingalerts'])) {
$votingalerts = $_POST['votingalerts'];
if ($votingalerts == 'va') {
$votingalertsval = 1;
}
}
if (isset($_POST['miscmail'])) {
$miscmail = $_POST['miscmail'];
if ($miscmail == 'mm') {
$miscmailval = 1;
}
}
if (isset($_POST['monthlyprojectupdates'])) {
$monthlyprojectupdates = $_POST['monthlyprojectupdates'];
if ($monthlyprojectupdates == 'mpu') {
$monthlyprojectupdatesval = 1;
}
}
if (isset($_POST['quarterlyecogeenews'])) {
$quarterlyecogeenews = $_POST['quarterlyecogeenews'];
if ($quarterlyecogeenews == 'qen') {
$quarterlyecogeenewsval = 1;
}
}
if (isset($_POST['annualreport'])) {
$annualreport = $_POST['annualreport'];
if ($annualreport == 'ar') {
$annualreportval = 1;
}
}
if (isset($_POST['optout'])) {
$optout = $_POST['optout'];
if ($optout == 'oo') {
$optoutval = 1;
}
}Any suggestions or a link to a good way to do this?
Thanks,
Mike