/    Sign up×
Community /Pin to ProfileBookmark

After submitting form, give thank you and remove form

I have a form that does not use a redirect after the user has submitted it. Rather, I would like the thank you message to appear (which I have done) but I would also like the form fields to disappear, so that the user cannot resubmit the form.

Or, is there a method of not allowing the user to resubmit the form, should I be using a redirect after submit?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachOct 23.2007 — you could do somethign similar to this
[code=php]
<html>
<body>

<?php
if (isset($_POST['send'])) {

// do some php here

echo ' Thank you for contacting us';

}
else {

?>

// contact form here

<?php

}
?>

</body>
</html>

[/code]
Copy linkTweet thisAlerts:
@nnhubbardauthorOct 23.2007 — I guess I am having a hard time understanding how that would work with the code I have already written. Here it is, could someone help me with how to implement this?

[code=php]<?php include 'inc/global.php'; ?>
<?
putenv("TZ=America/Los_Angeles");
?>
<? require ($_SERVER['DOCUMENT_ROOT'] . "/inc/db_connect.php");
$connection = @mysql_connect ($db_host, $db_user, $db_password) or die ("Error connecting");
mysql_select_db ($db_name, $connection);
?>
</head>
<body>
<div id="container">
<?php include 'inc/header.php'; ?>
<br clear="all" />
<div id="main_body">
<div id="content">
<div id="pageTitle">price quote</div>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis vitae
nunc. Sed lacus dui, facilisis id, iaculis non, ultrices at, enim. Donec
luctus pharetra est. Maecenas vehicula, mi eget gravida posuere, nulla
dolor convallis orci, ut lobortis ligula mi eget metus. Nulla consequat
arcu ornare dolor. Quisque enim enim, elementum a, accumsan sed, fermentum
quis, odio. In sed nisi ac nunc tincidunt tincidunt. Pellentesque vehicula.
Phasellus nulla. Vivamus faucibus pulvinar libero. Cras tempus, elit
ac dictum iaculis, nulla neque condimentum lorem, in dignissim turpis
felis lobortis turpis. Mauris orci orci, convallis ut, ultrices in, cursus
a, diam. Cras magna magna, consequat at, mollis et, laoreet nec, arcu.
Pellentesque ac ipsum eu pede sollicitudin placerat.</p>
<?php
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.
if ($_POST['name_first']=='')
$arrErrors['name_first'] = 'Please provide your First Name.';
if ($_POST['name_last']=='')
$arrErrors['name_last'] = 'Please provide your Last Name.';
if ($_POST['email']=='')
$arrErrors['email'] = 'A valid email address is required.';
if ($_POST['quote']=='')
$arrErrors['quote'] = 'Please enter an estimated budget for this project.';
if ($_POST['phone']=='')
$arrErrors['phone'] = 'Please provide your phone number.';
if (count($arrErrors) == 0) {
// Contact subject
$first_name = $_POST["name_first"];
$last_name = $_POST["name_last"];
$email = $_POST["email"];
$comment = $_POST["comments"];
$quote = $_POST["quote"];
$date = date ( 'm/d/Y g:ia' );

$query = "INSERT INTO user_info (name_first, name_last, email, quote, comments, submit_date) VALUES ('$first_name', '$last_name', '$email', '$quote', '$comments', '$date')";
mysql_query($query, $connection) or die (mysql_error());


$subject = "Zed Said Contact Form - Quote";
$mydate = date ( 'l, F d Y g:i A' );

// Details
$message = 'You have received a quote from '.$first_name.' '.$last_name.', be sure to login to receive this quote';

// Mail of sender
$mail_from = "$email";
// From
$header = "from: $name <$email>";

// Enter your email address
$to = '[email protected]';

$send_contact = mail($to,$subject,$message,$header);

// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "<div id="thanks">We've recived your information, thank you!</div>";
}
else {
echo "ERROR";
}
// Insert form processing above
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div>';
}
}
?>
<?php echo $strError; ?>
<form id="quote" method="post" action="<?php echo $PHP_SELF; ?>">
<p>
<label for="name_first">First Name</label>
<input name="name_first" type="text" id="name_first" value="<?php echo $_POST['name_first'] ?>">
<?php if (!empty($arrErrors['name_first'])) echo ' '.$arrErrors['name_first'].''; ?>
</p>
<p>
<label for="name_last">Last Name</label>
<input name="name_last" type="text" id="name_last" value="<?php echo $_POST['name_last'] ?>">
<?php if (!empty($arrErrors['name_last'])) echo ' '.$arrErrors['name_last'].''; ?>
</p>
<p>
<label for="email">Email</label>
<input name="email" type="text" id="email" value="<?php echo $_POST['email'] ?>">
<?php if (!empty($arrErrors['email'])) echo ' '.$arrErrors['email'].''; ?>
</p>
<p>
<label for="quote">Budget</label>
<input name="quote" type="text" id="quote" value="<?php echo $_POST['quote'] ?>">
<?php if (!empty($arrErrors['quote'])) echo ' '.$arrErrors['quote'].''; ?>
</p>
<p>
<label for="phone">Phone</label>
<input name="phone" type="text" id="phone" value="<?php echo $_POST['phone'] ?>">
<?php if (!empty($arrErrors['phone'])) echo ' '.$arrErrors['phone'].''; ?>
</p>
<p>
<input id="submit" type="submit" name="Submit" value="Submit">
</p>
</form>
</div>
</div>
<?php include 'inc/footer.php'; ?>
</div>[/code]
Copy linkTweet thisAlerts:
@nnhubbardauthorOct 24.2007 — I keep trying to add the suggested code to my page, and I understand how it will work, but all I get are errors.

Anyone willing to help?
×

Success!

Help @nnhubbard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...