| View previous topic :: View next topic |
| Author |
Message |
popkha
Joined: 09 Mar 2009
Posts: 1
|
| Posted: Mon Mar 09, 2009 12:28 pm how to change my php/html contact form script |
|
|
:?: hi please help me wit my contact form.
I need a pop up message and not the new window to show that email has been sent.
or page to reload and display the message in the same window
take a look here,
http://e-lineinc.com/eline1.0/BET/oc/contacts.html
thanks
I have php code that sends the file, but I think it needs some workaround. I also have some javascript for close button.
could you please look at it:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "myemailatrrr.com";
$email_subject = "Feedback from e-Line inc";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form your submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form your submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!eregi($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
$string_exp = "^[0-9 .-]+$";
if(!eregi($string_exp,$telephone)) {
$error_message .= 'The Telphone Number you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below:\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<p>Thank you for contacting us. We will be in touch with you soon!! </p>
<p>
<FORM><INPUT TYPE="BUTTON" VALUE="Go Back"
ONCLICK="history.go(-1)">
</FORM>
<p>
<FORM><input type="button" onClick="javascript: window.close();" value="Close" />
<?
}
?></FORM>
</p> :?: |
|
|
gummyworms
Joined: 13 May 2009
Posts: 18
|
| Posted: Wed May 13, 2009 1:52 am |
|
|
This is unfortunately the draw back of php post function.
I offer you a compromise. First when the user reaches the php page have this command in it
<?php
header( 'Location:http://e-lineinc.com/eline1.0/BET/oc/contacts.html' ) ;
?>
Put this in your if then statement after everything is all checked. Now the great part about this is that when redirection happens it usually happens with 1 sec, your clients wont notice anything at all maybe a flash white screen.
Now for your pop up thing have something like this
do something like require 'pop.html'
the pop.html would have the code for a pop window only like this
<script>
window.open("message.html","Window1",
"menubar=no,width=430,height=360,toolbar=no");
</script>
the message.html will contain whatever message you want to use.
I know this might be a little too much work. If you understand what i am trying to do you can definitely simplify everything
I hope that helps |
|
|
| |
|
|
|