Newbie in need of help with a contact form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stokkers
Forum Newbie
Posts: 2
Joined: Mon Dec 03, 2012 11:02 am

Newbie in need of help with a contact form

Post by Stokkers »

Hi All

I am trying to get a contact form to work, but it doesn't do what the instructions say it should.

I downloaded a ScriptoMart Captcha Contact Form, edited the feedback.php, uploaded all the files. One of the files is a form.php to try out before editing. The form opens up OK, I entered the captcha code, pressed Submit and was directed to a blank page where there should have been a message. The URL ended in feedback.php.

Can one of you switched on guys help?

This is the form php:

Code: Select all

 

<form name="feedback" method="post" action="feedback.php">
  <table width="400" border="0" align="center" cellpadding="2" cellspacing="2">
    <tr> 
      <td width="145"><strong>Name</strong></td>
      <td width="443"> <input name="name" type="text" id="name" size="25"></td>
    </tr>
    <tr> 
      <td><strong>Email</strong></td>
      <td><input name="email" type="text" id="email" size="25"></td>
    </tr>
    <tr>
      <td valign="top"><strong>Company</strong></td>
      <td><input name="company" type="text" id="company" size="25"></td>
    </tr>
    <tr> 
      <td valign="top"><strong>Comments</strong></td>
      <td><textarea name="Comments" cols="40" rows="5" id="Comments"></textarea></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><p><img id="captcha" src="securimage/securimage_show.php" alt="CAPTCHA Image" /> 
          <br />
          Enter Code:<br />
          <input type="text" name="captcha_code" size="10" maxlength="6" />
          &nbsp;<a href="a href="#" onclick="document.getElementById('captcha').src = 'securimage/securimage_show.php?' + Math.random(); return false""><img src="securimage/images/refresh.gif" alt="Click to refresh the verification image" name="verification" width="22" height="20" border="0" id="verification"></a></p></td>
    </tr>
    <tr> 
      <td><input type="reset" name="Reset" value="Reset"></td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>
And this is the feedback.php:

Code: Select all

 <?php session_start(); ?>

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();

if ($securimage->check($_POST['captcha_code']) == false) {
  // the code was incorrect
  // handle the error accordingly with your other error checking

  // or you can do something really basic like this
  die('The code you entered was incorrect.  Go back and try again.');
}
?>

<?php
# ----------------------------------------------------
# ----- Copyright http://www.scriptomart.com
# ----------------------------------------------------


// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$name = addslashes($_POST['name']);
@$email = addslashes($_POST['email']);
@$company = addslashes($_POST['company']);
@$Comments = addslashes($_POST['Comments']);

// Validation
// You can add additional form with or without validations below.
// You do not need to validate all form entries.
// The company name only can be left empty on this form submission.
if (strlen($name) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid name</font></p>");
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($Comments) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid comments</font></p>");
}

// This sends you the feedback form
// Make sure you edit youremail@yourdomain.com to your correct Email Address
$pfw_header = "From: $email\n"
  . "Reply-To: $email\n";
$pfw_subject = "Feedback Form";
$pfw_email_to = "kxxxx@btinternet.com";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "You have received feedback from your online form.\n"
. "\n"
. "The Visitors Name was: $name\n"
. "Their Email Address is: $email\n"
. "Their Company name is: $company\n"
. "The comments they left for you are below:\n"
. " $Comments\n"
. "\n"
. "Check the Date/Time of this email for response time/date.";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
// Make sure you edit youremail@yourdomain.com to your correct Email Address
$pfw_header = "From: kxxxx@btinternet.com\n"
  . "Reply-To: kxxxx@btinternet.com\n";
$pfw_subject = "Thank you for Contacting us";
$pfw_email_to = "$email";
$pfw_message = "Thank you for your feedback.\n"
. "\n"
. "Should your comments require a response we will do so at the earliest convenient time.\n"
. "\n"
. "Kind Regards\n"
. "\n"
. "Lizzie";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Thank You, Your submission has been sent!</font></p>");
?>

<script type="text/javascript">
<!-- change the below index.php to the page you would like to redirect after submission
function delayer(){
    window.location = "http://www.algethiguesthouse.co.uk/index.htm"
}
//--> to change the delay: 5000 = 5 seconds
</script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
Thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Newbie in need of help with a contact form

Post by social_experiment »

Try using an else statement because what happens if the code is clicked? The code (when you entered the proper verification code) isn't called, i'm guessing that is why you are only getting a blank page. Hth

Code: Select all

if ($securimage->check($_POST['captcha_code']) == false) {
  // the code was incorrect
  // handle the error accordingly with your other error checking

  // or you can do something really basic like this
  die('The code you entered was incorrect.  Go back and try again.');
}
else {
# ----------------------------------------------------
# ----- Copyright http://www.scriptomart.com
# ----------------------------------------------------


// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$name = addslashes($_POST['name']);
@$email = addslashes($_POST['email']);
@$company = addslashes($_POST['company']);
@$Comments = addslashes($_POST['Comments']);

// Validation
// You can add additional form with or without validations below.
// You do not need to validate all form entries.
// The company name only can be left empty on this form submission.
if (strlen($name) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid name</font></p>");
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($Comments) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid comments</font></p>");
}

// This sends you the feedback form
// Make sure you edit youremail@yourdomain.com to your correct Email Address
$pfw_header = "From: $email\n"
  . "Reply-To: $email\n";
$pfw_subject = "Feedback Form";
$pfw_email_to = "kxxxx@btinternet.com";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "You have received feedback from your online form.\n"
. "\n"
. "The Visitors Name was: $name\n"
. "Their Email Address is: $email\n"
. "Their Company name is: $company\n"
. "The comments they left for you are below:\n"
. " $Comments\n"
. "\n"
. "Check the Date/Time of this email for response time/date.";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
// Make sure you edit youremail@yourdomain.com to your correct Email Address
$pfw_header = "From: kxxxx@btinternet.com\n"
  . "Reply-To: kxxxx@btinternet.com\n";
$pfw_subject = "Thank you for Contacting us";
$pfw_email_to = "$email";
$pfw_message = "Thank you for your feedback.\n"
. "\n"
. "Should your comments require a response we will do so at the earliest convenient time.\n"
. "\n"
. "Kind Regards\n"
. "\n"
. "Lizzie";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Thank You, Your submission has been sent!</font></p>");
}
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Stokkers
Forum Newbie
Posts: 2
Joined: Mon Dec 03, 2012 11:02 am

Re: Newbie in need of help with a contact form

Post by Stokkers »

Well, sorted the problem out by accident. I had another problem with the site this morning. Turned out it was the .httaccess was corrupted. Not having had this problem before, I Googled it and discovered it could have been caused by the file permissions. Got them sorted out and my form is now working as it should.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Newbie in need of help with a contact form

Post by Christopher »

Stokkers wrote:...but it doesn't do what the instructions say it should.
That code is very low quality. I am surprised that it came with instructions! I'd recommend rewriting it.
(#10850)
Post Reply