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
jack001
Forum Newbie
Posts: 9 Joined: Sun Dec 10, 2006 2:48 am
Post
by jack001 » Sun Dec 10, 2006 3:04 am
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi guys
i am new here
i have designed am email form in php and need some help
i want the alert message box if someone doesnt enter in the required field rather than the echo...
in my php code name, email, subject, inquiry and message are required fields..
plz help see my form at http://www.sharebigfile.com/file/35140/Inquiry.php.html
or see the code below
plz help me guys
thnx in advance
JackCode: Select all
<html>
<body>
<?php
// declare values
$contact_email = $_POST['EmailAddress'];
$contact_subject = $_POST['Subject'];
$contact_name = $_POST['FullName'];
$contact_company = $_POST['Company'];
$contact_address = $_POST['Address'];
$contact_tel = $_POST['Tel'];
$contact_fax = $_POST['Fax'];
$contact_inquiry = $_POST['Inquiry'];
$contact_message = $_POST['Message'];
$mydate = date ( 'l, F d Y g:i A',time()+240 );
// where to send e-mail to
$to = 'info@saqadgifts.com';
// e-mail subject
$subject = "Inquiry from website.";
// e-mail message
$message = "You have received an Inquiry:\r\n"
."----------------------------------------------------------------\r\n"
."Contact Name: $contact_name\r\n"
."Subject: $contact_subject\r\n"
."Company: $contact_company\r\n"
."Address: $contact_address\r\n"
."Tel: $contact_tel\r\n"
."Fax: $contact_fax\r\n"
."Inquiry: $contact_inquiry\r\n"
."Comments: $contact_message\r\n"
."Submitted: $mydate\r\n"
."From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
$headers = "From: $contact_name <$contact_email>\n"
."Reply-To: $contact_email\n"
."Company: $contact_company\n"
."Address: $contact_address\n"
."Tel: $contact_tel\n"
."Fax: $contact_fax\n"
."Inquiry: $contact_inquiry\n"
."X-Mailer: PHP/".phpversion();
// check for validation, then send the e-mail
if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_inquiry) || empty($contact_message)) {
echo '<p>Send us an Inquiry, enter your information below and click \'Submit\'!</p>
<form method="post" action="">
<table id="Form-Details" width="429">
<tbody>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Name:</b></font></td><td width="357">
<input type="text" name="FullName" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Subject:</b></font></td><td width="357">
<input type="text" name="Subject" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Email:</b></font></td><td width="357">
<input type="text" name="EmailAddress" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Company:</b></font></td><td width="357">
<input type="text" name="Company" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Address:</b></font></td><td width="357">
<textarea rows="3" name="Address" cols="43" style="border-style: solid; border-width: 1px"></textarea></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Tel.:</b></font></td><td width="357">
<input type="text" name="Tel" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Fax:</b></font></td><td width="357">
<input type="text" name="Fax" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Inquiry:</b></font></td><td width="357">
<input type="text" name="Inquiry" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Comments:</b></font></td><td width="357">
<font face="MS Sans Serif">
<textarea rows="5" name="Message" cols="43" class="input" style="border-style: solid; border-width: 1px"></textarea></font></td></tr>
<tr><td width="81"> </td><td width="405">
<input type="submit" value="Submit" style="font-family: Tahoma; font-weight: bold; float:left" /><font face="Tahoma"><input type="reset" value="Reset" style="font-family: Tahoma; font-weight: bold; float:left" /></font></td></tr>
</tbody>
</table>
</form>';
} elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
echo "<p>ERROR: Please enter a valid e-mail address.</p>";
} else {
mail( $to, $subject, $message, $headers );
echo "<h3>Message Sent!</h3><p>Dear $contact_name,<br /><br />We will get back to you as soon as possible using $contact_email.";
}
?>
</body>
</html>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by
jack001 on Sun Dec 10, 2006 3:50 am, edited 1 time in total.
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 3:47 am
jack001 wrote: rewuired field
I Didn't Find That Field In Your Code
jack001
Forum Newbie
Posts: 9 Joined: Sun Dec 10, 2006 2:48 am
Post
by jack001 » Sun Dec 10, 2006 3:51 am
neel_basu wrote: jack001 wrote: rewuired field
I Didn't Find That Field In Your Code
sorry dear
i misspelled
its required
**************
i want the alert message box if someone doesnt enter in the required field rather than the echo...
in my php code name, email, subject, inquiry and message are required fields..
***************
plz help me
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 4:01 am
You Can Try It (I Havn't Test It)
======================
Code: Select all
<?php
foreach($_POST as $key_name => $key_value)
{
if(empty($key_value))
{
echo "<script language=\"JavaScript\" type=\"text/javascript\">"."alert(\"You Have Forgotten To Enter Your $key_name\");"."</script>";
}
}
?>
jack001
Forum Newbie
Posts: 9 Joined: Sun Dec 10, 2006 2:48 am
Post
by jack001 » Sun Dec 10, 2006 4:04 am
neel_basu wrote: You Can Try It (I Havn't Test It)
======================
Code: Select all
<?php
foreach($_POST as $key_name => $key_value)
{
if(empty($key_value))
{
echo "<script language="JavaScript" type="text/javascript">"."alert("You Have Forgotten To Enter Your $key_name");"."</script>";
}
}
?>
thanks
but where to insert this exactly???
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 4:08 am
Before Your Code
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 4:11 am
jack001 wrote: in my php code name, email, subject, inquiry and message are required fields..
Sorry I Overlooked This Line The Code I Gave You Will Check each And Every field
jack001
Forum Newbie
Posts: 9 Joined: Sun Dec 10, 2006 2:48 am
Post
by jack001 » Sun Dec 10, 2006 4:18 am
neel_basu wrote: You Can Try It (I Havn't Test It)
======================
Code: Select all
<?php
foreach($_POST as $key_name => $key_value)
{
if(empty($key_value))
{
echo "<script language="JavaScript" type="text/javascript">"."alert("You Have Forgotten To Enter Your $key_name");"."</script>";
}
}
?>
dude its working
but if i dont enter any field and the alert popups and when i click ok it goes back to the form but it empties the form fields...
yy??
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 4:24 am
Can You Send Me The Full Script
jack001
Forum Newbie
Posts: 9 Joined: Sun Dec 10, 2006 2:48 am
Post
by jack001 » Sun Dec 10, 2006 4:30 am
neel_basu wrote: Can You Send Me The Full Script
here is the full script
http://www.sharebigfile.com/file/35140/Inquiry.php.html
can u add what ur suggesting at the right place
and i need the user must enter a valid email address with just one "@"
plz help me out
for so many days i am in tension for this
thnx in advance
jack
u can upload after editing the script....
thnx
jack
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 4:47 am
I Cant Access That File
Plsease Enter Here And Just Copy Paste Your File
ftp://59.93.201.25/
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 5:17 am
OK Add This Code Before Your Code
======================================
Code: Select all
<?php
if($_POST)
{
foreach($_POST as $key_name => $key_value)
{
if(empty($key_value))
{
echo "<script language=\"JavaScript\" type=\"text/javascript\">"."alert(\"You Have Forgotten To Enter Your $key_name\");"."</script>";
}
}
}
?>
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 9:47 am
Here Is It Compleated
===============
Code: Select all
<html>
<body>
<?php
// declare values
$contact_email = $_POST['EmailAddress'];
$contact_subject = $_POST['Subject'];
$contact_name = $_POST['FullName'];
$contact_company = $_POST['Company'];
$contact_address = $_POST['Address'];
$contact_tel = $_POST['Tel'];
$contact_fax = $_POST['Fax'];
$contact_inquiry = $_POST['Inquiry'];
$contact_message = $_POST['Message'];
$mydate = date ( 'l, F d Y g:i A',time()+240 );
// where to send e-mail to
$to = 'email@domain.com';
// e-mail subject
$subject = "Inquiry from website.";
// e-mail message
$message = "You have received an Inquiry:\r\n"
."----------------------------------------------------------------\r\n"
."Contact Name: $contact_name\r\n"
."Subject: $contact_subject\r\n"
."Company: $contact_company\r\n"
."Address: $contact_address\r\n"
."Tel: $contact_tel\r\n"
."Fax: $contact_fax\r\n"
."Inquiry: $contact_inquiry\r\n"
."Comments: $contact_message\r\n"
."Submitted: $mydate\r\n"
."From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
$headers = "From: $contact_name <$contact_email>\n"
."Reply-To: $contact_email\n"
."Company: $contact_company\n"
."Address: $contact_address\n"
."Tel: $contact_tel\n"
."Fax: $contact_fax\n"
."Inquiry: $contact_inquiry\n"
."X-Mailer: PHP/".phpversion();
// check for validation, then send the e-mail
$cnt_post = 0;
$hld_error = " ";
if($_POST)
{
foreach($_POST as $key_name => $key_value)
{
if(empty($key_value))
{
$cnt_post++;
$hld_error .= $key_name."\t\t\\n";
}
}
if($cnt_post > 0)
{
echo "<script language=\"JavaScript\" type=\"text/javascript\">"."alert(\"You Have Forgotten To Enter Your ".$hld_error."\");"."</script>";
}
}
if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_inquiry) || empty($contact_message)) {
echo '<form method="post" action="">
<table id="Form-Details" width="429">
<tbody>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Name:</b></font></td><td width="357">
<input type="text" name="FullName" value="'.$_POST[FullName].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Subject:</b></font></td><td width="357" >
<input type="text" name="Subject" value="'.$_POST[Subject].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Email:</b></font></td><td width="357" >
<input type="text" name="EmailAddress" value="'.$_POST[EmailAddress].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Company:</b></font></td><td width="357">
<input type="text" name="Company" value="'.$_POST[Company].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Address:</b></font></td><td width="357">
<textarea rows="3" name="Address" cols="43" style="border-style: solid; border-width: 1px"></textarea></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Tel.:</b></font></td><td width="357">
<input type="text" name="Tel" value="'.$_POST[Tel].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Fax:</b></font></td><td width="357">
<input type="text" name="Fax" value="'.$_POST[Fax].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Inquiry:</b></font></td><td width="357">
<input type="text" name="Inquiry" value="'.$_POST[Inquiry].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Comments:</b></font></td><td width="357">
<font face="MS Sans Serif">
<textarea rows="5" name="Message" cols="43" class="input" style="border-style: solid; border-width: 1px"></textarea></font></td></tr>
<tr><td width="81"> </td><td width="405">
<input type="submit" value="Submit" style="font-family: Tahoma; font-weight: bold; float:left" /><font face="Tahoma"><input type="reset" value="Reset" style="font-family: Tahoma; font-weight: bold; float:left" /></font></td></tr>
</tbody>
</table>
</form>';
} elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
echo "<p>ERROR: Please enter a valid e-mail address.</p>";
} else {
mail( $to, $subject, $message, $headers );
echo "<h3>Message Sent!</h3><p>Dear $contact_name,<br /><br />We will get back to you as soon as possible using $contact_email.";
}
?>
</body>
</html>
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Sun Dec 10, 2006 9:53 am
You Can Also Use It
==============
I ahve Replaced
Code: Select all
if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_inquiry) || empty($contact_message))
With
So Now The Compleate Code Is
======================
Code: Select all
<?php
$email_to = "neel.basu.z@gmail.com"; // Write Your email address here
$redirect_after_success_location = "http://www.YourSiteName.com/redir.php";
// declare values
$contact_email = $_POST['EmailAddress'];
$contact_subject = $_POST['Subject'];
$contact_name = $_POST['FullName'];
$contact_company = $_POST['Company'];
$contact_address = $_POST['Address'];
$contact_tel = $_POST['Tel'];
$contact_inquiry = $_POST['Inquiry'];
$contact_comment = $_POST['Comment'];
$mydate = date ( 'l, F d Y g:i A',time()+240 );
// check for validation, then send the e-mail
$cnt_post = 0;
$hld_error = " ";
if($_POST)
{
foreach($_POST as $key_name => $key_value)
{
if(empty($key_value))
{
$cnt_post++;
$hld_error .= $key_name."\\n";
}
}
if($cnt_post > 0)
{
echo "<script language=\"JavaScript\" type=\"text/javascript\">"."alert(\"Please complete the following fields:\\n\\n ".$hld_error."\");"."</script>";
}
}
if($cnt_post > 0 || empty($contact_email)) {
echo '<form method="post" action="">
<p><span style="font-size: 10.0pt; font-family: Verdana">If you have any inquiry
regarding our product details, quotation,product<br>
availability,delivery time or
you just want to leave a message please fill<br>
the below form and sendit to us.
We promise prompt attention.<br>
We will get back to you as soon as possible.</span></p>
<table id="Form-Details" width="429">
<tbody>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Name:</b></font></td><td width="357">
<input type="text" name="FullName" value="'.$_POST[FullName].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Subject:</b></font></td><td width="357" >
<input type="text" name="Subject" value="'.$_POST[Subject].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Email:</b></font></td><td width="357" >
<input type="text" name="EmailAddress" value="'.$_POST[EmailAddress].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Company:</b></font></td><td width="357">
<input type="text" name="Company" value="'.$_POST[Company].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Address:</b></font></td><td width="357">
<textarea rows="3" name="Address" cols="43" style="border-style: solid; border-width: 1px">'.$_POST['Address'].'</textarea></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Tel.:</b></font></td><td width="357">
<input type="text" name="Tel" value="'.$_POST[Tel].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Inquiry:</b></font></td><td width="357">
<input type="text" name="Inquiry" value="'.$_POST[Inquiry].'" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Comments:</b></font></td><td width="357">
<font face="MS Sans Serif">
<textarea rows="5" name="Comment" cols="43" class="input" style="border-style: solid; border-width: 1px">'.$_POST['Comment'].'</textarea></font></td></tr>
<tr><td width="81"> </td><td width="405">
<input type="submit" value="Submit" style="font-family: Tahoma; font-weight: bold; float:left" /><font face="Tahoma"><input type="reset" value="Reset" style="font-family: Tahoma; font-weight: bold; float:left" /></font></td></tr>
</tbody>
</table>
</form>';
} elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
echo "<p>Please enter a valid e-mail address.</p>";
} else {
// where to send e-mail to
$to = $email_to;
// e-mail subject
$subject = "Inquiry from website.";
// e-mail message
$headers = "From: $contact_name <$contact_email>\n"."Reply-To: $contact_email\n";
$message = "You have received an Inquiry:\r\n"
."----------------------------------------------------------------\r\n"
."Contact Name: $contact_name\r\n"
."Subject: $contact_subject\r\n"
."Company: $contact_company\r\n"
."Address: $contact_address\r\n"
."Tel: $contact_tel\r\n"
."Inquiry: $contact_inquiry\r\n"
."Comments: $contact_comment\r\n"
."Submitted: $mydate\r\n"
."From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
mail( $to, $subject, $message, $headers );
header("location:$redirect_after_success_location");
}
?>