CSS
-Tricks
treehouse :
what would you like to learn today?
Web Design
Web Development
iOS Development
Show search box
Search
Search in:
All
Articles
Forums
Snippets
Videos
✕
Home
Forums
Snippets
Gallery
Videos
Almanac
Demos
Lodge
Navigation 'n' Search
Forums
Illustration by Nick Sirotich
Forums
»
PHP Problems
one page both display / handle form wordpress
toddvalentine
Permalink to comment
#
April 2009
I have written a php contact form that both displays and handles the form on my contact page in wordpress.
The contact page file is named contactPage.php and has a url of url/index.php/contact/
My problem is that every time I test the form, it directs me to my 404 page.
I have my set my form to both action="contactPage.php" and action="url/index.php/contact/"
but they both direct me to the 404 page
Has anyone had any success in having a script both display and handle a form in wordpress?
Thanks for the time. Code is below:
<?php
/*
Template Name: contactPage
*/
?>
<?php get_header(); ?>
<?
if (isset($_POST['submitted'])) {
function spam_scrubber($value) {
$bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:');
foreach ($bad as $v) {
if (stripos($value, $v) !== false) return '';
} // End foreach
$value = str_replace(array( "\r", "\n", "%0a", "%0d"), '', $value);
return trim($value);
} //End spam-scrubber
$scrubbed = array_map('spam_scrubber', $_POST);
if (!empty($scrubbed['name']) && !empty($scrubbed['email']) && !empty($scrubbed['message']) ) {
$body = "Name: {$scrubbed['name']}
\n\nMessage: {$scrubbed['message']}";
$body = wordwrap($body, 70);
mail(
'vtypemedia@gmail.com
', 'Contact Form Submission', $body, "From: {$scrubbed['email']}");
echo '<p>Thanks!</p>';
$_POST = array();
} else {
echo'<p>Please fill out the form completely</p>';
}
}
?>
<div id="mainCol">
<div id="mainColInside">
<div id="contact-area">
<h3>Contact Eric</h3>
<form method="post" action="/index.php/contact/">
<label for="Name">Name:</label>
<input type="text" name="name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
</div>
<div style="clear: both;"></div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>
ikthius
Permalink to comment
#
April 2009
so you have a contact directory in your index.php file???
that will be you problem, you can put files into directories, not the other way round.
you may have it like this:
root folder
|
-------- index.php
|
Contact folder
|
------------ contact.php
so your calling of the script should be:
http://www.yoursite.com/
contact/
contact.php
denotes directory
denotes file
also if the file is called contactform.php then you need to call this exact file, not a general contact.
analogy: phone pepsi and ask to speak to john !!!
Add a Comment
The contact page file is named contactPage.php and has a url of url/index.php/contact/
My problem is that every time I test the form, it directs me to my 404 page.
I have my set my form to both action="contactPage.php" and action="url/index.php/contact/"
but they both direct me to the 404 page
Has anyone had any success in having a script both display and handle a form in wordpress?
Thanks for the time. Code is below:
<?php
/*
Template Name: contactPage
*/
?>
<?php get_header(); ?>
<?
if (isset($_POST['submitted'])) {
function spam_scrubber($value) {
$bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:');
foreach ($bad as $v) {
if (stripos($value, $v) !== false) return '';
} // End foreach
$value = str_replace(array( "\r", "\n", "%0a", "%0d"), '', $value);
return trim($value);
} //End spam-scrubber
$scrubbed = array_map('spam_scrubber', $_POST);
if (!empty($scrubbed['name']) && !empty($scrubbed['email']) && !empty($scrubbed['message']) ) {
$body = "Name: {$scrubbed['name']}
\n\nMessage: {$scrubbed['message']}";
$body = wordwrap($body, 70);
mail('vtypemedia@gmail.com', 'Contact Form Submission', $body, "From: {$scrubbed['email']}");
echo '<p>Thanks!</p>';
$_POST = array();
} else {
echo'<p>Please fill out the form completely</p>';
}
}
?>
<div id="mainCol">
<div id="mainColInside">
<div id="contact-area">
<h3>Contact Eric</h3>
<form method="post" action="/index.php/contact/">
<label for="Name">Name:</label>
<input type="text" name="name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
</div>
<div style="clear: both;"></div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>
that will be you problem, you can put files into directories, not the other way round.
you may have it like this:
so your calling of the script should be: http://www.yoursite.com/contact/contact.php
denotes directory
denotes file
also if the file is called contactform.php then you need to call this exact file, not a general contact.
analogy: phone pepsi and ask to speak to john !!!