Jump to content

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


simcoweb

Recommended Posts

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.

[code]<?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';
?>[/code]

The form is at [url=http://www.plateauprofessionals.com/gencontact.php]www.plateauprofessionals.com/gencontact.php[/url]

It's fairly basic with the exception of the CAPTCHA image and has action="sendform.php" which is the script code shown.
Link to comment
Share on other sites

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

[code]
<?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

?>
[/code]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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:

[code]<?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';
?>[/code]

The form input for the security image is basic stuff:

[quote]<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>[/quote]

Thanks for your help!
Link to comment
Share on other sites

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

[code]<?php
session_start();
session_register("secure");
?>[/code]

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.