Hi, just wondering how I can change the content of page using PHP_SELF. It would be good really for use on a contact form, to remove all of the fields, etc once the user has submitted the form and to display a DIV with the usual thanks and should be in touch within twenty-four hours.
Found site this examples what I’m trying to explain (all content is changed within the same page)! Click here to visit.
In the form processing script you could set a session variable after the email has been sent and then redirect back to the contact form page. When the contact form page loads, check for the existence and value of the above session variable and then use php to set the css to display the appropriate content div containing either the form or a thank you message.
Hi, thanks fr your reply. Ok, sounds an interesting way to do this…are there any other ways that this could be done without using a session? Just curious!
Hi, thanks for your message. I think I’d prefer to use sessions. So now, small question, I have an admin area and have started a session so how do I write to the existing session? I also want the user to be able to click back to the page and enter more details so I’m guessing I would need to destroy (somehow) that particular session variable?
I actually mislead you a bit because I didn’t realise you were submitting the form page to itself in which case you don’t need sessions at all. Sorry :headbang:
I would do something like this.
<?php
if(isset($_POST['submit'])) {
//do some processing here and then set the class values
//for the form and message containers
$formClass = 'hide';
$msgClass = 'show';
unset($_POST['submit']);
} else {
$formClass = 'show';
$msgClass = 'hide';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
.show {
display: block
}
.hide {
display: none
}
</style>
</head>
<body>
<form class="<?php echo $formClass; ?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<input type="text" name="txtEmail" />
<input type="submit" value="Submit" name="submit" />
</form>
<div class="<?php echo $msgClass; ?>">
Thank you for your email
</div>
</body>
</html>