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.
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: https://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) && $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 »</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)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Passing PHP variable cuases Error 404’ is closed to new replies.