PHP help... contact form problem.
Asked by
wenn (
2673)
September 28th, 2009
Ive got a simple contact form with email validation, and when you fill it out and submit it refreshes the page. I DO NOT WANT THAT.
My form is in the footer, this is very annoying since it jumps up to the top and you never see the conformation message.
I’m no PHP whiz, so forgive me if its a dumb simple thing, but its annoying the hell out of me!
Observing members:
0
Composing members:
0
10 Answers
You should probably do an ajax form submit and replace the form with the confirmation message. I’ve got to get to bed, but I’ll find a tutorial for you in the morning if someone else hasn’t already.
(basically, opposite of this: http://24ways.org/2005/edit-in-place-with-ajax)
i have googled, havent been able to find an answer that works. and i really dont feel like doing AJAX.
I am just wondering if theres a snippet of code evading me that will cancel the refresh.
I pretty much use a variation of this
Not really. You will need to use javascript/ajax if you don’t want the page to refresh.
You could drop a http://www.whatever.com/#link into the page to make it jump to the bottom after the page refreshes if you are completely against ajax.
Oh, and for the record. Php is a serverside language. That means your browser sends a request for a page to the server, the server finds the page, handles the code, translate it to html, and return that html to your browser. Your browser can display html, but not php (which is good, because we don’t want other people to see our php code anyway). So without a page refresh (or ajax request) there is no communication between the server that handles your php and the browser that displays the html.
There is one other option that I wouldn’t recommend.
frames
You could have it refresh but then use javascript to send the page to the bottom.
This is untested, so I can’t vouch for it, but it’s the best I could come up with:
function scrollToBottom () {
var cafh=document.body.clientHeight;
var dafh = document.body.scrollHeight;
if (cafh > dafh) {
var agogo = dafh – cafh;
window.scrollTo(0, agogo);
}
}
then pull something like…
<?php
if (isset($_POST[‘submit’])) {
echo ”<script type=\“text/javascript\”>scrollToBottom()</script>”;
}
?>
@LanceVance Ugh, frames in itself are terrible, but for this use it would be even nastier xD
@lefteh What’s wrong with using normal HTML anchors like @markyy and @johnpowell mentioned?
Nothing. Just another alternative.
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.