Working on a WordPress integration of this Blogfest HTML template i found that an working php / html contact form lead to a 404 error page in a WordPress page. What can be wrong with this form once is working just fine on a php / html template, but integrated in a custom WordPress page template is failing?
In this article you’ll find a small and useful WordPress tip what can save your working hours finding a possible bug. Take for example the following form code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | <form method="post" action="<?php the_permalink(); ?>" id="form"> <div class="form_row"> <div class="form_item"> <label for="author">Name *</label> <input type="text" name="author" id="author" class="required" value="" size="22" /> </div> <div class="form_item"> <label for="email">E-mail *</label> <input type="text" name="email" id="email" class="required email" value="" size="22" /> </div> <div class="form_item"> <label for="url">Website</label> <input type="text" name="url" id="url" value="" size="22" tabindex="3" /> </div> </div> <div class="form_row"> <div class="form_item_comment"> <label for="comment">Message *</label> <textarea name="message" id="comment" class="required" cols="58" rows="10"></textarea> </div> </div > <div class="form_row"> <div class="submit_comment"> <input name="submit" type="submit" class="button" id="submitButton" value="Send Message"/> </div> </div> </form> |
The WordPress Tip
Please notice the highlighted line nr 9. Everything look just fine, rite? In a HTML template, yes, but when you are integrating a form in a WordPress page template keep in mind that the name attribute should be different then “name” or “author”. Once i changed the name attribute to “username” (example) the form was working again and no more 404 error.