...

View Full Version : hide html form on submission



Jordan656
03-30-2009, 12:12 AM
hi

i have a standard html form i am using to receive information from customers. I know there are various ways of stopping a form being sent twice, but my site is all about user-friendliness so i want to go the extra mile.

Is there any way a form can be hidden once successfully submitted, and replaced with a new, previously unseen div. I was playing around with a javascript that toggles divs but can't get it to 'stick' (ie if a user leaves the page then comes back the new div is still present, not the form).

If anyone out there can help then

a) theyre a pure genius
b) ill be very grateful

thanks

timgolding
03-30-2009, 12:49 AM
What processes the form?
Have you got php installed on your server if so you could have something like this



if(isset($_POST))
{
echo "new div";

}
else
{
echo "Form";

}

Jordan656
03-30-2009, 01:02 AM
that looks good, but im not good with php and dont really know where i would place that.

the page is .php (due to my love of includes)

this is the code for the form

<form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="../formscripts/namecheck.php">
<input name="name" type="text" size="50" />
<input name="proposedname" type="text" size="50" />
<input name="email" type="text" size="50" />
</form>


this is the code for the processing

<?php header("Refresh: 0;url=http://www "); ?>
<?php
mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email")
?>

<?php
mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email")
?>

<?php
mail("$email", "Your choice of name", "

Hi $name,

Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours.

We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

Name: $name
Proposed name: $proposedname
Email address: $email

Many thanks


","From: from addy")
?>

bold are things i chopped out of the code to post it up here - CF caches well and i dont want my customers coming across these posts!

If theres any way to get that all on one page, with the replacement divs even better!

Thanks

timgolding
03-30-2009, 01:37 AM
I'm abit confused about this line



<?php header("Refresh: 0;url=http://example.com"); ?>

Ive seen header("Location: "); but not refresh ill test that in a minute.
But i think you should try


<?php
if(isset($_POST))
{
echo'
<form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
<input name="name" type="text" size="50" />
<input name="proposedname" type="text" size="50" />
<input name="email" type="text" size="50" />
</form>';
}
else
{
header("Refresh: 0;url=http://www ");
mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");

mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");
mail("$email", "Your choice of name", "

Hi $name,

Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours.

We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

Name: $name
Proposed name: $proposedname
Email address: $email

Many thanks


","From: from addy");


}
?>


Give it a try any problems then its maybe to do with that line or whatever the JS function formCheck(this); does

timgolding
03-30-2009, 01:46 AM
Ok i tesed the refresh command and it just seems to redirect to a different page does it redirect back to itself maybe? In which case it would need tobe what ever the url of that page is. Not sure if this should be done after the mail functions are called though. I mean does the email get sent. Maybe it should be



<?php
if(isset($_POST))
{
echo'
<form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
<input name="name" type="text" size="50" />
<input name="proposedname" type="text" size="50" />
<input name="email" type="text" size="50" />
</form>';
}
else
{

mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");

mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");
mail("$email", "Your choice of name", "

Hi $name,

Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours.

We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

Name: $name
Proposed name: $proposedname
Email address: $email

Many thanks


","From: from addy");
header("Refresh: 0;");

}
?>

Not sure about that give it a try.

timgolding
03-30-2009, 01:51 AM
Yeah the second example would work i just tested it :)

timgolding
03-30-2009, 01:56 AM
Actually you need to completely remove that header function



<?php
if(isset($_POST))
{
echo'
<form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
<input name="name" type="text" size="50" />
<input name="proposedname" type="text" size="50" />
<input name="email" type="text" size="50" />
</form>';
}
else
{

mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");

mail("address", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");
mail("$email", "Your choice of name", "

Hi $name,

Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours.

We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

Name: $name
Proposed name: $proposedname
Email address: $email

Many thanks


","From: from addy");


echo "Place you new div here";

}
?>



and replace your output for the new div where i have shown.

Jordan656
03-30-2009, 07:51 PM
ive placed this code on my page. when the form submits the page flashes (i assume its refreshing) but no emails are sent, and no alternative div appears.

Any suggestions?

timgolding
03-30-2009, 11:47 PM
Sorry I've been a little busy today with work and things. I've looked at my code and am a little ashamed of what i posted but i got it working now.
Basically i forgot copy the post data to the variables and I got the isset condition the wrong way around it should have been (!isset($_POST)). Sorry i was in a rush to get to bed last night and did'nt really check through what i did. But i have completed the code and uploaded it to my server and it is sending the emails. It wasn't before because it was never getting to that bit of code.

Heres the code


<?php
if(!isset($_POST["submit"]))
{
echo'
<form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
<label>Name: </label>
<input name="name" type="text" size="50" /><br />
<label>Proposed Name: </label>
<input name="proposedname" type="text" size="50" /><br />
<label>Email: </label>
<input name="email" type="text" size="50" /><br />
<input type="submit" value="submit" name="submit" />
</form>';
}
else
{
$email=$_POST['email'];
$proposedname=$_POST['proposedname'];
$name=$_POST['name'];
mail("tim@example.com", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");

mail("timmy@example.com", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");
mail("timothy@example.com", "Your choice of name", "

Hi $name,

Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours.

We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

Name: $name
Proposed name: $proposedname
Email address: $email

Many thanks


","From: mail@cybadev.co.uk");


echo "Place you new div here";

}
?>


This 100% works i have tested it see for yourself http://cybadev.co.uk/email.php. If you have any problems let me know. But provided you javascript validation works there shouldn't be a problem

timgolding
04-01-2009, 01:42 AM
I should of really pointed out that this script isn't at all secure. Although you have some javascript validation in place that won't stop a hacker sending post data by other means. You really need to implement some sever side validation. You should maybe implement some PEAR (http://pear.php.net/) validation on the names and email otherwise a hacker might use your script to send hundreds of unsolicited emails. You especially need to validate that the email is a single email and that the string doesn't contain more than one valid email. It gets a bit risky when you are using the optional additional header in the mail function.

Heres the validation script to download

http://pear.php.net/package/Validate/download

Download it, untar it. Find the file Validate.php in the package and put it in your website folder. then include it in your PHP script with


require_once('Validate.php');


You may want to add some extra characters to the punctuation regex.
Anyway once it's included in your script. You can use it like so



<?php
require_once('Validate.php');

//email validation
$email="tim@example.com";

if(Validate::email($email, true)) //use true to use dns lookup
echo "Valid email";
else
echo "Invalid email";

// String validation.
//This assumes you want to allow whitespaces, punctuation, Alpha and numeric if you want too remove any of these just drop them out
$name="Tim Golding";
$min_length = 1;
$max_length = 50;
define('PUNCTUATION', '\.,;\:&"\'\?\!\(\)');
define('EXTRAS', "'" . "-"); //extra punctuation for names
if(Validate::string($name, array("format" => VALIDATE_EALPHA . VALIDATE_NUM . VALIDATE_SPACE . PUNCTUATION . EXTRAS ,"min_length" => $min_length ,"max_length" => $max_length)))
echo "Valid name";
else
echo "Invalid name";

?>


Thats some simple examples. So how to add this to your code... Like so


<?php
if(!isset($_POST["submit"]))
{
echo'
<form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
<label>Name: </label>
<input name="name" type="text" size="50" /><br />
<label>Proposed Name: </label>
<input name="proposedname" type="text" size="50" /><br />
<label>Email: </label>
<input name="email" type="text" size="50" /><br />
<input type="submit" value="submit" name="submit" />
</form>';
}
else
{
// Simple validation to check they are all set
if(!isset($_POST['email'], $_POST['proposedname'], $_POST['name']))
die ('You must enter an email, proposed name and a name');

require_once('Validate.php'); // You must put Validate.php in the same folder as this script for this to work
//setting post data
$email=$_POST['email'];
$proposedname=$_POST['proposedname'];
$name=$_POST['name'];

//And the validation shown above
//Email validation
if(!Validate::email($email, true)) //use true to use dns lookup
die("Sorry the email you entered is invalid");

//names validation
$min_length = 1;
$max_length = 50;
define('PUNCTUATION', '\.,;\:&"\'\?\!\(\)');
define('EXTRAS', "'" . "-"); //extra punctuation for names
if(!Validate::string($name, array("format" => VALIDATE_EALPHA . VALIDATE_NUM . VALIDATE_SPACE . PUNCTUATION . EXTRAS ,"min_length" => $min_length ,"max_length" => $max_length)))
die("Sorry the name your entered is invalid");

if(!Validate::string($proposedname, array("format" => VALIDATE_EALPHA . VALIDATE_NUM . VALIDATE_SPACE . PUNCTUATION . EXTRAS ,"min_length" => $min_length ,"max_length" => $max_length)))
die("Sorry the proposedname your entered is invalid");

mail("tim@example.com", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");

mail("timmy@example.com", "Name check $name to $proposedname", "

Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

Name: $name
Proposed name: $proposedname
Email address: $email

Thankyou.
","From: $email");
mail("timothy@example.com", "Your choice of name", "

Hi $name,

Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests received 9am - 9pm we aim to reply within 2 hours.

We have received the following information. If any details are incorrect please reply to this email with the correct information.

Name: $name
Proposed name: $proposedname
Email address: $email

Many thanks


","From: mail@cybadev.co.uk");


echo "Place you new div here";

}
?>


There you have it hacker proof code. Though it just exits with an error message if its invalid. You may want to do something more exciting here?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum