/    Sign up×
Community /Pin to ProfileBookmark

Help With Captcha

The following is my code. However I can send the form and it gives me an error page and doesn’t require the captcha to be entered. Any help is much appreciated.

<?php

session_start();

if(isset($_POST[‘submit’])) {

if(!empty($_POST[‘Name’]) && !empty($_POST[‘Email’]) && !empty($_POST[‘Phone’]) && !empty($_POST[‘Comments’]) && !empty($_POST[‘code’])) {

if($_POST[‘code’] == $_SESSION[‘rand_code’]) {

// send email
$accept = “Thank you for contacting me.”;

} else {

$error = “Please verify that you typed in the correct code.”;

}

} else {

$error = “Please fill out the entire form.”;

}

}

?>

<style type=”text/css”>
body,td,th {
font-family: “Times New Roman”, Times, serif;
color: #FFF;
}
body {
background-color: #000;
}
a:link {
color: #9CF;
}
a:visited {
color: #FCF;
}
a:hover {
color: #C9C;
}
a:active {
color: #96F;
}

#header {
}
#babypics {
}
#InfantPhotography {
font-family: “Brush Script MT”;
font-size: 36px;
color: #F5B9F7;
font-weight: bold;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#ServingDFW {
font-family: “Times New Roman”, Times, serif;
font-size: 24px;
color: #A4D7E8;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Printgifts {
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Sessions {
font-family: “Brush Script MT”;
font-size: 36px;
color: #99C;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Price {
font-family: “Times New Roman”, Times, serif;
font-size: 24px;
font-weight: bold;
color: #F0F;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#text {
font-family: “Times New Roman”, Times, serif;
font-size: 18px;
color: #FFF;
text-align: center;
margin-top: 15px;
margin-right: 310px;
margin-bottom: 15px;
margin-left: 50px;
}
#PackageHead {
font-family: “Brush Script MT”;
font-size: 36px;
color: #09F;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#packagedetails {
font-family: “Times New Roman”, Times, serif;
font-size: 16px;
font-weight: bold;
color: #FFF;
list-style-position: inside;
list-style-type: square;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Setappointmentform {
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#footer {
text-align: center;
}
#familypackagesright {
float: right;
width: 250px;
margin: 15px;
padding: 5px;
}
</style>

<title>Children</title>
<script src=”SpryAssets/SpryValidationTextField.js” type=”text/javascript”></script>
<link href=”SpryAssets/SpryValidationTextField.css” rel=”stylesheet” type=”text/css” />
<div id=”header”><?php include_once’template_header.php’?></div>
<div id=”babypics”>
<table width=”200″ border=”0″ align=”center” cellpadding=”5″ cellspacing=”5″>
<tr>
<td><img src=”Sample Images/7.JPG” width=”174″ height=”116″ /></td>
<td><img src=”Sample Images/5 – Copy.jpg” width=”174″ height=”116″ /></td>
<td><img src=”Sample Images/PICT2819.jpg” width=”116″ height=”174″ /></td>
<td><img src=”Sample Images/DSC01135.JPG” width=”174″ height=”116″ /></td>
<td><img src=”Sample Images/PICT6287.JPG” width=”116″ height=”174″ /></td>
</tr>
</table>
</div>
<div id=”familypackagesright”><?php include_once’growing_packages_details.php’?></div>
<div id=”InfantPhotography”>Children Photography</div>
<div id=”ServingDFW”>Serving Fort Worth &amp; Denton County Texas</div>
<div id=”Printgifts”>
<table width=”423″ border=”0″ align=”center” cellpadding=”5″ cellspacing=”5″>
<tr>
<td colspan=”2″ align=”center” valign=”top”><a href=”print_package_prices.php”>Price List</a></td>
<td width=”248″ align=”center” valign=”top”><form action=”https://www.paypal.com/cgi-bin/webscr” method=”post”>
<input type=”hidden” name=”cmd” value=”_s-xclick” />
<input type=”hidden” name=”hosted_button_id” value=”E755J6G65EGBG” />
<input type=”image” src=”https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/btn/btn_gift_SM.gif” border=”0″ name=”submit” alt=”PayPal – The safer, easier way to pay online!” />
<img alt=”” border=”0″ src=”https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/scr/pixel.gif” width=”1″ height=”1″ />
</form></td>
</tr>
</table>
</div>
<div id=”Sessions”>Session Price</div>
<div id=”Price”>$125</div>
<div id=”text”>
<p>* Each session is normally about one hour long <br />
(we allow time for kids to be kids)<br />
*
We allow for up to two outfit changes<br />
* Session location is total up to you</p>
</div>
<div id=”PackageHead”>Package Includes</div>
<div id=”packagedetails”>*
Unlimited Images Taken <br />
* $50 Photo Credit<br />
*
All photos on CD w/ Edits (High Resolution)<br />
* Online Album of your images(Family and Friends can order all the prints they want)</div>
<div id=”Setappointmentform”>
<p>To Set up an Appointment Contact us<br>
<img src=”webimages/phonenumber.jpg” width=”184″ height=”35″ alt=”Call Us”> <br>
or<br>
<img src=”webimages/emailaddress.jpg” alt=”Email Us” width=”248″ height=”29″ border=”0″ usemap=”#Map”>
<map name=”Map”>
<area shape=”rect” coords=”5,4,246,25″ href=”mailto:[email protected]” alt=”Email Us”>
</map>
</p>
<p>&nbsp;</p>
<?php if(!empty($error)) echo ‘<div class=”error”>’.$error.'</div>’; ?>
<?php if(!empty($accept)) echo ‘<div class=”accept”>’.$accept.'</div>’; ?>

<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>, appointment.php” method=”post” enctype=”multipart/form-data”>
<label for=”Name”>Name:</label>
<input type=”text” name=”Name” id=”Name”>
<label for=”Email”>Email</label>
<span id=”sprytextfield1″>
<input type=”text” name=”Email” id=”Email” />
<span class=”textfieldRequiredMsg”>A value is required.</span><span class=”textfieldInvalidFormatMsg”>Invalid format.</span></span>
<p>
<label for=”Phone”>Phone</label>
<span id=”sprytextfield2″>
<input type=”text” name=”Phone” id=”Phone” />
(000-000-0000)
<span class=”textfieldRequiredMsg”>A value is required.</span><span class=”textfieldInvalidFormatMsg”>Invalid format.</span></span>
<label for=”Comments”><br>
<br>
Comments</label>
<textarea name=”Comments” id=”Comments” cols=”45″ rows=”5″></textarea>
</p>
<img src=”captcha.php”/>
<p><input type=”text” name=”code” /> Are you human?</p>
<input type=”submit” name=”submit” value=”Send” class=”button” /></p>
</p>
</form>
<p>&nbsp;</p>
</div>
<div id=”footer”><?php include_once’template_footer.php’?></div>
<script type=”text/javascript”>
var sprytextfield1 = new Spry.Widget.ValidationTextField(“sprytextfield1”, “email”, {validateOn:[“blur”, “change”]});
var sprytextfield2 = new Spry.Widget.ValidationTextField(“sprytextfield2”, “phone_number”, {format:”phone_custom”, pattern:”000-000-0000″, hint:”000-000-0000″});
</script>

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@tracknutMar 16.2011 — I am not a huge fan of this "combine everything into one page" style of coding forms, and that's probably what's got you screwed up. You've got everything there, but I think you're tripping over whether the page is to display the form, or whether it's to process the submitted results. Another thing, I'm not under the impression you can put a comma-separated list of pages in your "action" attribute. So I pulled out the second one and rearranged some things so you can see it work just for the form. Then you can add back in a link to your appointment page, I 'd suggest a header() call from the form processor instead.

The following code is just enough to make the form correctly call itself and display the passed $_POST parameters, it isn't a complete solution ?

<i>
</i>&lt;?php

session_start();
if(isset($_POST['submit'])) {
print_r ($_POST);
die ();
if(!empty($_POST['Name']) &amp;&amp; !empty($_POST['Email']) &amp;&amp; !empty($_POST['Phone']) &amp;&amp; !empty($_POST['Comments']) &amp;&amp; !empty($_POST['code'])) {

if($_POST['code'] == $_SESSION['rand_code']) {

// send email
echo "Thank you for contacting me.";
die ();
} else {

$error = "Please verify that you typed in the correct code.";

}

} else {

$error = "Please fill out the entire form.";

}

}

?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;

&lt;head&gt;
&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"&gt;
&lt;title&gt;Children&lt;/title&gt;
&lt;/head&gt;


&lt;style type="text/css"&gt;
body,td,th {
font-family: "Times New Roman", Times, serif;
color: #FFF;
}
body {
background-color: #000;
}
a:link {
color: #9CF;
}
a:visited {
color: #FCF;
}
a:hover {
color: #C9C;
}
a:active {
color: #96F;
}

#header {
}
#babypics {
}
#InfantPhotography {
font-family: "Brush Script MT";
font-size: 36px;
color: #F5B9F7;
font-weight: bold;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#ServingDFW {
font-family: "Times New Roman", Times, serif;
font-size: 24px;
color: #A4D7E8;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Printgifts {
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Sessions {
font-family: "Brush Script MT";
font-size: 36px;
color: #99C;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Price {
font-family: "Times New Roman", Times, serif;
font-size: 24px;
font-weight: bold;
color: #F0F;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#text {
font-family: "Times New Roman", Times, serif;
font-size: 18px;
color: #FFF;
text-align: center;
margin-top: 15px;
margin-right: 310px;
margin-bottom: 15px;
margin-left: 50px;
}
#PackageHead {
font-family: "Brush Script MT";
font-size: 36px;
color: #09F;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#packagedetails {
font-family: "Times New Roman", Times, serif;
font-size: 16px;
font-weight: bold;
color: #FFF;
list-style-position: inside;
list-style-type: square;
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#Setappointmentform {
text-align: center;
margin-top: 15px;
margin-right: 275px;
margin-bottom: 15px;
margin-left: 15px;
}
#footer {
text-align: center;
}
#familypackagesright {
float: right;
width: 250px;
margin: 15px;
padding: 5px;
}
&lt;/style&gt;

&lt;title&gt;Children&lt;/title&gt;
&lt;script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /&gt;
&lt;body&gt;
&lt;div id="header"&gt;&lt;?php include_once'template_header.php'?&gt;&lt;/div&gt;
&lt;div id="babypics"&gt;
&lt;table width="200" border="0" align="center" cellpadding="5" cellspacing="5"&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="Sample Images/7.JPG" width="174" height="116" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="Sample Images/5 - Copy.jpg" width="174" height="116" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="Sample Images/PICT2819.jpg" width="116" height="174" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="Sample Images/DSC01135.JPG" width="174" height="116" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="Sample Images/PICT6287.JPG" width="116" height="174" /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;div id="familypackagesright"&gt;&lt;?php include_once'growing_packages_details.php'?&gt;&lt;/div&gt;
&lt;div id="InfantPhotography"&gt;Children Photography&lt;/div&gt;
&lt;div id="ServingDFW"&gt;Serving Fort Worth &amp;amp; Denton County Texas&lt;/div&gt;
&lt;div id="Printgifts"&gt;
&lt;table width="423" border="0" align="center" cellpadding="5" cellspacing="5"&gt;
&lt;tr&gt;
&lt;td colspan="2" align="center" valign="top"&gt;&lt;a href="print_package_prices.php"&gt;Price List&lt;/a&gt;&lt;/td&gt;
&lt;td width="248" align="center" valign="top"&gt;&lt;form action="https://www.paypal.com/cgi-bin/webscr" method="post"&gt;
&lt;input type="hidden" name="cmd" value="_s-xclick" /&gt;
&lt;input type="hidden" name="hosted_button_id" value="E755J6G65EGBG" /&gt;
&lt;input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/btn/btn_gift_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /&gt;
&lt;img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/scr/pixel.gif" width="1" height="1" /&gt;
&lt;/form&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;div id="Sessions"&gt;Session Price&lt;/div&gt;
&lt;div id="Price"&gt;$125&lt;/div&gt;
&lt;div id="text"&gt;
&lt;p&gt;* Each session is normally about one hour long &lt;br /&gt;
(we allow time for kids to be kids)&lt;br /&gt;
* We allow for up to two outfit changes&lt;br /&gt;
* Session location is total up to you&lt;/p&gt;
&lt;/div&gt;
&lt;div id="PackageHead"&gt;Package Includes&lt;/div&gt;
&lt;div id="packagedetails"&gt;* Unlimited Images Taken &lt;br /&gt;
* $50 Photo Credit&lt;br /&gt;
* All photos on CD w/ Edits (High Resolution)&lt;br /&gt;
* Online Album of your images(Family and Friends can order all the prints they want)&lt;/div&gt;
&lt;div id="Setappointmentform"&gt;
&lt;p&gt;To Set up an Appointment Contact us&lt;br&gt;
&lt;img src="webimages/phonenumber.jpg" width="184" height="35" alt="Call Us"&gt; &lt;br&gt;
or&lt;br&gt;
&lt;img src="webimages/emailaddress.jpg" alt="Email Us" width="248" height="29" border="0" usemap="#Map"&gt;
&lt;map name="Map"&gt;
&lt;area shape="rect" coords="5,4,246,25" href="mailto:[email protected]" alt="Email Us"&gt;
&lt;/map&gt;
&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;?php if(!empty($error)) echo '&lt;div class="error"&gt;'.$error.'&lt;/div&gt;'; ?&gt;
&lt;?php if(!empty($accept)) echo '&lt;div class="accept"&gt;'.$accept.'&lt;/div&gt;'; ?&gt;

&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post" enctype="multipart/form-data"&gt;
&lt;label for="Name"&gt;Name:&lt;/label&gt;
&lt;input type="text" name="Name" id="Name"&gt;
&lt;label for="Email"&gt;Email&lt;/label&gt;
&lt;span id="sprytextfield1"&gt;
&lt;input type="text" name="Email" id="Email" /&gt;
&lt;span class="textfieldRequiredMsg"&gt;A value is required.&lt;/span&gt;&lt;span class="textfieldInvalidFormatMsg"&gt;Invalid format.&lt;/span&gt;&lt;/span&gt;
&lt;p&gt;
&lt;label for="Phone"&gt;Phone&lt;/label&gt;
&lt;span id="sprytextfield2"&gt;
&lt;input type="text" name="Phone" id="Phone" /&gt;
(000-000-0000)
&lt;span class="textfieldRequiredMsg"&gt;A value is required.&lt;/span&gt;&lt;span class="textfieldInvalidFormatMsg"&gt;Invalid format.&lt;/span&gt;&lt;/span&gt;
&lt;label for="Comments"&gt;&lt;br&gt;
&lt;br&gt;
Comments&lt;/label&gt;
&lt;textarea name="Comments" id="Comments" cols="45" rows="5"&gt;&lt;/textarea&gt;
&lt;/p&gt;
&lt;img src="captcha.php"/&gt;
&lt;p&gt;&lt;input type="text" name="code" /&gt; Are you human?&lt;/p&gt;
&lt;input type="submit" name="submit" value="Send" class="button" /&gt;&lt;/p&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;div id="footer"&gt;&lt;?php include_once'template_footer.php'?&gt;&lt;/div&gt;
&lt;script type="text/javascript"&gt;
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "email", {validateOn:["blur", "change"]});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "phone_number", {format:"phone_custom", pattern:"000-000-0000", hint:"000-000-0000"});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@shutterbugauthorMar 16.2011 — I will try that and see what happens

Thank you very much for you help and time.
Copy linkTweet thisAlerts:
@shutterbugauthorMar 17.2011 — How do I tell it to double check then Captcha then send to appointment.php

This is what I get

Array ( [Name] => Testing [Email] => [email protected] [Phone] => 817-917-9705 [Comments] => Testing [code] => fsrtm [submit] => Send ) [B][/B]

Thanks in advance

If I change this part to appointment.php then it works. If I keep it for checking the Captcha then I get the above problem.

<form action="appointment.php" method="post" enctype="multipart/form-data">
×

Success!

Help @shutterbug spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...