Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Redirect based on form input

Posted on 2009-05-11
13
Medium Priority
?
474 Views
Last Modified: 2012-05-06
I got the below code from this post:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23076549.html

But I cannot get it to work, even straight copying & pasting. I get a warning that the headers were already opened on either line 6 or line 8 depending on which of the choices I attempt.

There are a few other things I need to do with my form (validation & sending an email of results) in addition to redirecting based on the input of one of the fields, but I can't get past just the redirect part in order to attempt the other coding.

If someone knows how I can accomplish the other goals in addition to being able to use the code below, I would greatly appreciate it!
<?php 
  $ec=$_POST['ec'];
  if (isset($ec))
  {
        if ($ec=="1232")
          header("Location: example.php");
        elseif ($ec=="8832")
      header("Location: 8832.tpl");       
  }
  ?>
<div id="content-info">
  <div align="center">
  <table cellspacing="0">
    <tr>
      
          <td>
        <form name="myForm" action="thispage.php" method="post">
        <br /><br />
       <h3>Please enter the Email Code that you received to retrieve your message</h3>
         <br />
                <p><blockquote>Email Code:
           <input type="text" name="ec" maxlength="4" size="6" /></blockquote>
         </p>
         <br />
        
          
            <div align="left">
              <input type="submit"  />
            </div>
        
 
  </form>
  </td>
  </tr>
  </table></div>
</div>

Open in new window

0
Comment
Question by:risigm
  • 6
  • 6
13 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24359285
You probably have some code before the code in the snippet. Lines 1-10 in the snippet must be before your <!DOCTYPE and <html> tags.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24359301
The first lines should be slightly different. Instead of this:

$ec=$_POST['ec'];
if (isset($ec)) {
  if ($ec=="1232")

...you should do this:

if (isset($_POST['ec'])) {
  $ec=$_POST['ec'];
  if ($ec=="1232")
0
 

Author Comment

by:risigm
ID: 24359418
Thanks for responding, cxr.

I checked the file directly on the server, and there is no junk before the php tag (i know sometimes in certain text editors this can happen), so then I tried your solution of swapping those 2 lines, and now it says headers opened on line 5.  I didn't paste the code with the html & body tags previously, so i included it again below, with your suggested change.

Checked again, no junk before the php opener tag.
<?php 
if (isset($_POST['ec'])) {
  $ec=$_POST['ec'];
  if ($ec=="1232")
      header("Location: example.php");
        elseif ($ec=="8832")
      header("Location: 8832.tpl");       
  }
  ?>
  <html><body>
<div id="content-info">
  <div align="center">
  <table cellspacing="0">
    <tr>
      
          <td>
        <form name="myForm" action="thispage.php" method="post">
        <br /><br />
       <h3>Please enter the Email Code that you received to retrieve your message</h3>
         <br />
                <p><blockquote>Email Code:
           <input type="text" name="ec" maxlength="4" size="6" /></blockquote>
         </p>
         <br />
        
          
            <div align="left">
              <input type="submit"  />
            </div>
        
 
  </form>
  </td>
  </tr>
  </table></div>
</div>
</body></html>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24359651
Insert an "exit;" at line 8:
<?php 
if (isset($_POST['ec'])) {
  $ec=$_POST['ec'];
  if ($ec=="1232")
      header("Location: example.php");
  elseif ($ec=="8832")
      header("Location: 8832.tpl");       
  exit;
}
?>

Open in new window

0
 

Author Comment

by:risigm
ID: 24360416
Tried putting in the 8832 code...
Warning: Cannot modify header information - headers already sent by (output started at /home/*****/public_html/thispage.php:1) in /home/******/public_html/thispage.php on line 7

If I put in 1232...
Warning: Cannot modify header information - headers already sent by (output started at /home/*****/public_html/thispage.php:1) in /home/******/public_html/thispage.php on line 5

:(

Is this code working for you?
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24360459
I think your file is in unicode format and has a BOM, i.e. invisible characters before the <?php on the first line. Do "save as..." in some editor and check the file format. It must not be unicode. Or upload the file here, then I can check it. Or create a new ascii file and copy-paste your current code into the new file.
0
 

Expert Comment

by:rgbarron
ID: 24363692
Everything looks right to me, so if you have access to your php.ini file, you might want to check the output_buffering parameter.  

Having this parameter set to "off" can cause this problem.

Even if you don't have access to the ini file itself, you can use

ini_set('output_buffering', 'on');

to set the value for that page's execution only.
0
 

Author Comment

by:risigm
ID: 24366268
Strangely when I had someone else try this form this morning, it worked, so then I tried, and it worked also.

Perhaps there was an error w/my server that was doing it.

Now that for whatever bizarre reason that part is working... the original reason above I was going to post was my validation & email codes. I have added them into the (now working) code above, and it checks to see which code was submitted & redirects, but it does not validate the form OR send an email. If you submit the form without entering anything at all, you get a blank page.

Please see my code below.

Thank you for your patience. :)
<?php 
if (isset($_POST['code'])) {
  $code=$_POST['code'];
  if ($code=="1232")
      header("Location: congratulations.php");
  elseif ($code=="8832")
      header("Location: sorry.php");       
  exit;
}
?>
<?php
 
function VerifyForm(&$values, &$errors)
{
    // Do all necessary form verification
    
    if (strlen($values['name']) < 3)
        $errors['name'] = 'Name too short';
    elseif (strlen($values['name']) > 50)
        $errors['name'] = 'Name too long';
        
    // Needs better checking ;)
    if (!ereg('.*@.*\..{2,4}', $values['email']))
        $errors['email'] = 'Email address invalid';
 
    if (strlen($values['jobtitle']) == 0)
        $errors['jobtitle'] = 'Job Title required';
 
    if (strlen($values['company']) == 0)
        $errors['company'] = 'Company required';
 
    if (strlen($values['phone']) == 0)
        $errors['phone'] = 'Phone number required'; 
 
    if (strlen($values['code']) == 0)
        $errors['code'] = 'Code required';
 
 
        
    return (count($errors) == 0);
}
 
function DisplayForm($values, $errors)
{
    ?>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html>
 
<head>
 
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta http-equiv="Content-Language" content="en-us" />
 
 
<title>Website</title>
 
<script type="text/javascript" src="http://www.website.com/js/son_js.js"></script>
<link rel="stylesheet" media="all" type="text/css" href="offers.css"/> 
 
        <style>
            TD.error
            {
                color: red;
                font-weight: bold;    
            }
        </style>
</head>
 
 
<body class="son_body" onload="MM_preloadImages('http://www.website.com/images/nav_home_over.gif','http://www.website.com/images/nav_programs_over.gif','http://www.website.com/images/nav_partners_over.gif','http://www.website.com/images/nav_sponsors_over.gif','http://www.website.com/images/nav_research_over.gif','http://www.website.com/images/nav_company_over.gif','http://www.website.com/images/nav_news_over.gif','http://www.website.com/images/nav_contact_over.gif','http://www.website.com/images/find_out_button_over.gif','http://www.website.com/images/seeking_button_over.gif','http://www.website.com/images/partners_contactbutton_over.gif')">
 
    <?php
    if (count($errors) > 0)
        echo "<p>Hello. Either all the fields were not filled out properly or the code you entered was not recognized. Please try again.</p>";
    ?>
 
<table width="886" border="0" cellpadding="0" cellspacing="0" class="son_background" align="center">
	<!-- Begin Header and Nav -->
	<tr>
		<td><img src="http://www.website.com/images/page_top.gif" alt=""/></td>
	</tr>
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td><img src="http://www.website.com/images/spacer.gif" width="34" alt=""/></td>
					<td><a href="http://www.website.com/index.htm"><img src="http://www.website.com/images/son_logo.gif" alt="Website" border="0"/></a></td>
					<td><a href="http://www.website.com/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','http://www.website.com/images/nav_home_over.gif',0)">
					<img src="http://www.website.com/images/nav_home.gif" alt="Home" name="home" border="0"/></a></td>
					<td><a href="http://www.website.com/programs/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('programs','','http://www.website.com/images/nav_programs_over.gif',0)">
					<img src="http://www.website.com/images/nav_programs.gif" alt="Our Programs" name="programs" border="0"/></a></td>
					<td><a href="http://www.website.com/partners/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('partners','','http://www.website.com/images/nav_partners_over.gif',0)">
					<img src="http://www.website.com/images/nav_partners.gif" alt="Media Partners" name="partners" border="0"/></a></td>
					<td><a href="http://www.website.com/sponsors/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('sponsors','','http://www.website.com/images/nav_sponsors_over.gif',0)">
					<img src="http://www.website.com/images/nav_sponsors.gif" alt="Corporate Sponsors" name="sponsors" border="0"/></a></td>
					<td><a href="http://www.website.com/research/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('research','','http://www.website.com/images/nav_research_over.gif',0)">
					<img src="http://www.website.com/images/nav_research.gif" alt="ROI" name="research" border="0"/></a></td>
					<td><a href="http://www.website.com/company/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('company','','http://www.website.com/images/nav_company_over.gif',0)">
					<img src="http://www.website.com/images/nav_company.gif" alt="Company" name="company" border="0"/></a></td>
					<td><a href="http://www.website.com/news/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('news','','http://www.website.com/images/nav_news_over.gif',0)">
					<img src="http://www.website.com/images/nav_news.gif" alt="News" name="news" border="0"/></a></td>
					<td><a href="http://www.website.com/contact/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contact','','http://www.website.com/images/nav_contact_over.gif',0)">
					<img src="http://www.website.com/images/nav_contact.gif" alt="Contact" name="contact" border="0"/></a></td>
				</tr>
			</table>	
		</td>
	</tr>
	<!-- End Header and Nav -->
	<tr>
		<td><img src="http://www.website.com/images/spacer.gif" height="23" width="77" alt=""/></td>
	</tr>
	<!-- Begin Text Row -->
	<tr>
	  <td>
			<div id="EdLunchContainer" class="clearfix">
				<div id="EdLunchTopCap">
					<h2>Find out if you are the lucky winner </h2>
				</div>
				<div id="EdLunchContent" class="clearfix">
					<div id="Left">
						<img src="http://www.website.com/images/text.gif">
					</div>
					<div id="Right">
						<form id="EdLunchForm" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
							<table id="EdLunch">
								<tr>
									<td class="error">
										<input class="input" type="text" name="name" value="<?php htmlentities($values['name']) ?>"/>
									<br /><?php $errors['name'] ?></td>
									<td class="error">
										<input class="input" type="text" name="jobtitle" value="<?php htmlentities($values['jobtitle']) ?>"/>
									<br /><?php $errors['jobtitle'] ?></td>
								</tr>
								<tr>
									<td>
										<p>Name</p>
									</td>
									<td>
										<p>Job Title </p>
									</td>
								</tr>
								<tr>
									<td class="error">
										<input class="input" type="text" name="company" value="<?php htmlentities($values['company']) ?>"/>
									<br /><?php $errors['company'] ?></td>
									<td class="error">
										<input class="input" type="text" name="phone" value="<?php htmlentities($values['phone']) ?>"/>
									<br /><?php $errors['phone'] ?></td>
								</tr>
								<tr>
									<td>
										<p>Company</p>
									</td>
									<td>
										<p>Phone</p>
									</td>
								</tr>
								<tr>
									<td class="error">
										<input class="input" type="text" name="email" value="<?php htmlentities($values['email']) ?>"/>
									<br /><?php $errors['email'] ?></td>
									<td class="error">
										<input class="input" type="text" name="code" value="<?php htmlentities($values['code']) ?>"/>
									<br /><?php $errors['code'] ?></td>
								</tr>
								<tr>
									<td>
										<p>E-mail</p>
									</td>
									<td>
										<p>Enter Your Code Here! </p>
									</td>
								</tr>
								<tr>
									<td>
									</td>
									<td>
										<input class="button" type="submit" value="Submit"/>
									</td>
								</tr>
							</table>
						</form>
					</div>
				</div>
				<div id="EdLunchBottomCap">
				</div>
			</div>
	        <p>&nbsp;</p></td>
	</tr>
				</tr>
			</table>
		</td>
	</tr>
	<!-- End Text Row -->
	<div id="ImageFooter">
		
	</div>
</table>
</body>
</html>
<?php
}
 
function ProcessForm($values)
{
    mail('removed@removed.com', 'Code Form', $values['text'], "From: \"{$values['name']}\" 
 
<{$values['email']}>");
    
}
 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $formValues = $_POST;
    $formErrors = array();
    
    if (!VerifyForm($formValues, $formErrors))
        DisplayForm($formValues, $formErrors);
    else
        ProcessForm($formValues);
}
else
    DisplayForm(null, null);
?>

Open in new window

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24366643
If the user enters "1232" or "8832" he will be redirected to a new page before any validation is executed.

Remove the exit; in line 8. It should only be executed when you actually redirect. Something like this:

<?php
if (isset($_POST['code'])) {
  $code=$_POST['code'];
  if ($code=="1232") {
      header("Location: congratulations.php");
      exit;
  }
  elseif ($code=="8832") {
      header("Location: sorry.php");      
      exit;
  }
}
?>
 
These are wrong:

<?php $_SERVER['PHP_SELF'] ?>
<?php htmlentities($values['name']) ?>
<?php $errors['name'] ?>
<?php htmlentities($values['jobtitle']) ?>
<?php $errors['jobtitle'] ?>
... and so on.

You must echo the value, and end it with a ; character:

<?php echo $_SERVER['PHP_SELF']; ?>
<?php echo htmlentities($values['name']); ?>
<?php echo $errors['name']; ?>
<?php echo htmlentities($values['jobtitle']); ?>
<?php echo $errors['jobtitle']; ?>
...and so on.
0
 

Author Comment

by:risigm
ID: 24368250
Thanks cxr, I had a feeling it was some sort of idiotic mistake from not paying attentiion. it sends the emails now, but sends them twice. once blank, and once filled in & perfectly as wanted, but with the subject working on both. *dramatic sigh*

I'm about to just give up! I've been trying to work through my stupid mistakes for 2 days now.

Sorry I'm such a pain but I haven't used that much PHP for a while, and I'm clearly beyond rusty. :(
<?php
if (isset($_POST['code'])) {
  $code=$_POST['code'];
  if ($code=="1232") {
      header("Location: congratulations.php");
 
  }
  elseif ($code=="8832") {
      header("Location: sorry.php");      
 
  }
}
?>
<?php
 
function VerifyForm(&$values, &$errors)
{
    // Do all necessary form verification
    
    if (strlen($values['name']) < 3)
        $errors['name'] = 'Name too short';
    elseif (strlen($values['name']) > 50)
        $errors['name'] = 'Name too long';
        
    // Needs better checking ;)
    if (!ereg('.*@.*\..{2,4}', $values['email']))
        $errors['email'] = 'Email address invalid';
 
    if (strlen($values['jobtitle']) == 0)
        $errors['jobtitle'] = 'Job Title required';
 
    if (strlen($values['company']) == 0)
        $errors['company'] = 'Company required';
 
    if (strlen($values['phone']) == 0)
        $errors['phone'] = 'Phone number required'; 
 
    if (strlen($values['code']) == 0)
        $errors['code'] = 'Code required';
 
 
        
    return (count($errors) == 0);
}
 
function DisplayForm($values, $errors)
{
    ?>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html>
 
<head>
 
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta http-equiv="Content-Language" content="en-us" />
 
 
<title>My Website</title>
 
<script type="text/javascript" src="http://www.mywebsite.com/js/son_js.js"></script>
<link rel="stylesheet" media="all" type="text/css" href="offers.css"/> 
 
        <style>
            TD.error
            {
                color: red;
                font-weight: bold;    
            }
        </style>
</head>
 
 
<body class="son_body" onload="MM_preloadImages('http://www.mywebsite.com/images/nav_home_over.gif','http://www.mywebsite.com/images/nav_programs_over.gif','http://www.mywebsite.com/images/nav_partners_over.gif','http://www.mywebsite.com/images/nav_sponsors_over.gif','http://www.mywebsite.com/images/nav_research_over.gif','http://www.mywebsite.com/images/nav_company_over.gif','http://www.mywebsite.com/images/nav_news_over.gif','http://www.mywebsite.com/images/nav_contact_over.gif','http://www.mywebsite.com/images/find_out_button_over.gif','http://www.mywebsite.com/images/seeking_button_over.gif','http://www.mywebsite.com/images/partners_contactbutton_over.gif')">
 
    <?php
    if (count($errors) > 0)
        echo "<p>Hello. Either all the fields were not filled out properly or the code you entered was not recognized. Please try again.</p>";
    ?>
 
<table width="886" border="0" cellpadding="0" cellspacing="0" class="son_background" align="center">
	<!-- Begin Header and Nav -->
	<tr>
		<td><img src="http://www.mywebsite.com/images/page_top.gif" alt=""/></td>
	</tr>
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td><img src="http://www.mywebsite.com/images/spacer.gif" width="34" alt=""/></td>
					<td><a href="http://www.mywebsite.com/index.htm"><img src="http://www.mywebsite.com/images/son_logo.gif" alt="My Website" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','http://www.mywebsite.com/images/nav_home_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_home.gif" alt="Home" name="home" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/programs/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('programs','','http://www.mywebsite.com/images/nav_programs_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_programs.gif" alt="Our Programs" name="programs" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/partners/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('partners','','http://www.mywebsite.com/images/nav_partners_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_partners.gif" alt="Media Partners" name="partners" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/sponsors/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('sponsors','','http://www.mywebsite.com/images/nav_sponsors_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_sponsors.gif" alt="Corporate Sponsors" name="sponsors" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/research/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('research','','http://www.mywebsite.com/images/nav_research_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_research.gif" alt="ROI" name="research" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/company/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('company','','http://www.mywebsite.com/images/nav_company_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_company.gif" alt="Company" name="company" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/news/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('news','','http://www.mywebsite.com/images/nav_news_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_news.gif" alt="News" name="news" border="0"/></a></td>
					<td><a href="http://www.mywebsite.com/contact/index.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contact','','http://www.mywebsite.com/images/nav_contact_over.gif',0)">
					<img src="http://www.mywebsite.com/images/nav_contact.gif" alt="Contact" name="contact" border="0"/></a></td>
				</tr>
			</table>	
		</td>
	</tr>
	<!-- End Header and Nav -->
	<tr>
		<td><img src="http://www.mywebsite.com/images/spacer.gif" height="23" width="77" alt=""/></td>
	</tr>
	<!-- Begin Text Row -->
	<tr>
	  <td>
			<div id="EdLunchContainer" class="clearfix">
				<div id="EdLunchTopCap">
					<h2>Find out if you are the lucky winner </h2>
				</div>
				<div id="EdLunchContent" class="clearfix">
					<div id="Left">
						<img src="http://www.mywebsite.com/images/text.gif">
					</div>
					<div id="Right">
						<form id="EdLunchForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
							<table id="EdLunch">
								<tr>
									<td class="error">
										<input class="input" type="text" name="name" value="<?php echo htmlentities($values['name']); ?>"/>
									<br /><?php echo $errors['name']; ?></td>
									<td class="error">
										<input class="input" type="text" name="jobtitle" value="<?php echo htmlentities($values['jobtitle']); ?>"/>
									<br /><?php echo $errors['jobtitle']; ?></td>
								</tr>
								<tr>
									<td>
										<p>Name</p>
									</td>
									<td>
										<p>Job Title </p>
									</td>
								</tr>
								<tr>
									<td class="error">
										<input class="input" type="text" name="company" value="<?php echo htmlentities($values['company']); ?>"/>
									<br /><?php echo $errors['company']; ?></td>
									<td class="error">
										<input class="input" type="text" name="phone" value="<?php echo htmlentities($values['phone']); ?>"/>
									<br /><?php echo $errors['phone']; ?></td>
								</tr>
								<tr>
									<td>
										<p>Company</p>
									</td>
									<td>
										<p>Phone</p>
									</td>
								</tr>
								<tr>
									<td class="error">
										<input class="input" type="text" name="email" value="<?php echo htmlentities($values['email']); ?>"/>
									<br /><?php echo $errors['email']; ?></td>
									<td class="error">
										<input class="input" type="text" name="code" value="<?php echo htmlentities($values['code']); ?>"/>
									<br /><?php echo $errors['code']; ?></td>
								</tr>
								<tr>
									<td>
										<p>E-mail</p>
									</td>
									<td>
										<p>Enter Your Code Here! </p>
									</td>
								</tr>
								<tr>
									<td>
									</td>
									<td>
										<input class="button" type="submit" value="Submit"/>
									</td>
								</tr>
							</table>
						</form>
					</div>
				</div>
				<div id="EdLunchBottomCap">
				</div>
			</div>
	        <p>&nbsp;</p></td>
	</tr>
				</tr>
			</table>
		</td>
	</tr>
	<!-- End Text Row -->
	<div id="ImageFooter">
		
	</div>
</table>
</body>
</html>
<?php
}
 
$Name = $_POST['name'];
$Email = $_POST['email'];
$Jobtitle = $_POST['jobtitle'];
$Company = $_POST['company'];
$Phone = $_POST['phone'];
$Code = $_POST['code'];
$Subject = "Contest Form";
$Message = "
Name: $Name
Job Title: $Jobtitle
Company: $Company
Phone: $Phone
Email: $Email
Code: $Code";
 
mail("me@mywebsite.com",$Subject, $Message,"From: $Name <$Email>");    
 
 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $formValues = $_POST;
    $formErrors = array();
    
    if (!VerifyForm($formValues, $formErrors))
        DisplayForm($formValues, $formErrors);
    else
        ProcessForm($formValues);
}
else
    DisplayForm(null, null);
?>

Open in new window

0
 

Author Comment

by:risigm
ID: 24371321
ugh... I still can't figure out what I'm doing wrong. :(
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 24372610
The ProcessForm() function is removed in your last code, the email is sent first when you display the form (with blank values) and again when you submit it. Put this into line 210:

function ProcessForm($formValues) {

...and a } at line 227 to end the function.

You should also have "exit;" in lines 6 and 10.
0
 

Author Comment

by:risigm
ID: 24381095
thank you!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question