Title: Passing PHP variable cuases Error 404
Last modified: August 19, 2016

---

# Passing PHP variable cuases Error 404

 *  Resolved [guitarcrazy087](https://wordpress.org/support/users/guitarcrazy087/)
 * (@guitarcrazy087)
 * [17 years ago](https://wordpress.org/support/topic/passing-php-variable-cuases-error-404/)
 * Okay, so here’s the deal. I’m making myself a contact page via making a plugin.
   View it [here](http://joehenry.name/contact).
 * The plugin works fine at first. When you view the page it displays the contact
   form perfectly. The problem is, after you submit the form, I get a 404 Not Found
   error. This doesn’t happen if none of the fields in the form are filled out though.
 * The thing is, whether any fields of the form are filled out or not, the form 
   still passes a PHP variable on submission telling my script to validate the form.
   So the weird thing is that I don’t get the 404 Error when I pass the one variable,
   but only when one of the field are filled out.
 * Any help is really appreciated. Here’s my code:
 *     ```
       <?php
       /*
       Plugin Name: Every Body Else Contact Form
       Description: A sweet contact form that fits perfectly with the Every Body Else theme.
       Version: 1.0
       Author: Joe Henry
       Author URI: http://joehenry.frihost.net
       */
   
       function send_email() {
   
       }
   
       function insert_contact($content) {
       	if (true == strstr($content, '<!-- Contact Form -->')) {
       		$form = '
   
       <!-- Contact Form -->
   
       <script type="text/javascript" src="contact.js"></script>
   
       <form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
   
       ';
       		$sendmail = $_POST['sendmail'];
       		if (isset($sendmail) &amp;&amp; $sendmail == 'yes') {
       			$name = $_POST['name'];
       			$email = $_POST['email'];
       			$subject = $_POST['subject'];
       			$url = $_POST['url'];
       			$comments = $_post['comments'];
       			$valid = 'yes';
   
       			$name = trim($name);
       			$nl = strlen($name);
       			if ($nl < 2) {
       				$valid = "no";
       				$ne = "	<li>The name you entered is too short...</li>";
       			}
       			else if ($nl > 20) {
       				$valid = "no";
       				$ne = "	<li>The name you entered is too long...</li>";
       			}
   
       			$email = trim($email);
       			$dot = strrpos($email, ".");
       			$at  = strrpos($email, "@");
       			$emlength = strlen($email);
       			$domainlength = $emlength - 1 - $at;
       			if ($at == FALSE || $dot == FALSE || $at == 0 || $dot < $at || $dot == ++$at || $at > 63 || $dot + 1 == $emlength || $domainlength > 255) {
       				$valid = "no";
       				$eme = "	<li>The email address you entered is not valid...</li>";
       			}
   
       			$content = trim($content);
       			$contentlength = strlen($content);
       			if ($contentlength < 4) {
       				$valid = 'no';
       			}
   
       		}
       		if ($valid == 'no') {
       			$form .= '<div class="oops">
       Ooooooooooops. You did not fill the form out correctly =/
       	<ul>
       ' . $ne . '
       ' . $eme . '
       	<ul>
       </div>
   
       ';
       		}
       		if ($valid == 'yes') {
       			$form .= 'Email sent';
       		}
       		if (!is_user_logged_in()) {
       			$form .= '
       <p><input type="text" name="name" /> <small><b>Name</b> (required)</small></p>
       <p><input type="text" name="email" /> <small><b>Email address</b> (required)</small></p>
       <p><input type="text" name="subject" /> <small><b>Subject</b></small></p>
       <p><input type="text" name="url" /> <small><b>URL</b></small></p>
   
       ';
       		}
       		else {
       			global $current_user;
           		get_currentuserinfo();
           		$name = $current_user->display_name;
           		$form .= '<p><small>Logged in as <a href="' . get_option('siteurl') . '/wp-admin/profile.php">' . $name . '</a>. <a href="' . wp_logout_url(get_permalink()) . '" title="Log out of this account">Log out &raquo;</a></small></p>';
       		}
       		$form .= '<small><b>Your comments</b> (required):</small><br /><textarea name="comments"></textarea><br /><br />';
       		$form .= '<input type="hidden" name="sendmail" value="yes" />';
       		$form .= '<input type="submit" value="Fire!" />';
       		$form .= '</form>';
       		$content = str_replace('<!-- Contact Form -->', $form, $content);
       	}
       	return $content;
       }
   
       add_filter('the_content', 'insert_contact');
   
       ?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [guitarcrazy087](https://wordpress.org/support/users/guitarcrazy087/)
 * (@guitarcrazy087)
 * [17 years ago](https://wordpress.org/support/topic/passing-php-variable-cuases-error-404/#post-1076387)
 * Just in case this might help, I just discovered that I only get the error when
   the name is filled out and the other manditory fields aren’t. If you try just
   filling out the email field it returns with the correct error message.
 * Thanks to anybody who can help!
 * Joe
 *  Thread Starter [guitarcrazy087](https://wordpress.org/support/users/guitarcrazy087/)
 * (@guitarcrazy087)
 * [17 years ago](https://wordpress.org/support/topic/passing-php-variable-cuases-error-404/#post-1076389)
 * Okay, nevermind, I figured it out.
 * It turns out that somehow my line:
 * $name = $_POST[‘name’];
 * Was conflicting with some other line. Probably my input named ‘name’ was conflicting
   with my posts array name or something. I fixed it by changing the input name 
   from ‘name’ to ‘qname’.
 * Thanks anyway.
 * Joe

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Passing PHP variable cuases Error 404’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 2 replies
 * 1 participant
 * Last reply from: [guitarcrazy087](https://wordpress.org/support/users/guitarcrazy087/)
 * Last activity: [17 years ago](https://wordpress.org/support/topic/passing-php-variable-cuases-error-404/#post-1076389)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
