Contact us form
-
Hi All,
I have created one single page and placed it into the theme directory within the theme itself. named: contactus.php
Within this page if i have paste
<?php /* Template Name: Contact us */ ?>Within the admin panel i have created one PAGE with this template name tagged. So i am able to paste all the code into the contactus.php and wordpress reads the code of contactus.php
THE CODE:
<?php /* Template Name: Contact us */ ?> <?php get_header();?> <?php $raisedip = $_SERVER['REMOTE_ADDR']; $lasturl = $_SERVER['HTTP_REFERER']; $FormError = false; $FormMessages = array(); if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['sendit'] == 'yeah')) { if (empty($_POST['name']) || ($_POST['name'] == '')) { $FormMessages[] = '<div class="error">I can\'t send this without a name</div>'; $FormError = true; } if (empty($_POST['email']) || ($_POST['email'] == '')) { $FormMessages[] ='<div class="error">I can\'t send this without a valid email</div>'; $FormError = true; } if ($FormError == false) { $FormMessages[] = '<div class="thanks">Your message has been send succesfully</div>'; $receiver = '//'; $subject = "Someone has tried to contact us in regards to ". $_POST['subject']; $message = "Name: ". $_POST['name'] ."\nE-mail contact: ". $_POST['email'] ."\nCountry: ". $_POST['country'] . "\nSubject: ". $_POST['subject'] ."\nMessage: ". $_POST['message'] ."\r\n"; $headers = 'From: no-reply <//>' . "\r\n\\"; wp_mail($receiver, $subject, $message, $headers); } } ?> <?php if (!empty($FormMessages)){ foreach ($FormMessages as $errors) { echo $errors.'<br />'; } } ?> <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <table id="contactformtable"> <legend style="float:right; padding-right:30px;"><h3> Contact us </h3></legend> <tr> <td>Your name</td> <td><input type="text" name="name" maxlength="40"></td> </tr> <tr> <td>Your E-mail address</td> <td><input type="text" name="email" maxlength="40"> </tr> <tr> <td>Country</td> <td><select name="country"> <option value="nl">Nederland</option> <option value="be" selected>Belgie</option> </td> </tr> <tr> <td>Subject</td> <td><select name="subject"> <option value="drivers">Drivers</option> <option value="cfg">CFG makers</option> <option value="website" selected>Website</option> </td> </tr> <tr> <td>Message</td> <td><TEXTAREA name="message" cols="20" rows="20"></TEXTAREA> </td> </tr> <input type="hidden" name="sendit" value="yeah"> <input type="hidden" name="ip" value="<?php echo $raisedip; ?>"> <input type="hidden" name="referer" value="<?php echo $lasturl; ?>"> <tr> <td><input type="submit" name="submit" value="Send"></td> <td><input type="reset" name="clear" value="Clear fields"></td> </tr> </table> </form> <?php get_footer(); ?>Now when i dont fill in the name and email field, it returns the 2 errors as stated within the if statements.
When i fill in one of the fields it shows the 404 page and the same when i fill in all the field and hit the submit button. Again the 404 page will be shown.I know this code is not yet finished in regards to the errors but i should say it should work for this far.
Can someone tell me whats wrong ? Why i get the 404 errors when i hit the submit button ?
Cheers
The topic ‘Contact us form’ is closed to new replies.