?
Solved

Problem using Java script to submit PHP form data

Posted on 2009-04-20
15
Medium Priority
?
1,089 Views
Last Modified: 2013-11-23
I am trying to submit form data to Salesforce.com.  I have a specialrequest.php page that the presents the text fields with a submit button and special_request_process.php page to validate the data and post to Salesforce.com.  I am using hiddenfields on the process page and Java script to post the data that was entered and validated.  Both pages are displayed below.

The data is passed to Salesforce.com, but I also get these Notices:

Notice: Undefined index: first_name in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 21

Notice: Undefined index: last_name in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 22

Notice: Undefined index: company in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 23

Notice: Undefined index: email in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 24

Notice: Undefined index: phone in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 25
     
Use Back - Please Complete All Required Information
Please Go back!

Can anyone help me determine what is causing the messages, and also why it always results in "Use Back - Please Complete All Required Information" as if a value has no data?

I am new at this and any help is appreciated.

Thanks
specialrequest.php code:
 
<!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>Success Associates-Essentials of Succession Planning</title>
 
 
<style>
 
body{
	margin:0;
	padding:0;
	font-family:Verdana, Helvetica, sans-serif;
	color:#565656;
	background:url(images/background_blue.gif) 0 0 repeat-x #cccccc;
	}
#wrapper{
	margin:0 auto 10px auto;
	width:798px;
	border:1px solid #333;
	background-color:#fff;
 
	}
 
#contentRight{
	background-color:#d0e2f0;
	float:right;
	width:320px;
	padding:10px;
 
	}
 
 
#contentLeft{
	background-color:#fff;
	float:left;
	width:410px;
	padding: 10px 0 0 20px;
 
	}
 
.darkBlue{
	color:#003f7a;
	}
 
h1{ padding:5px 0 15px 20px;
margin:0;
	font-size:24px;
	color:#003f7a;
	}
h2{ margin:0;
	font-size:20px;
	color:#003f7a;
	font-weight:normal;
	}
 
h3{ margin:0;
	font-size:16px;
	color:#003f7a;
	font-weight:bold;
	}
h4{ margin:0;
	font-size:12px;
	color:#666666;
	text-transform:uppercase;
	font-weight:normal;
	}
 
 
ul li{
	color:#003f7a;
	padding-bottom:10px;
font-size:17px;
list-style-image:url(images/bullets.gif);
	}
 
	form{padding:0 0 0 15px;
	margin:0;}
.formsize{
	margin-left:10px;
	width:200px;
	color:#999;
	}
 
.regtext{font-size:12px;}
.regtextSM{font-size:9px;}
 
 
#footer{
	width:798px;
	margin:0 auto;
	font-size:11px;
	text-align:center
	}
#footer a{
	font-size:11px;
	color:#003f7a;
	}
 
 
</style>
 
</head>
 
<body>
 
<div id="wrapper">
 
<div id="header">
  <img src="images/hdr_success_associates.gif" width="798" height="96" alt="Success Associates Logo" />
 
  <h1>Are You Downsizing When You Should be Rightsizing?</h1>
  </div>
<div id="content">
 
 
<div id="contentRight">
<h3>Essentials of Succession Planning</h3>
<h4>Free White paper</h4>
<p><img src="images/documents.gif" width="280" height="164" alt="Documnets" /></p>
 
 
<form action="special_request_process.php" method="post">
 
 
  <p class="regtext" style="font-weight:bold; color:#003f7a;">
<input type="checkbox" name="sendWhitepaper" checked/>Yes, Send Me Your Free Succession
Planning White Paper.</p>
 
 
<p class="regtext" ; color:black;">
<tr class="BlackText">
<td>First Name:<font color="#ff6600"> *</font></td>
<td> <input style="background-color: white" name="first_name" id="first_name" size="25" type="text"><span class="BlackText"> </span> </td></tr>
<tr class="BlackText"><br/>
<td>Last Name:<font color="#ff6600"> *</font></td>
<td> <input style="background-color: white" name="last_name" id="last_name" size="25" type="text"><span class="BlackText"> </span> </td></tr>
<tr class="BlackText">
<td> Company:&nbsp;&nbsp;&nbsp;<font color="#ff6600">*</font></td>
<td> <input style="background-color: white" name="company" id="company" size="25" type="text"><span class="BlackText"> </span> </td></tr><br>
<tr class="BlackText">
<td> E&#150;Mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff6600"> *</font> </td>
<td> <input style="background-color: white" name="email" id="email" size="25" type="text"><span class="BlackText"> </span> </td></tr>
<tr class="BlackText">
<td>Phone:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff6600"> *</font></td>
<td> <input style="background-color: white" name="phone" id="phone" size="25" type="text"><span class="BlackText"> </span> </td></tr>
</p>
 
 
 
 
<!--<p><img src="images/btn_access_now.gif" width="157" height="46" alt="Access now" /></p>-->
 
<input type="submit" name="Submit" value="Send"></td>
 
<!--<p class="regtext"><input type="checkbox" name="ReceiveEmails" checked/>Yes, I would like to receive periodic e-mail updates related to succession planning from Success Associates.</p> -->
<p class="regtextSM"> * Required Fields</p>
<p class="regtextSM">Success Associates does not share or sell e-mail addresses collected via our Web site to third-parties. For our complete <a href="http://www.successassociates.com/privacy_policy.html">Privacy Policy</a>, click here.</p>
 
 
</form>
 
 
</div>
 
<div id="contentLeft">
 
 
<h2>
How Succession Planning Can
Ensure You're Retaining Your
Top Talent in Turbulent Times
</h2>
 
 
<p>In today's economic climate, HR leaders are challenged to facilitate collaborative processes to identify, develop and retain your organizations top 50 to 300 leaders; and may involve difficult decisions as to which leaders to include in a reduction in force.
 </p>
 
<p>Download our Free Guide to 'Implementing Succession Planning in a Downturn' where you'll learn:</p>
 
 
<ul>
<li>The cost reduction business case for implementing succession management</li>
<li>Why <em><strong>now</strong></em> is a great time to accelerate
    systematic leadership planning efforts
</li>
<li>Rapid implementation provides valuable
   decision support in as little as 6 weeks.
</li>
</ul>
 
 
</div>
 
<p style="clear:both"></p>
</div>
 
</div>
<div id="footer">    &copy; 2009 Success Associates, Inc. All Rights Reserved. &nbsp; &nbsp;  <a href="http://www.successassociates.com/contact_us/">Contact Us</a> | <a href="http://www.successassociates.com/privacy_policy.html">Privacy</a> | <a href="http://www.successassociates.com/legal.html">Legal</a> | <a href="http://www.successassociates.com/index.html">Home</a></div>
</body>
</html>
  
=============================================================================
 
special_request_process.php code:
 
<!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">
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Success Associates </title>
</head>
 
<body>
<!--Required code to submit to SaleForce.com-->
<form  name="sfdotcom" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input type=hidden name="oid"    value="#############" >
<input type=hidden name="return" value="#############">
 
 
<?php
//data for Salesforce.com
// validation expected data exists
 
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$company =  $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
?>
 
 
<input type="hidden"  name="first_name"  id="first_name"                value= <?php  echo $first_name ?> >
<input type="hidden"  name="last_name"   id="last_name"                 value= <?php  echo $last_name ?> >
<input type="hidden"  name="company"     id="company"    maxlength="40" value= <?php  echo $company ?> >
<input type="hidden"  name="phone"       id="phone"                     value= <?php  echo $phone ?> >
<input type="hidden"  name="email"       id="email"                     value= <?php  echo $email ?> >
<input type="hidden"  name="lead_source" id="lead_source"               value= "Web Contact" >
 
<?php
//Test inputed email for proper format
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Request was NOT submitted</h2>\n";
echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \">Please go back and complete or enter a valid email address.</a>");
}
//Test that all required fields have data
if(empty($first_name) || empty($last_name) || empty($company) || empty($email) || empty($phone)) {
echo "<h2>Use Back - Please Complete All Required Information</h2>\n";
die ("<a href= \"# \" onclick= \"history.back(); \">Please Go back!</a>");
}
?>
</form>
 
 
 
<p align="center">
<!--Successful request submission message-->
<?php// $todayis = date("l, F j, Y - g:i a") ;?>
<?php// echo $todayis ?>
<br />
<br >
Thank You <?php echo $first_name." ".$last_name ?> at <?php echo $email ?>. Your request was submitted and you will receive your copy of Essentials of Succession Planning by email.
<br>
<br>
<!--Remember to change the address back to production site -->
<a href="http://www.successassociates.com"> Click here to return to the Success Associates Website </a>
 
<?php phpinfo()
?>
<script language="JavaScript">
// Explicit Form Submit so data is sent to SalesForce.com
document.sfdotcom.submit();
</script>
</body>
</html>

Open in new window

0
Comment
Question by:s_c_alderfer
  • 8
  • 7
15 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24187354
Use quotes on the html attributes:

<input type="hidden"  name="first_name"  id="first_name"                value= <?php  echo $first_name ?> >

...should be:

<input type="hidden"  name="first_name"  id="first_name"                value="<?php  echo $first_name ?>" />
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24187520
At the start of special_request_process.php, line 228 in the snippet, insert this:

var_dump($_POST);

This will let you see the content of the $_POST array.
0
 

Author Comment

by:s_c_alderfer
ID: 24187844
I added the " and inserted the var_dump as you can see below:

<!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">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Success Associates </title>
</head>

<body>
<!--Required code to submit to SaleForce.com-->
<form  name="sfdotcom" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input type=hidden name="oid"    value="#############" >
<input type=hidden name="return" value="#############">


<?php
//data for Salesforce.com
// validation expected data exists
var_dump($_POST);

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$company =  $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
?>



<input type="hidden"  name="first_name"  id="first_name"                value= "<?php  echo $first_name ?>" / >
<input type="hidden"  name="last_name"   id="last_name"                 value= "<?php  echo $last_name ?>" / >
<input type="hidden"  name="company"     id="company"    maxlength="40" value= "<?php  echo $company ?>" / >
<input type="hidden"  name="phone"       id="phone"                     value= "<?php  echo $phone ?>" / >
<input type="hidden"  name="email"       id="email"                     value= "<?php  echo $email ?>" / >
<input type="hidden"  name="lead_source" id="lead_source"               value= "Web Contact" >

<?php
================================================================================
This is the output:

  array(0) { }
Notice: Undefined index: first_name in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 22

Notice: Undefined index: last_name in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 23

Notice: Undefined index: company in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 24

Notice: Undefined index: email in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 25

Notice: Undefined index: phone in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 26
     
Use Back - Please Complete All Required Information
Please Go back!

I did a test on our website running fiddler and can see the values that are sent to Saleforce.com.  

I think my problem is the Javascript submit, where it does the submit to Salesforce.com, but then also runs through the validation again and at that time the values are null.  Do you know of a way to submit/post only the data values?

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:s_c_alderfer
ID: 24187896
I just retested, and noticed that a page with the variables briefly appears, and then the final page
 array(0) { }
Notice: Undefined index: first_name in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 22

Notice: Undefined index: last_name in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 23

Notice: Undefined index: company in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 24

Notice: Undefined index: email in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 25

Notice: Undefined index: phone in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 26
     
Use Back - Please Complete All Required Information
Please Go back!

Thanks
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24188377
There is a hidden variable here, sent to salesforce.com together with the other parameters:

<input type=hidden name="return" value="#############">

Does the value contain special_request_process.php ?

Is it possible that salesforce.com processes the request, and then redirects back to special_request_process.php? It looks like this is whats happening.

If so, make a new page for the "return" parameter.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24188425
Heh... I just tried to click the link in the action attribute:

https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8

It redirects back to the page where it came from... i.e. this page. :)

To get rid of the errors:

if($_POST) {
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $company =  $_POST['company'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
}

...and the javascript must only be written when the form is posted:

<?php
if($_POST) {
echo '<script language="JavaScript">
document.sfdotcom.submit();
</script>';
}
?>
0
 

Author Comment

by:s_c_alderfer
ID: 24188738
That gets me past the notices I was getting but it now it is having issues with the data validation code.
My updated code is below This is the message that  I get:
       
Notice: Undefined variable: email in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 39

Use Back - Please Complete All Required Information

====================================================

<!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">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Success Associates </title>
</head>

<body>
<!--Required code to submit to SaleForce.com-->
<form  name="sfdotcom" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input type=hidden name="oid"    value="alphanumericstring" >
<input type=hidden name="return" value="www.successassociates.com">


<?php
//data for Salesforce.com
// validation expected data exists

if($_POST) {
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $company =  $_POST['company'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
}

?>
<input type="hidden"  name="first_name"  id="first_name"                value= "<?php  echo $first_name ?>" / >
<input type="hidden"  name="last_name"   id="last_name"                 value= "<?php  echo $last_name ?>" / >
<input type="hidden"  name="company"     id="company"    maxlength="40" value= "<?php  echo $company ?>" / >
<input type="hidden"  name="phone"       id="phone"                     value= "<?php  echo $phone ?>" / >
<input type="hidden"  name="email"       id="email"                     value= "<?php  echo $email ?>" / >
<input type="hidden"  name="lead_source" id="lead_source"               value= "Web Contact" >

<?php
//Test inputed email for proper format
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Request was NOT submitted</h2>\n";
echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \">Please go back and complete or enter a valid email address.</a>");
}
?>
<?php
//Test that all required fields have data
if(empty($first_name) || empty($last_name) || empty($company) || empty($email) || empty($phone)) {
echo "<h2>Use Back - Please Complete All Required Information</h2>\n";
die ("<a href= \"# \" onclick= \"history.back(); \">Please Go back!</a>");
}
?>
</form>



<p align="center">
<!--Successful request submission message-->
<?php $todayis = date("l, F j, Y - g:i a") ;?>
<?php echo $todayis ?>
<br />
<br >
Thank You <?php echo $first_name." ".$last_name ?> at <?php echo $email ?>. Your request was submitted and you will receive your copy of Essentials of Succession Planning by email.
<br>
<br>
<!--Remember to change the address back to production site -->
<a href="http://www.successassociates.com"> Click here to return to the Success Associates Website </a>


<?php
if($_POST) {
echo '<script language="JavaScript">
document.sfdotcom.submit();
</script>';
}
?>
</body>
</html>

I tried using the same code to verify the variables before validation with this code:

I get this error using this code.

Parse error: parse error in C:\Program Files\Apache Group\Apache2\htdocs\specials\special_request_process.php on line 41

==========================================================================

<!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">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Success Associates </title>
</head>

<body>
<!--Required code to submit to SaleForce.com-->
<form  name="sfdotcom" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input type=hidden name="oid"    value="alphanumericstring" >
<input type=hidden name="return" value="www.successassociates.com">


<?php
//data for Salesforce.com
// validation expected data exists

if($_POST) {
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $company =  $_POST['company'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
}

?>
<input type="hidden"  name="first_name"  id="first_name"                value= "<?php  echo $first_name ?>" / >
<input type="hidden"  name="last_name"   id="last_name"                 value= "<?php  echo $last_name ?>" / >
<input type="hidden"  name="company"     id="company"    maxlength="40" value= "<?php  echo $company ?>" / >
<input type="hidden"  name="phone"       id="phone"                     value= "<?php  echo $phone ?>" / >
<input type="hidden"  name="email"       id="email"                     value= "<?php  echo $email ?>" / >
<input type="hidden"  name="lead_source" id="lead_source"               value= "Web Contact" >

<?php
//Test inputed email for proper format
if($_POST) {
      $email = $_POST['email']
      }
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Request was NOT submitted</h2>\n";
echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \">Please go back and complete or enter a valid email address.</a>");
}
?>
<?php
//Test that all required fields have data
if($_POST) {
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $company =  $_POST['company'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
}
if(empty($first_name) || empty($last_name) || empty($company) || empty($email) || empty($phone)) {
echo "<h2>Use Back - Please Complete All Required Information</h2>\n";
die ("<a href= \"# \" onclick= \"history.back(); \">Please Go back!</a>");
}
?>
</form>



<p align="center">
<!--Successful request submission message-->
<?php $todayis = date("l, F j, Y - g:i a") ;?>
<?php echo $todayis ?>
<br />
<br >
Thank You <?php echo $first_name." ".$last_name ?> at <?php echo $email ?>. Your request was submitted and you will receive your copy of Essentials of Succession Planning by email.
<br>
<br>
<!--Remember to change the address back to production site -->
<a href="http://www.successassociates.com"> Click here to return to the Success Associates Website </a>


<?php
if($_POST) {
echo '<script language="JavaScript">
document.sfdotcom.submit();
</script>';
}
?>
</body>
</html>

Thanks for your help!
0
 

Author Comment

by:s_c_alderfer
ID: 24188907
I found the issue, I forgot the ending ; on that line.

It seems I have a problem with the logic of my email validation.  I enter a valid email, but I stiil get the response that it is either imcomplete or incorrect.  I changed the error message so there is only one phrase that is a link back to the form.

"Please go back and complete or enter a valid email address."

===============================================================================
Do you see what the problem might be?

<!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">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Success Associates </title>
</head>

<body>
<!--Required code to submit to SaleForce.com-->
<form  name="sfdotcom" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input type=hidden name="oid"    value="################" >
<input type=hidden name="return" value="www.successassociates.com">


<?php
//data for Salesforce.com
// validation expected data exists

if($_POST) {
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $company =  $_POST['company'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
}

?>
<input type="hidden"  name="first_name"  id="first_name"                value= "<?php  echo $first_name ?>" / >
<input type="hidden"  name="last_name"   id="last_name"                 value= "<?php  echo $last_name ?>" / >
<input type="hidden"  name="company"     id="company"    maxlength="40" value= "<?php  echo $company ?>" / >
<input type="hidden"  name="phone"       id="phone"                     value= "<?php  echo $phone ?>" / >
<input type="hidden"  name="email"       id="email"                     value= "<?php  echo $email ?>" / >
<input type="hidden"  name="lead_source" id="lead_source"               value= "Web Contact" >

<?php
//Test inputed email for proper format
if($_POST) {
      $email = $_POST['email'];
}
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")));
{
//echo "<h2>Use Back - Enter valid e-mail</h2>\n";
//$badinput = "<h2>Request was NOT submitted</h2>\n";
//echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \"><h2>Please go back and complete or enter a valid email address.</a>");
}
?>
<?php
//Test that all required fields have data
if($_POST) {
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $company =  $_POST['company'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
}
if(empty($first_name) || empty($last_name) || empty($company) || empty($email) || empty($phone)) {
echo "<h2>Use Back - Please Complete All Required Information</h2>\n";
die ("<a href= \"# \" onclick= \"history.back(); \">Please Go back!</a>");
}
?>
</form>



<p align="center">
<!--Successful request submission message-->
<?php $todayis = date("l, F j, Y - g:i a") ;?>
<?php echo $todayis ?>
<br />
<br >
Thank You <?php echo $first_name." ".$last_name ?> at <?php echo $email ?>. Your request was submitted and you will receive your copy of Essentials of Succession Planning by email.
<br>
<br>
<!--Remember to change the address back to production site -->
<a href="http://www.successassociates.com"> Click here to return to the Success Associates Website </a>


<?php
if($_POST) {
echo '<script language="JavaScript">
document.sfdotcom.submit();
</script>';
}
?>
</body>
</html>
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24188968
You forgot a semicolon. Change this:

if($_POST) {
      $email = $_POST['email']
      }

into this:

if($_POST) {
      $email = $_POST['email'];
      }
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24188994
Don't test unless it is a POST operation. Change this:

<?php
//Test inputed email for proper format
if($_POST) {
      $email = $_POST['email'];
}
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")));
{
//echo "<h2>Use Back - Enter valid e-mail</h2>\n";
//$badinput = "<h2>Request was NOT submitted</h2>\n";
//echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \"><h2>Please go back and complete or enter a valid email address.</a>");
}
?>

... into this:

<?php
//Test inputed email for proper format
if($_POST) {
      $email = $_POST['email'];
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")));
{
//echo "<h2>Use Back - Enter valid e-mail</h2>\n";
//$badinput = "<h2>Request was NOT submitted</h2>\n";
//echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \"><h2>Please go back and complete or enter a valid email address.</a>");
}
}
?>
0
 

Author Comment

by:s_c_alderfer
ID: 24189095
That gives me the same response.  

"Please go back and complete or enter a valid email address."

I think what I need here is a test whether the form was already submitted and if so, go to the happy ending message.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24189177
Yes... you should rewrite this script slightly. Instead of testing multiple places with "if($_POST)", you should just split the entire script in two parts, i.e. have "if($_POST)" just once. You need to store firstname/lastname/email somewhere... in session variables for example. Something like this:
<?php session_start(); ?>
<!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">
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Success Associates </title>
</head>
 
<body>
 
<?php if($_POST) { ?>
 
<!--Required code to submit to SaleForce.com-->
<form  name="sfdotcom" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input type=hidden name="oid"    value="################" >
<input type=hidden name="return" value="www.successassociates.com">
 
 
<?php
//data for Salesforce.com
// validation expected data exists
 
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$company =  $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
 
// store name/email in session variables
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
 
?>
<input type="hidden"  name="first_name"  id="first_name"                value= "<?php  echo $first_name ?>" / >
<input type="hidden"  name="last_name"   id="last_name"                 value= "<?php  echo $last_name ?>" / >
<input type="hidden"  name="company"     id="company"    maxlength="40" value= "<?php  echo $company ?>" / >
<input type="hidden"  name="phone"       id="phone"                     value= "<?php  echo $phone ?>" / >
<input type="hidden"  name="email"       id="email"                     value= "<?php  echo $email ?>" / >
<input type="hidden"  name="lead_source" id="lead_source"               value= "Web Contact" >
 
<?php
//Test inputed email for proper format
$email = $_POST['email'];
 
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")));
{
//echo "<h2>Use Back - Enter valid e-mail</h2>\n";
//$badinput = "<h2>Request was NOT submitted</h2>\n";
//echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \"><h2>Please go back and complete or enter a valid email address.</a>");
}
?>
<?php
//Test that all required fields have data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$company =  $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
 
if(empty($first_name) || empty($last_name) || empty($company) || empty($email) || empty($phone)) {
echo "<h2>Use Back - Please Complete All Required Information</h2>\n";
die ("<a href= \"# \" onclick= \"history.back(); \">Please Go back!</a>");
}
?>
</form>
 
<script language="JavaScript">
document.sfdotcom.submit();
</script>
 
<?php }  // end of if($_POST) 
else {
  // fetch name/email from session
  $first_name = $_SESSION['first_name'];
  $last_name = $_SESSION['last_name'];
  $email = $_SESSION['email'];
}
 
?>
 
 
<p align="center">
<!--Successful request submission message-->
<?php $todayis = date("l, F j, Y - g:i a") ;?>
<?php echo $todayis ?>
<br />
<br >
Thank You <?php echo $first_name." ".$last_name ?> at <?php echo $email ?>. Your request was submitted and you will receive your copy of Essentials of Succession Planning by email.
<br>
<br>
<!--Remember to change the address back to production site -->
<a href="http://www.successassociates.com"> Click here to return to the Success Associates Website </a>
 
</body>
</html>

Open in new window

0
 

Author Comment

by:s_c_alderfer
ID: 24189300
Still stops at the email verification with "Please go back and complete or enter a valid email address."

If I comment out the email verification lines 45-54, it works as you expect and ends with the confirmation page.

================================================================================
<?php session_start(); ?>
<!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">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Success Associates </title>
</head>

<body>

<?php if($_POST) { ?>

<!--Required code to submit to SaleForce.com-->
<form  name="sfdotcom" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input type=hidden name="oid"    value="##################" >
<input type=hidden name="return" value="www.successassociates.com">


<?php
//data for Salesforce.com
// validation expected data exists

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$company =  $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];

// store name/email in session variables
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;

?>
<input type="hidden"  name="first_name"  id="first_name"                value= "<?php  echo $first_name ?>" / >
<input type="hidden"  name="last_name"   id="last_name"                 value= "<?php  echo $last_name ?>" / >
<input type="hidden"  name="company"     id="company"    maxlength="40" value= "<?php  echo $company ?>" / >
<input type="hidden"  name="phone"       id="phone"                     value= "<?php  echo $phone ?>" / >
<input type="hidden"  name="email"       id="email"                     value= "<?php  echo $email ?>" / >
<input type="hidden"  name="lead_source" id="lead_source"               value= "Web Contact" >

<?php
//Test inputed email for proper format
$email = $_POST['email'];

if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")));
{
//echo "<h2>Use Back - Enter valid e-mail</h2>\n";
//$badinput = "<h2>Request was NOT submitted</h2>\n";
//echo $badinput;
die ("<a href= \"# \" onclick= \"history.back(); \"><h2>Please go back and complete or enter a valid email address.</a>");
}
?>
<?php
//Test that all required fields have data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$company =  $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];

if(empty($first_name) || empty($last_name) || empty($company) || empty($email) || empty($phone)) {
echo "<h2>Use Back - Please Complete All Required Information</h2>\n";
die ("<a href= \"# \" onclick= \"history.back(); \">Please Go back!</a>");
}
?>
</form>

<script language="JavaScript">
document.sfdotcom.submit();
</script>

<?php }  // end of if($_POST)
else {
  // fetch name/email from session
  $first_name = $_SESSION['first_name'];
  $last_name = $_SESSION['last_name'];
  $email = $_SESSION['email'];
}

?>


<p align="center">
<!--Successful request submission message-->
<?php $todayis = date("l, F j, Y - g:i a") ;?>
<?php echo $todayis ?>
<br />
<br >
Thank You <?php echo $first_name." ".$last_name ?> at <?php echo $email ?>. Your request was submitted and you will receive your copy of Essentials of Succession Planning by email.
<br>
<br>
<!--Remember to change the address back to production site -->
<a href="http://www.successassociates.com"> Click here to return to the Success Associates Website </a>

</body>
</html>

Thanks
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 24189382
This is wrong:

if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")));

First, the semicolon at the end is wrong, remove that. Secondly, the logic in this test is hard to understand... it can be simplified like this:

if(!$email or !strstr($email,"@") or !strstr($email,"."))
0
 

Author Comment

by:s_c_alderfer
ID: 24189448
That did it.

Thank you very much for your help!

I will Accept as Solution but I'm waiting for an edit to one of my posts.

Kind Regards,

Steve
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 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