Email Form PHP Coding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ghi572000
Forum Newbie
Posts: 6
Joined: Mon Sep 20, 2010 4:02 pm

Email Form PHP Coding

Post by ghi572000 »

Hi new here so not sure if in the right forum, however I am using a email form in php and want to find a way so when the error messages in the form open, they will open in a pop up rather than having hit the back button to go back to the form? Do I need to add some JS to make this happen or is it a matter of adding some additional code somewhere?

This is the code im using in Code for sendemail.php:

Code: Select all

<?php

$ip = $_POST['ip']; 
$httpref = $_POST['httpref']; 
$httpagent = $_POST['httpagent']; 
$visitor = $_POST['visitor']; 
$visitormail = $_POST['visitormail'];
$subject = $_POST['subject'];
$phone = $_POST['phone'];
$notes = $_POST['notes'];
$attn = $_POST['attn']; 

if (eregi('http:', $notes)) {
die ("Please enter your message before you try submitting the form. ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
{
echo "<h2>Go Back - Please enter a valid e-mail address.</h2>\n"; 
$badinput = "<h2>Email not Valid something is wrong with the address you enterd.</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Go Back and fill in all fields correctly before you try submitting the form.</h2>\n";
die ("go back and try again"); 
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ; 
$subject = "WEB SITE MAIL" ; 

$notes = stripcslashes($notes); 

$message = "$todayis [EST] \n
Subject: $subject \n 
From: $visitor ($visitormail)\n
Phone: $phone \n 
Message: $notes \n
IP Address: IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("admin@myemail.co.uk", $subject, $message, $from);

?>

Any help will be appreciated
Regards
Gary
TonsOfFun
Forum Commoner
Posts: 54
Joined: Wed Jun 02, 2010 7:37 pm

Re: Email Form PHP Coding

Post by TonsOfFun »

I don't know about the pop-up, but the way I do forms is that I make them 'sticky'.
So when the user clicks submit, it displays the errors at the top, and creates a form that has their previous answers in the fields.
ghi572000
Forum Newbie
Posts: 6
Joined: Mon Sep 20, 2010 4:02 pm

Re: Email Form PHP Coding

Post by ghi572000 »

Tons of fun thanks for your input but do you have an example of your method and how you implement it in to your forms?
Regards
Gary
Post Reply