Jump to content


Photo

form script doesn't show any errors but doesn't work either


  • Please log in to reply
9 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 25 October 2006 - 04:35 PM

I have this form script (below) that doesn't produce any errors but does not display any validation errors nor sends the data nor displays the confirmation message. Basically it displays the header/footer and the rest is blank. I don't see the point where it's breaking down.

<?php

// do the security check
if (isset($_POST['submit'])) {
// clean and check form inputs including the secure image code
    $name = trim(strip_tags($_POST['name']));
    $location = trim(strip_tags($_POST['location']));
    $email = trim(strip_tags($_POST['email']));
    $phone = trim(strip_tags($_POST['phone']));
    $best_time = trim(strip_tags($_POST['best_time']));
    $details = trim(strip_tags($_POST['details']));
    $referred_by = trim(strip_tags($_POST['ref_by']));
    $secure = strtoupper(trim(strip_tags($_POST['secure'])));
    $match = $_SESSION['secure']; // the code on the image
}
$err = "";
include 'header.php';
// input error checking
    if ($name=="") {
        $err.= "Please provide your name. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }
    if ($location=="") {
	  $err.= "Please provide your city of residence. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
	}
	if (!$email) {
        $err.= "Please provide your email address. <a href=\"javascript: history.go(-1)\">Back</a><br>";
    }
    if ($email) {
        if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
            $err.= $email. " is not a valid email address. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
        }
    }
    if ($phone=="") {
        $err.= "Please provide a phone number. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }
    if ($best_time=="") {
	  $err.= "Please provide the best time to contact you. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
	}
    if (!$secure) {
        $err.= "No security code entered. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }
    if (($secure!=$match) && ($secure!="")) {
        $err.= "Security code mismatch. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }
    if ($err=="") {

// set mail variables
$to="admin@plateauprofessionals.com";
$subject="Plateau Professionals Inquiry";
$mailContent="--------CONTACT--------\n"
            ."Name: ".$name."\n"
            ."Location: ".$location."\n"
            ."E-mail: ".$email."\n\n--------PHONE--------\n"
            ."Phone: ".$phone."\n"
            ."Best time to call: ".$best_time."\n\n--------Details--------\n"
            ."Details: ".$details."\n"
			."Referred by: ".$referred_by."\n";
// send the results
mail($to, $subject, $mailContent, "From:$email") or print "Could not send email";

echo "<h2>Message Sent</h2><br>\n";
echo "<font class='bodytext'><blockquote>Your message has been sent. A representative will respond as soon as possible. Thank you for contacting Plateau Professionals!</blockquote><br>\n";
}
include 'footer.php';
?>

The form is at www.plateauprofessionals.com/gencontact.php

It's fairly basic with the exception of the CAPTCHA image and has action="sendform.php" which is the script code shown.

#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 25 October 2006 - 04:49 PM

Debug your $err variable. It will only perform the mailing part of your script if $err is empty. Perhaps it isn't?

<?php

$err = "";
include 'header.php';
// input error checking
    if ($name=="") {
        $err.= "Please provide your name. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }
    if ($location=="") {
	  $err.= "Please provide your city of residence. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
	}
	if (!$email) {
        $err.= "Please provide your email address. <a href=\"javascript: history.go(-1)\">Back</a><br>";
    }
    if ($email) {
        if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
            $err.= $email. " is not a valid email address. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
        }
    }
    if ($phone=="") {
        $err.= "Please provide a phone number. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }
    if ($best_time=="") {
	  $err.= "Please provide the best time to contact you. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
	}
    if (!$secure) {
        $err.= "No security code entered. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }
    if (($secure!=$match) && ($secure!="")) {
        $err.= "Security code mismatch. <a href=\"javascript: history.go(-1)\">Back</a><br/>";
    }

echo $err;
exit(); //this will exit the script allowing you to see the value of $err

?>


#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 25 October 2006 - 05:17 PM

heh...silly me. I forgot to put an echo statement to show the various errors. Guess I thought they'd somehow magically appear.  ;D

Only challenge left is the security image. For some reason it's not matching it and continually says the security code entry doesn't match. I KNOW i'm typing them in correctly. See anything in that segment that stands out?

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 October 2006 - 05:19 PM

first thing that stands out to me is this:

$match = $_SESSION['secure']; // the code on the image

i don't see a session_start(); at the beginning of your script, so $match is not being set to anything.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 25 October 2006 - 05:23 PM

Funny you should mention that as i'd just put that in there before receiving your post email. I've added it but it still provides a mismatch error.

My revised code looks like this now:

<?php
session_start();
// do the security check
if (isset($_POST['submit'])) {
// clean and check form inputs including the secure image code
    $name = trim(strip_tags($_POST['name']));
    $location = trim(strip_tags($_POST['location']));
    $email = trim(strip_tags($_POST['email']));
    $phone = trim(strip_tags($_POST['phone']));
    $best_time = trim(strip_tags($_POST['best_time']));
    $details = trim(strip_tags($_POST['details']));
    $referred_by = trim(strip_tags($_POST['ref_by']));
    $secure = strtoupper(trim(strip_tags($_POST['secure'])));
    $match = $_SESSION['secure']; // the code on the image
}
$err = "";
include 'header.php';
// input error checking
    if ($name=="") {
        $err.= "Please provide your name. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>";
    }
    if ($location=="") {
	  $err.= "Please provide your city of residence. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>";
	}
	if (!$email) {
        $err.= "Please provide your email address. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br>";
    }
    if ($email) {
        if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
            $err.= $email. " is not a valid email address. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>";
        }
    }
    if ($phone=="") {
        $err.= "Please provide a phone number. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>";
    }
    if ($best_time=="") {
	  $err.= "Please provide the best time to contact you. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>";
	}
    if (!$secure) {
        $err.= "No security code entered. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>";
    }
    if (($secure!=$match) && ($secure!="")) {
        $err.= "Security code mismatch. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>";
    }
    
//echo $err;
//exit;
      if ($err!='') {
    echo "<center>";
    echo "<strong>Form Error(s)</strong><br/>";
    echo "<font class='bodytext'>The following fields were not completed correctly. Please return to the form and complete them accordingly.<br>\n";
    echo "<font color='#cc3300'>". nl2br($err). "</font><br/>\n";
    echo "</center>";
} else {

// set mail variables
$to="admin@plateauprofessionals.com";
$subject="Plateau Professionals Inquiry";
$mailContent="--------CONTACT--------\n"
            ."Name: ".$name."\n"
            ."Location: ".$location."\n"
            ."E-mail: ".$email."\n\n--------PHONE--------\n"
            ."Phone: ".$phone."\n"
            ."Best time to call: ".$best_time."\n\n--------Details--------\n"
            ."Details: ".$details."\n"
			."Referred by: ".$referred_by."\n";
// send the results
mail($to, $subject, $mailContent, "From:$email") or print "Could not send email";

echo "<h2>Message Sent</h2><br>\n";
echo "<font class='bodytext'><blockquote>Your message has been sent. A representative will respond as soon as possible. Thank you for contacting Plateau Professionals!</blockquote><br>\n";
}
include 'footer.php';
?>

The form input for the security image is basic stuff:

<td><img src="captcha_image.php" alt="security image" border="0"/></td>
</tr>
            <tr>
            <td><p align="right"><font class="bodytext">Verification:</font><br><font size="1">Enter the code shown.</font> </p></td>
            <td><input type="text" name="secure" maxlength="8"></td>


Thanks for your help!

#6 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 25 October 2006 - 05:37 PM

Ok, got it to work by adding this to the sessions:

<?php
session_start();
session_register("secure");
?>

Which then matches the variable match for $_SESSION in the validation process. Form produced no errors and I received the email from the contact form.

Thanks again!

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 October 2006 - 05:38 PM

umm i think that's more of a bandaid than a fix...

echo out $match see if it contains something
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 25 October 2006 - 05:45 PM

It echoes the security code.

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 October 2006 - 05:55 PM

what about before you added that session_register stuff
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 25 October 2006 - 06:01 PM

It echoes nothing if I remove the session lines.

Actually i've removed the session_register lines and just having session_start(); on both the form page and the parsing script makes it work.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users