General Question

wenn's avatar

PHP help... contact form problem.

Asked by wenn (2673points) 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

phoenyx's avatar

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)

wenn's avatar

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.

jrpowell's avatar

I pretty much use a variation of this

markyy's avatar

@wenn You can’t stop the page from refreshing without ajax. If you want to refresh the page but want the page to automatically scroll down to the footer (without javascript) it is possible. Just add the div id to the action url of the form. Exactly like Fluther uses permalink: http://www.fluther.com/disc/56793/php-help-contact-form-problem/#quip814350 where #quip814350 is the id of my post.

jrpowell's avatar

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.

markyy's avatar

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.

LanceVance's avatar

There is one other option that I wouldn’t recommend.

frames

lefteh's avatar

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>”;
}
?>

Vincentt's avatar

@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?

lefteh's avatar

Nothing. Just another alternative.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther