I am just creating a simple contact form, but I notice that it seems to post to an invalid page. The url in the browser is correct but the title of the page is “Page not found”
on the top of the page
$emailed = false;
if (isset($_POST['submit'])) {
wp_mail('example@example.com', $_POST['subject'], $_POST['content']);
$emailed = true;
}
below … the HTML:
<form action="<?php the_permalink(); ?>" method="post" id="contactform">
<div class="formelem">
<label for="name">Name</label>
<input type="text" name="name" class="required" />
</div>
<div class="formelem">
<label for="email">Email</label>
<input type="text" name="email" class="required email" />
</div>
<div class="formelem">
<label for="subject">Subject</label>
<input type="text" name="subject" class="required" />
</div>
<div class="formelem">
<label for="content">Content</label>
<textarea name="content" cols="30" rows="10" class="required"></textarea>
</div>
<input type="submit" value="Submit Message" name="submit" value="submit" />
</form>
I could be wrong, but I vaguely remember that: name, email get hijacked by WordPress to do post comments, if you renamed the form elements to be contact-name and contact-email, do you get the same issue?
It is no only
name
oremail
problem, as Tom wrote. I had problem even with input field with name attribute same as one of my Custom Post Types. For example:And when having registered CPT “movie” somewhere else, your form submitting will end with 404 error.
Conclusion: Don’t use
name
,email
andany registered custom post type handle
as input name attribute value in your forms.Try to change
name="email"
to something likename="my_theme_email"
, do the same with all your field it sounds like some name are reserved with WordPress when sending form data. I got the the same problem and I fixed it like that.It works to me, just changed your
It will work. Thanks.
Also you can not use year as the name of the field.