Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old November 18th, 2012, 08:31 AM
rhapsody rhapsody is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 rhapsody User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 53 sec
Reputation Power: 0
Javascript - Php contact form

I want to add "required fields" alert to my php code,
my code is;

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = '_';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Your message has been sent. We will contact you shortly.');
window.location = 'contact1.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Your message could not be delivered. You can contact us at(_)');
window.location = 'contact1.html';
</script>
<?php
}
?>

any help will be appreciated...

Reply With Quote
Old November 18th, 2012, 08:46 AM
rhapsody rhapsody is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 rhapsody User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 53 sec
Reputation Power: 0
Quote:
Originally Posted by rhapsody
I want to add "required fields" alert to my php code,
my code is;

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = '_';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Your message has been sent. We will contact you shortly.');
window.location = 'contact1.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Your message could not be delivered. You can contact us at(_)');
window.location = 'contact1.html';
</script>
<?php
}
?>

any help will be appreciated...



also tried adding a js. code but it still gives "required fields alert" even though all the fields are filled in...I also wanna add "valid mail address" alert in case...

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

// that's the code I've recently added...
if( (empty($field_name)) || (empty($field_email)) || ($field_message) )
{
echo '<script>alert("The name and address fields are required.");</script>';
echo '<script>history.back(1);</script>';
exit;
}
//

$mail_to = '_';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Your message has been sent. We will contact you shortly.');
window.location = 'contact1.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Your message could not be delivered. You can contact us at(_)');
window.location = 'contact1.html';
</script>
<?php
}
?>

Reply With Quote
Old November 19th, 2012, 05:59 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,439 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
would it not be better to check on form submit?

Code:
<form method="post" onsubmit+"return checkForm()">


where checkForm() is your function to validate.
It would return false until valid fields are entered.
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Reply With Quote
Old November 19th, 2012, 06:59 AM
rhapsody rhapsody is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 rhapsody User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 53 sec
Reputation Power: 0
Quote:
Originally Posted by DavidMR
would it not be better to check on form submit?

Code:
<form method="post" onsubmit+"return checkForm()">


where checkForm() is your function to validate.
It would return false until valid fields are entered.


Thx for help! so where should I put that code then? also want the "mail address alert" to pop up unless the correct type is entered including "@",".com" and so on..

Reply With Quote
Old November 19th, 2012, 07:02 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,439 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
on the page where the form is where you would put it. can you show the form page?

Reply With Quote
Old November 19th, 2012, 08:45 AM
rhapsody rhapsody is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 rhapsody User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 53 sec
Reputation Power: 0
Quote:
Originally Posted by DavidMR
on the page where the form is where you would put it. can you show the form page?


here's the php code;

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = '--@--.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Your message has been sent. We will contact you shortly.');
window.location = 'contact1.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Your message could not be delivered. You can contact us at --@--.com');
window.location = 'contact1.html';
</script>
<?php
}
?>

and the code in html ;

<form action="contact1.php" method="post">
Your Name :<br>
<input name="cf_name" type="text" size="25"><br>
Your e-mail address :<br>
<input name="cf_email" type="text" size="25"><br>
Message :<br>
<textarea name="cf_message" cols="30" rows="3"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>

Reply With Quote
Old November 19th, 2012, 09:11 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,439 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
Code:
<script type="text/javascript">
function checkForm() {
var cf_name = document.getElementById('cf_name');
var cf_email = document.getElementById('cf_email');
var cf_message = document.getElementById('cf_message');

if (cf_name.value.length <= 0) {
alert('no name');
return false;
}

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (cf_email.value.length <= 0 || !filter.test(cf_email.value)) {
alert('no email');
return false;
}

if (cf_message.value.length <= 0) {
alert('no message');
return false;
}
return true;
}
</script>
<form action="contact1.php" method="post" onsubmit="return checkForm()">
Your Name :<br>
<input id="cf_name" name="cf_name"  type="text" size="25"><br>
Your e-mail address :<br>
<input id="cf_email" name="cf_email" type="text" size="25"><br>
Message :<br>
<textarea id="cf_message"  name="cf_message" cols="30" rows="3"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>

Reply With Quote
Old November 19th, 2012, 09:51 AM
rhapsody rhapsody is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 rhapsody User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 53 sec
Reputation Power: 0
Quote:
Originally Posted by DavidMR
Code:
<script type="text/javascript">
function checkForm() {
var cf_name = document.getElementById('cf_name');
var cf_email = document.getElementById('cf_email');
var cf_message = document.getElementById('cf_message');

if (cf_name.value.length <= 0) {
alert('no name');
return false;
}

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (cf_email.value.length <= 0 || !filter.test(cf_email.value)) {
alert('no email');
return false;
}

if (cf_message.value.length <= 0) {
alert('no message');
return false;
}
return true;
}
</script>
<form action="contact1.php" method="post" onsubmit="return checkForm()">
Your Name :<br>
<input id="cf_name" name="cf_name"  type="text" size="25"><br>
Your e-mail address :<br>
<input id="cf_email" name="cf_email" type="text" size="25"><br>
Message :<br>
<textarea id="cf_message"  name="cf_message" cols="30" rows="3"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>


that worked perfect! thanks!

Reply With Quote
Old February 27th, 2013, 05:38 AM
Divya Divya is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 Divya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 28 sec
Reputation Power: 0
Smile

hi i'm new to PHP, could any one tell me how to get the data of a particular column from database of mysql and display it in a listbox on a web page.


Thanks in advance.

Reply With Quote
Old February 28th, 2013, 10:50 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,439 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
Quote:
Originally Posted by Divya
hi i'm new to PHP, could any one tell me how to get the data of a particular column from database of mysql and display it in a listbox on a web page.


Thanks in advance.

you would normally use a sql statement and mssql or mysql not anything client side (unless you use ajax which would be overkill)

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Javascript - Php contact form


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap