Hello again all,
First i just want to thank everyone for being such a great help to a php newbie, but I've hit another snag in a project.
As you can see from the following code, I have a form that uses a switch statement to display relevant fields to the user. As it sits right now, if the user makes a selection from the question, "what service form do you need to submit?", they are "stuck" with their choice.
Is there a way the user could "reset" the form in case they select the wrong option or is there a way so that every time they choose an option from that drop-down menu, php re-reads the switch code?
<?php
if ($_POST['submit'] == true) {
echo "Your form has been submitted. Check your inbox for a confirmation message.";
} else {
?>
<form name="form2" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>Company Name:</td>
<td>
<?php
if ($_POST['cName'] == true) {
echo'<input type="text" name="cName" value="'.$_POST['cName'].'" />';
} else {
echo'<input type="text" name="cName" />';
}
?>
</td>
</tr>
<tr>
<td>Phone Number:</td>
<td>
<?php
if ($_POST['cPhone'] == true) {
echo'<input type="text" name="cPhone" value="'.$_POST['cPhone'].'" />';
} else {
echo'<input type="text" name="cPhone" />';
}
?>
</td>
</tr>
<tr>
<td>Fax Number:</td>
<td>
<?php
if ($_POST['faxNumber'] == true) {
echo'<input type="text" name="faxNumber" value="'.$_POST['faxNumber'].'" />';
} else {
echo'<input type="text" name="faxNumber" />';
}
?>
</td>
</tr>
<tr>
<td>Company Address:</td>
<td>
<?php
if ($_POST['companyAddress'] == true) {
echo'<input type="text" name="companyAddress" value="'.$_POST['companyAddress'].'" />';
} else {
echo'<input type="text" name="companyAddress" />';
}
?>
</td>
</tr>
<tr>
<td>City:</td>
<td>
<?php
if ($_POST['city'] == true) {
echo'<input type="text" name="city" value="'.$_POST['city'].'" />';
} else {
echo'<input type="text" name="city" />';
}
?>
</td>
</tr>
<tr>
<td>State:</td>
<td>
<?php
if ($_POST['state'] == true) {
echo'<input type="text" name="state" value="'.$_POST['state'].'" />';
} else {
echo'<input type="text" name="state" />';
}
?>
</td>
</tr>
<tr>
<td>Zip Code:</td>
<td>
<?php
if ($_POST['zipCode'] == true) {
echo'<input type="text" name="zipCode" value="'.$_POST['zipCode'].'" />';
} else {
echo'<input type="text" name="zipCode" />';
}
?>
</td>
</tr>
<tr>
<td>Fed Tax ID:</td>
<td>
<?php
if ($_POST['fedTaxId'] == true) {
echo'<input type="text" name="fedTaxId" value="'.$_POST['fedTaxId'].'" />';
} else {
echo'<input type="text" name="fedTaxId" />';
}
?>
</td>
</tr>
<tr>
<td>Owner's Name:</td>
<td>
<?php
if ($_POST['ownersName'] == true) {
echo'<input type="text" name="ownersName" value="'.$_POST['ownersName'].'" />';
} else {
echo'<input type="text" name="ownersName" />';
}
?>
</td>
</tr>
<tr>
<td>E-Commerce Manager (if different from above):</td>
<td>
<?php
if ($_POST['eCommerceManager'] == true) {
echo'<input type="text" name="eCommerceManager" value="'.$_POST['eCommerceManager'].'" />';
} else {
echo'<input type="text" name="eCommerceManager" />';
}
?>
</td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<?php
if ($_POST['emailAddress'] == true) {
echo'<input type="text" name="emailAddress" value="'.$_POST['emailAddress'].'" />';
} else {
echo'<input type="text" name="emailAddress" />';
}
?>
</td>
</tr>
<tr>
<td>What service form do you need to submit?</td>
<td><select name="serviceForm" onchange="document.forms['form2'].submit();">
<option>Select One</option>
<option>EDI</option>
<option>Glaxis</option>
<option>EDI and Glaxis</option>
</select>
</td>
</tr>
<?php
switch ($_POST['serviceForm']) {
case 'EDI':
?>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><strong>EDI Service Request</strong></td>
</tr>
<tr>
<td>EDI Volume Plan:</td>
<td><input name="volumePlan" type="checkbox" value="low volume" /> Low Volume (10 or less invoices/month)<br />
<input name="volumePlan" type="checkbox" value="standard volume" /> Standard Volume (10+ invoices/month)
</td>
</tr>
<tr>
<td>How would you like to pay your monthly fees?</td>
<td><select name="paymentOptions">
<option>Mail a Check (adds $10/month processing fee)</option>
<option>Direct Debit (E.F.T.)</option>
</select>
</td>
</tr>
<?php // is there an easy way to display an additional fields here
// if the user chooses the "Direct Debit" Option?
// would another switch statement do the trick?
?>
<tr>
<td>Do you accept the EDI Terms of Service?</td>
<td><select name="termsOfService">
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td valign="top"><input type="submit" name="submit" value="Send Form" /> <input type="reset" name="reset" value="Start Over" /></td>
</tr>
</table>
</form>
<?php
break;
case 'Glaxis':
?>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><strong>Glaxis Service Request</strong></td>
</tr>
<tr>
<td>Previous Lynx Dispatch Number:</td>
<td><input type="text" name="linxDispatch" /></td>
</tr>
<tr>
<td>When would you like to go Live??</td>
<td><input type="text" name="liveDate" /></td>
</tr>
<tr>
<td>Would you like to setup PPG online ordering?</td>
<td><select name="ppgOnlineOrdering">
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td>Do you accept the Glaxis Terms of Service?</td>
<td><select name="glaxisTermsOfService">
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td valign="top"><input type="submit" name="submit" value="Send Form" /> <input type="reset" name="reset" value="Start Over" /></td>
</tr>
</table>
</form>
<?php
break;
case 'EDI and Glaxis':
?>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><strong>EDI Service Request</strong></td>
</tr>
<tr>
<td>EDI Volume Plan:</td>
<td><input name="volumePlan" type="checkbox" value="low volume" /> Low Volume (10 or less invoices/month)<br />
<input name="volumePlan" type="checkbox" value="standard volume" /> Standard Volume (10+ invoices/month)
</td>
</tr>
<tr>
<td>How would you like to pay your monthly fees?</td>
<td><select name="paymentOptions">
<option>Check (adds $10/month processing fee)</option>
<option>Direct Debit (E.F.T.)</option>
</select>
</td>
</tr>
<tr>
<td>Do you accept the EDI Terms of Service?</td>
<td><select name="termsOfService">
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<tr>
<td colspan="2"> </td>
</tr>
<td colspan="2"><strong>Glaxis Service Request</strong></td>
</tr>
<tr>
<td>Previous Lynx Dispatch Number:</td>
<td><input type="text" name="linxDispatch" /></td>
</tr>
<tr>
<td>When would you like to go Live??</td>
<td><input type="text" name="liveDate" /></td>
</tr>
<tr>
<td>Would you like to setup PPG online ordering?</td>
<td><select name="ppgOnlineOrdering">
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td>Do you accept the Glaxis Terms of Service?</td>
<td><select name="glaxisTermsOfService">
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td valign="top"><input type="submit" name="submit" value="Send Form" /> <input type="reset" name="reset" value="Start Over" /></td>
</tr>
</table>
</form>
<?php
break;
}
}
?>
If you noticed the notes in the code, I'd also like to be able to display additional fields if the user selects a certain payment option. Can i do an additional swtich statement there or am i heading in the wrong direction?
I apologize for the length of this post, but greatly appreciate the input!
Thanks again,
J