Contact-form Gone Awry Because of Poor HTML Attribute Naming

Few days ago, I was building a simple contact form WordPress plugin for a project I was working.
I added shortcode support to the plugin so the contact form can be included in posts and pages.

The contact form consist of the following form fields – name, email, phone number, mail subject and message with respective name attributes as follows: name, email, phonenumber, subject, message.



echo '

<form action="' . $_SERVER['REQUEST_URI'] . '" method="post"><label for="name">Name <strong>*</strong></label>
<input name="sender_name" type="text" />
<div><label for="email">Email <strong>*</strong></label>
<input name="sender_email" type="text" /></div>
<div><label for="phonenumber">Phone Number <strong>*</strong></label>
<input name="sender_phonenumber" type="text" /></div>
<div><label for="subject">Subject <strong>*</strong></label>
<input name="email_subject" type="text" /></div>
<div><label for="message">Message <strong>*</strong></label>
<textarea name="email_message">
<div><input name="send_message" type="submit" value="Send" /></div>
</form>';

On including the contact form in a WordPress post using shortcode, when the form get submitted, instead of sending the form data via POST method to the current page (detectable by $_SERVER[‘REQUEST_URI’] super-global) for processing, the form does get submitted to the current page but the content of the current page mysteriously becomes a list of recently published articles (similar to WordPress index/front-page) with the URL of the page unchanged.

HTML form gone awry in WordPress

 

After hours of trying to figure out the cause of the problem, something said to me, try changing the name attributes of the input and textarea element to a less-general name which I did by prefixing the attribute with “cft_
As soon as made the change, voila! the contact-form worked.

I still can’t figure out why the form didn’t work. If you know the likely cause of the problem, let me know in the comment.

Update

Thanks to Bert Visser in HTML5 G+ Community, i got t know there are Reserved Terms which should be avoided when passing the term through the $_GET or $_POST array as doing so can cause WordPress to respond with a 404 error without any other hint or explanation.

From observation, the name term is a reserved term hence the weird error.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address