Forum Moderators: coopster
I have a WordPress site I'm designing, and it's utilizing the jQuery Coda Slider on the home page. There are three panels in the slider, the last one contains a contact form.
Now, This is more of a PHP question than anything, but I *do* know that if I make the return URL "mysites.com/wordpress/#contact, then it *will* reload the page, and be focused on that third panel of the slider. In the end, this is what I'm looking for. My issue is I can't make it do it.
My contact form is a custom-written function in the WordPress theme files. it works terrifically - I have it running perfectly on a myriad of other sites. However, because the slider is incorporated in this one, I'm having a usability issue: if someone enters the *wrong* info in the form and submits, the idea is that the page reloads with error messages for the end user to correct. (This is typical behavior, and the function is fine - works as it should). The *issue* is, when the page reloads, the slider is on the 1st (default) panel. What I want is, if the form is submitted, I want it to either 1) reload the page, displaying panel 3 (the contact form) OR 2) redirect to another page on the site that will allow the transaction to complete.
Now, I know I *could* do a header (Location...), and option #2 would happen. Yay! Except this isn't your normal site - I *can't* do that here, because I'm using WordPress. I get a "headers already sent" message - which is to be expected, really. (But hey, I tried anyway.) I tried changing the path of what's to happen on submit to "include" the new file, but I get an error on that as well.
So after that novel, take a look at the code (I'm cleaning extraneous stuff out - no need for bloat):
function bb_contact() {
// form fields
$form = 'this is the form layout fields, etc';
// thank you message
$thanks = 'thank you message that's displayed on successful submission';
// start the script
foreach($_POST as $k => $v)...;(bunch o' checking stuff)
if ($action != "sendmail") { // when the form initially loads
$begin .= '<form method="post" action="' . $PHP_SELF . '" id="contactform">' . "\n";
echo $begin . $form;
}
if ($action == "sendmail") { // if "submit button is pressed, begin the checks
$begin .= '<form method="post" action="' . $PHP_SELF . '" id="contactform">' . "\n";
echo $begin;
if ($fromname == "" ¦¦ !ereg('[-\'a-zA-Z]', $fromname)) {
echo '<p>You didn\'t enter your name.</p>' . "\n";
$send == "no";
}
... more input checks here...
if ($send == "no") {
echo $form;
return;
}
...more checks here...
if ( ($fromname != $test_fromname) ¦¦ ($message != $test_message) ) {
echo 'error message for spam activity here' . "\n";
echo $form;
return;
} else { // if submitted and clears all checking
$subject = "Contact from website";
$message = nl2br("
From: $fromname ($fromemail)
$message
");
$message = stripSlashes($message);
$mailheader = "From: $fromname <$fromemail>\nContent-Type: text/html";
mail("My Name <my email address>", "$subject", "$message", "$mailheader");
}
{
echo $thanks;
return;
}
} // end "action = sendmail" section
} // end contact form
Okay, so the bolded stuff is where the issue lies (although I think *possibly* the form action could be it, too - but I'm not sure. i think it *is* right though - because the script is running form the WP functions.php file, so to keep running, it does have to call back on itself.) As it stands up there, it all works great - except it doesn't load on the correct panel when the form is submitted.
I've tried redoing it like so:
if ($send == "no") {
include(TEMPLATEPATH . '/contact/contact-form.php');
return;
} and this has the same effect - it pulls in the file, but the page doesn't load to the 3rd panel.
I've also tried:
if ($send == "no") {
header("Location:" . get_bloginfo('home') . "/#contact");
return;
} and I get a "headers already sent" error.
I've also tried using "exit" in place of "return" but when I do that the script never completes and my browser crashes.
So now that I've set you up - do you think you can help me figure out how to finish this? I'd be perfectly happy having the submission redirect to another page - but as mentioned it doesn't work. I'd love any hints on how to pull this off.
Thanks for any help you can give! :)