Form info not being sent

Yes we are. Now that the php is actually being parsed, you can start on the code :smiley:

The code I’m posting hasn’t been tested, the checks on the form field values are very elementary, and I changed the logic so the form sends its values to itself (and not to a separate script) because that way it’s easier to handle errors (IMO). It means that your form page must be called “contact_page.php” instead of “contact_page.html”. After the mail has been sent, it redirects to your confirmation page.
In the code I left out all html that comes before and after the form to keep things simple. You’ll have to add that where I indicated (see script). I hope all is clear :slight_smile:


<?php
// initialize error messages array
$errors = array();

// if the form has been submitted, check the form field values
// if all is ok, send the mail and redirect
// if something is wrong, display the form with error messages

if (isset($_POST['required'])) {

  // check email
  if (!isset($_POST['required']) || trim($_POST['required']) == '') {
    $errors['email'] = 'Email required';
  }

  // check name
  if (!isset($_POST['realname']) || trim($_POST['realname']) == '') {
    $errors['realname'] = 'Name required';
  }

  // check message
  if (!isset($_POST['message']) || trim($_POST['message']) == '') {
    $errors['message'] = 'Message required';
  }

  // if no errors, send mail and redirect
  if (count($errors) == 0) {

    // Subject of email sent to you.
    $subject = 'Results from Contact form'; 

    // Your email address. This is where the form information will be sent. 
    $emailadd = 'xxxxxxx@xxxxxx.com'; 

    // the text to be emailed
    $text = "
      email: " . $_POST['email'] . "\
\

      name: " . $_POST['realname'] . "\
\

      message: " . $_POST['message'] . "\
\

    "; 
 
    mail($emailadd, $subject, $text);
    header('Location: http://www.ijacobs.com/confirmation.html');
    exit();
  }
}

// Below this part you'll have to add all the html code of your 
// form page. For simplicities sake, I'll only show the form code:
?>
...
... add all html here that goes before the form section
...
<section id="form">
<?php
  // show errors, if any
  foreach ($errors as $key => $value) {
    echo "<p>$value</p>";
  }
?>
  <form action="" method="post">
    <input type="hidden" name="required" value="yes"/>
    E-mail: <input type="email" size="30" name="email"/>
    <br />
    Name: <input type="text" size="30" name="realname"/>
    <br />
      Message:<br />
    <textarea cols="30" rows="10" name="message"></textarea>
    <br />
    <input type="submit" value="submit"/>
  </form>
</section>
...
... at all html here that goes after the form section
...

I’ve filled in the page (email address etc) and uploaded it. Changed the index so that it loads the contact_page.php and uploaded them. On clicking the ‘Contact’ button, I get this error message and no Contact Page…

‘Parse error: syntax error, unexpected ‘[’ in /home/ix/public_html/pages/contact_page.php on line 43’

As I am using Html where you say, do I use <head> and <body> to contain the elements? I have, but I don’t know if it’s right.

I didn’t notice it when I posted, but vBulletin messes up the script:

    header('Location: [B][COLOR="Red"][ url ][/COLOR][/B]http://www.ijacobs.com/confirmation.html');[B][COLOR="red"][ /url ][/COLOR][/B]

See those pieces in red? Eliminate them.

Done it.
Now the form is loaded, but submit leads straight to a 404.
HOWEVER, whoopee, in my email is sitting the test message I sent.
You don’t know how grateful I am for all the time you’ve taken to get me up and working.
I’ll have to sort the 404 out for a ‘message sent’ etc. and get the css sorted.
Send me a message from the Contact page if you want to check.
Thanks again.

404 means it can’t find the page. Maybe its name isn’t confirmation.html? Or maybe you put it in a subfolder?

Guido,

Sorted the confirmation.html and received your message ’ Let\‘s see if this works ;-)’

I’ll tidy up the css after dinner.
Thanks so much for all your help. Hopefully I’ve learned a lot too.

My last message appears to have disappeared. I put it up before I ate and when I refreshed the page it disappeared.
Anyway, I’ve sorted out the confirmation.html and received your message: ’ Let\‘s see if this works ;-)’
Thanks for all your help, I’ve learned a lot too.
Should I put a doctype in the html on the php page? I presume I can make css stick.
Thanks again.

Whoops, there it is above. I didn’t think we had got to 2 pages of Q&A.
Good luck

Got the css tidied up and yes, a doctype helps, I worked out.

The message returns to blank if either the name or the message isn’t filled in, but it gets sent when an email address isn’t filled in.

Is there a way I can make them all required and also link some sort of message that all fields need to be filled, when they haven’t been?

Last question, I promise.