homepage Welcome to WebmasterWorld Guest from 54.211.47.170
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Form to redirect based on radio buttons clicked
php redirect based on radio selection
frella




msg:4348372
 7:35 pm on Aug 5, 2011 (gmt 0)

I am very new at creating php forms but I have created the below form which is working great. I am able to receive the data entered in the MySQL database I created and also via email submission.

However, I would like for my clients that neither wish to purchase a logo entry nor an advertisement to be redirected to a type of "thankyou" page confirming submission of their entry. In other words if they client at any time clicks on the radio button for No Logo AND No Advertisement, these should not be sent to a directory_payment.html and instead another "thank you" page.

here is my whole page script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>2011 North American Directory Entry Form</title>
<style type="text/css">
.style1 {
font-size: large;
}
.style2 {
font-size: small;
font-style: italic;
}
.style3 {
font-size: small;
}
</style>
</head>
<body>
<table border="1" cellspacing="5%" width="905" style="font-family: Arial, Helvetica, sans-serif">
<tr>
<td>
<img height="155" src="shows/medica.gif" width="155" /></td><td><b>
<span class="style1">North American Exhibitor's Directory Form</span><br />
</b>Exhibitors from the United States and Canada at MEDICA 2011 will be
listed in the North American Exhibitors&#39; Directory.&nbsp; This is a
separate booklet from the main show catalogue, designed exclusively for
exhibitors from North America.&nbsp; Copies of the North American
Exhibitors&#39; Directory will be distributed from strategic locations
throughout the trade fair.<br />
<br />
For U.S. and Canadian exhibitors, the basic alphabetical entry that
includes booth number and company contact information is free of charge.&nbsp;
<b>Optional advertisements and logo placements are also available for
standard fees as outlined below.</b></td></tr>

<form action="/insert.php" method="post">
<input type="hidden" name="good_url"
value="http://www.mdna.com/directory_payment.html" />
<input type="hidden" name="subject" value="Directory Form Submission" />
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" />


<input type="hidden" name="recipients" value="jkesselring@mdna.com" />

<input type="hidden" name="required" value="companyname:Company Name,address:Company Address,city:City,state:State,zip:Postal Code,country:Country,tel:Telephone,fax:Fax,email:E-Mail Address,url:Internet URL" />


<input type="hidden" name="derive_fields" value="email=email,realname=company" />


<input type="hidden" name="mail_options" value="Exclude=email;realname" />

<table border="1" cellspacing="5%" style="font-family: Arial, Helvetica, sans-serif; width: 905px;">
<tr>
<td colspan="2">
<b>FREE ALPHABETICAL ENTRY (required)</b></td>
</tr>
<tr>
<td style="width: 433px">
<p>Company Name:</p>
</td>
<td><input type="text" name="companyname" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>Address:</p>
</td>
<td><input type="text" name="address" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>City:</p>
</td>
<td><input type="text" name="city" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>State/Province:</p>
</td>
<td><input type="text" name="state" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>Postal Code:</p>
</td>
<td><input type="text" name="zip" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>Country:</p>
</td>
<td><input type="text" name="country" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>Telephone:</p>
</td>
<td><input type="text" name="tel" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>Fax:</p>
</td>
<td><input type="text" name="fax" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>E-Mail:</p>
</td>
<td><input type="text" name="email" />
</td>
</tr>
<tr>
<td style="width: 433px">
<p>Internet URL:</p>
</td>
<td><input type="text" name="url" />
</td>
</tr>
<tr>
<td colspan="2" style="font-weight: 700">LOGO AND ADVERTISEMENT PLACEMENT ORDERS (optional)</td>
</tr>
<tr>
<td style="width: 433px"><p style="margin-bottom: 0px"><b>Logo Placement:</b></p>
<p style="margin-top: 0px; margin-bottom: 0px"><b>US$250.00</b></p>
<p style="margin-top: 0px">4-color process</p>
</td>
<td>
Yes <input type="radio" name="logo" value="Yes Logo" />
No <input type="radio" name="logo" value="No Logo" />
</td>
</tr>
<tr>
<td style="width: 433px"><p style="text-align: right">If you requested Logo Placement, indicate submission option:</p>
</td>
<td>
<input type="checkbox" name="logoemail" value="Will email the Logo" />Email the print material to jkesselring@mdna.com
<br />
<input type="checkbox" name="logosend" value="Will send the Logo" />Send digitalized data on diskette along with hard copy<br />
<span class="style2">Material required: Logo digitalized on diskette
along with a hard copy
of the logo OR the logo emailed to
</span>
<a href="mailto:example@example.com">
<span class="style2">example@example.com</span></a><span class="style2">in MAC-format or as .gif, .tif, or .jpg file (300 dpi), along with a .pdf
version, letters in splines. </span>
</td>
</tr>
<tr>
<td style="width: 433px"><p style="margin-bottom: 0px"><b>Advertising Placement
(4-color process):</b></p>
<p style="margin-top: 0px; margin-bottom: 0px; font-weight: 700;">1/2 Page Advertisement =
<b>US$850</b></p>
<p style="margin-top: 0px; margin-bottom: 0px; font-style: italic; font-size: small;">1/2 page horizontal, 4-color process: 7 1/2" X 5" non bleed, or 8 3/4" X 5 3/4" bleed<br />
1/2 page vertical, 4-color process: 3 5/8" X 10" non bleed, or 4 1/2" X 11" bleed</p>
<p style="margin-top: 0px; margin-bottom: 0px; font-weight: 700;">1/1 Page Advertisement =<b>
US$1,200</b></p>
<p style="margin-top: 0px; font-style: italic; font-size: small;">(inside covers and back page upon quotation)<br />
1/1 page; 4-color process.: 7 1/2" X 10" non bleed, or 8 5/8" X 11" bleed</p>
</td>
<td>
Yes - 1/2 Page Ad <input type="radio" name="ad" value="Yes, Half Ad" />
<br />
Yes - 1/1 Page Ad <input type="radio" name="ad" value="Yes, Full Ad" />
<br />
No <input type="radio" name="ad" value="No Ad" />
</td>
</tr>
<tr>
<td style="width: 433px"><p style="text-align: right">If you requested Ad Placement, indicate submission option:</p>
</td>
<td>
<input type="checkbox" name="ademail" value="Will Email Ad" />Email the print material to jkesselring@mdna.com
<br />
<input type="checkbox" name="adsend" value="Will Send Ad" />Send digitalized data on diskette along with hard copy
<br />
<span class="style2">Material required: Logo digitalized on diskette
along with a hard copy
of the logo OR the logo emailed to
</span>
<a href="mailto:example@example.com">
<span class="style2">example@example.com</span></a><span class="style2">in MAC-format or as .gif, .tif, or .jpg file (300 dpi), along with a .pdf
version, letters in splines. </span>
</td>
</tr>

<tr>
<td style="width: 433px"><input type="submit" value="Submit" /></td>
<td style="text-align:right;">&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>

[edited by: tedster at 6:13 pm (utc) on Aug 6, 2011]
[edit reason] made specific details anonymous [/edit]

 

mipapage




msg:4350721
 10:49 am on Aug 12, 2011 (gmt 0)

Have you solved this?

frella




msg:4350759
 1:36 pm on Aug 12, 2011 (gmt 0)

No not yet. I realize I may need to use logical operators but I am not sure how to formulate it properly with my current redirect....I am a newbie.

rocknbil




msg:4350844
 4:44 pm on Aug 12, 2011 (gmt 0)

When posting, isolate your code to the relevant parts, code dumps are largely ignored.

clicks on the radio button for No Logo AND No Advertisement, these should not be sent to a directory_payment.html and instead another "thank you" page.


First, the way radio buttons work - you are always supposed to have a default value checked. Many clients request that nothing be checked at load, but it's problematic- what if it's submitted with neither? You need an extra conditional if neither is set, and extra error trapping for it. (see solution 2)

Solution 1:

Yes <input type="radio" name="logo" value="Yes Logo" />
No <input type="radio" name="logo" value="No Logo" />
....

Yes - 1/2 Page Ad <input type="radio" name="ad" value="Yes, Half Ad" />
<br />
Yes - 1/1 Page Ad <input type="radio" name="ad" value="Yes, Full Ad" />
<br />
No <input type="radio" name="ad" value="No Ad" />

$nologo_noad = 'landing=2.html';
$default_landing = 'default-landing.html';

if (!isset($_POST['logo'] or !isset($_POST['ad')) {
// you need to return to form here with an error. A header will exit.
exit;
}
if (isset($_POST['logo'] and isset($_POST['ad') and ($_POST['logo']=='No Logo') and ($_POST['ad']=='No Ad')) {
header($nologo_noad);
}
else {
header($default_landing);
}

Solution 2:

Use radio buttons as they were intended, load a default value. Make your job easier. Also, comparing text values is terminally problematic, you'll have to modify them and dig through your code to do so. This gets particularly important when stored in databases.

<label for="logo-yes">Yes</label> <input type="radio" name="logo" id="logo-yes" value="1"/>
<label for="logo-no">No</label> <input type="radio" name="logo" id="logo-no" value="0" checked="checked"/>
....

<label for="ad-yes-half">Yes - 1/2 Page Ad</label> <input type="radio" name="ad" id="ad-yes-half" value="1"/>
<br />
<label for="ad-yes-full">Yes - 1/1 Page Ad</label> <input type="radio" name="ad" id="yes-full" value="2"/>
<br />
<label for="ad-no">No</label> <input type="radio" name="ad" id="ad-no" value="0" checked="checked"/>

Then, conveniently located at the top of your script, you have arrays storing the textual values you want to display:

$logo_values = Array('No Logo','Yes Logo'); // 0 = no, 1 - yes, etc.
$ad_values = Array('No Ad','Yes, Half Ad','Yes, Full Ad');

// Though it may never get used, we still have to verify data. This is to make it more
// difficult for potential hackers to abuse your form. Note though, it's different.

if (!isset($_POST['logo'] or !isset($_POST['ad')) {
die("Please use the form to submit data");
}

// Now we can depend on at least one value being checked.
if (($_POST['logo']=='0') and ($_POST['ad']=='0')) {
header($nologo_noad);
}
else {
header($default_landing);
}

To display them, just reference your arrays. You'll never have to mess with this code if the values change.

echo '<p>Logo: ' . $logo_values[$_POST['logo']] . '</p>';
echo '<p>Ad: ' . $logo_values[$_POST['ad']] . '</p>';

<aside>

From the above you can see, how do you get back to the form on error? exactly, you can't . . . often the solution is to take short cuts, display an error telling the user to "go back" and rely on the user to do so (extreme 1995 usability). What you need to do is devise a way to re-display the form on error - generally I like to do this:

if (isset($_POST['some-required-value'])) {
$errors = process_form();
if ($errors) { output_form($errors); }
}
else { output_form(); }

where you'd write the follwing functions:

function process_form() {
$err = null;
// Process form here, concatenate to $err if any found
return $err;
}

function output_form ($err=null) {
// Build the form here, if errors are found display them
// dynamically re-populate fields on error
echo $form;
}

Combining the above, you can use your text value arrays to output the form too, so that as you update it in one place, it updates it on the form, in emails, and on the response page too - which is another unwieldy beast if you want your response page to have any of the values from the form. Most coders resort to setting session values to do this, you don't need to if you re-think your form submit logic.

frella




msg:4350856
 4:54 pm on Aug 12, 2011 (gmt 0)

Thank you rocknbil! You have been very informative and detailed. I will give this a shot and see how it turns out.
(sorry for the code dump, I realized after submitting that I should have only posted the relevant....but it was too late). I appreciate you taking the time to look through it for me!

g1smd




msg:4350961
 8:40 pm on Aug 12, 2011 (gmt 0)

You don't redirect to a different URL when the form is submitted. Instead, what you do is always invoke the same script file on submission.

The single script file has different sets of HTML code and content that it can return based on what exactly has been selected on the form.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved