Hey all,
I'm having a problem with my WordPress contact form. It is a script I edited from a tutorial I found, and it should be working right. I have a jQuery script that is supposed to help validate it and process it without page refresh.
The problem is that for some reason, neither the PHP script nor the jQuery script can seem to find my contact page when the form is submitted. The jQuery script, for example, works perfectly fine up until the ajax call, but once it sends the request Firebug says it hits the 404 page. I disabled JavaScript in my browser to see if it was the jQuery causing a problem, but the PHP script does the same thing. This doesn't make sense, because they're both on the contact page. When I click "submit", the script sends me to my 404 page. The form is at www.mydomain.com/contact, and the form action is also www.mydomain.com/contact. So why would I get the 404 page when it submits?
I've used an almost identical script on another WordPress site I made for a client, and it works perfectly. I am hosted by Dreamhost, if that makes a difference.
Here is the contact page script:

contact.php

<?php
/*
Template Name: contact
 */

//If the form is submitted
if(isset($_POST['submit'])) {

	$error = array();
	// Check to make sure that the name field is not empty
	if(trim($_POST['name']) === '') {
		$nameError = true;
		$hasError = true;
	} else {
		$name = trim($_POST['name']);
	}
	
	// Check to make sure sure that a valid email address is submitted
	if(trim($_POST['email']) === '')  {
		$emailError = true;
		$hasError = true;
	} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
		$emailError = true;
		$hasError = true;
	} else {
		$email = trim($_POST['email']);
	}
	
	// Check to make sure that the subject field is not empty
	if(trim($_POST['subject']) === '') {
		$subjectError = true;
		$hasError = true;
	} else {
		$subject = trim($_POST['subject']);
	}
		
	// Check to make sure comments were entered	
	if(trim($_POST['message']) === '') {
		$messageError = true;
		$hasError = true;
	} else {
		if(function_exists('stripslashes')) {
			$message = stripslashes(trim($_POST['message']));
		} else {
			$message = trim($_POST['message']);
		}
	}
		
	//If there is no error, send the email
	if(!isset($hasError)) {

		$emailTo = 'myemail@mydomain.com';
		$subject = $subject;
		$body = "Name: $name \n\nEmail: $email \n\nMessage: $message";
		$headers = 'From: mydomain.com <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
		
		mail($emailTo, $subject, $body, $headers);

		$emailSent = true;
	}
} ?>

<?php get_header(); ?>
   <div id="main">
      <div id="contact-left">
         <div id="contact-container">
	<?php if (have_posts()) : ?>
	
	<?php while (have_posts()) : the_post(); ?>
		<h1>Contact Me</h1>
				
		<?php the_content(); ?>
					
		<form id="contactme" action="<?php the_permalink(); ?>" method="post">
		   <fieldset>
		      <label for="name" class="error"<?php if($nameError) echo ' style="display: block;"'?>>Please provide a name</label>
		      <input type="text" name="name" id="name" size="40" maxlength="50" value="name" onfocus="if(this.value=='name') this.value='';" onblur="if(this.value=='') this.value='name';" />
					
		      <label for="email" class="error"<?php if($emailError) echo ' style="display: block;"'?>>Please provide a valid e-mail address</label>
		      <input type="text" name="email" id="email" size="40" maxlength="50" value="email" onfocus="if(this.value=='email') this.value='';" onblur="if(this.value=='') this.value='email';" />
					
		      <label for="subject" class="error"<?php if($subjectError) echo ' style="display: block;"'?>>Please provide a subject</label>
		      <input type="text" name="subject" id="subject" size="40" maxlength="150" value="subject" onfocus="if(this.value=='subject') this.value='';" onblur="if(this.value=='') this.value='subject';" />
					
		      <label for="message" class="error"<?php if($messageError) echo ' style="display: block;"'?>>Please provide a message</label>
		      <textarea name="message" id="message" rows="8" cols="43" onfocus="if(this.value=='message') this.value='';" onblur="if(this.value=='') this.value='message';" >message</textarea>
					
		      <input type="submit" id="submit" value="submit" />
		   </fieldset>
		</form>
	<?php endwhile; endif; } ?>
	</div>
      </div> <!-- /contact-left -->
      <?php get_sidebar(); ?>		

</div> <!-- /main -->
<div class="clear"></div>

<?php get_footer(); }?>

Thanks!

Rename your file to index.php

I can't, I already have an index.php page and it does something else.

...

Your requesting the file at http://yourdomain.com/contact

Try navigating to it with http://yourdomain.com/contact.php?

When your going to http://youdomain.com/contact your telling the browser to navigate to a directory not a file.

I'm not sure if im teaching you to suck eggs at the moement....

The other,

What function is the form pointing at? "the_permalink();"


I can't see an include or that function within this file. Change this to contact.php

Ah, wordpress uses mod_rewrite to rewrite page URLs. So /contact should be fine based on the permalink structure I have set up. the_permalink() is a wordpress function that returns the URI for the current post or page. In the case of this page it returns www.mydomain.com/contact.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.