PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

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 16th, 2012, 05:02 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
php4 - Php contact form

hey!

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 16th, 2012, 08:38 AM
MatthewJ MatthewJ is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 1,021 MatthewJ User rank is Lance Corporal (50 - 100 Reputation Level)MatthewJ User rank is Lance Corporal (50 - 100 Reputation Level)MatthewJ User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 6 Days 12 h 13 m 18 sec
Reputation Power: 9
Check this tutorial out... it should give you some ideas on how to handle validation with PHP.

http://phpmaster.com/form-validation-with-php/

Matt

Reply With Quote
Old November 16th, 2012, 08: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
some javascript on the previous page would be a good thing to have. Check the fields beforehand so that the user doesn't have to submit the page before learning that he/she missed something.
__________________
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 16th, 2012, 10:00 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
some javascript on the previous page would be a good thing to have. Check the fields beforehand so that the user doesn't have to submit the page before learning that he/she missed something.


i tried adding this code;

if ($field_name != '') { ?>
<script language="javascript" type="text/javascript">
alert('Please fill in your name.');
window.location = 'contact1.html';
</script>
<?php
}

but it still doesn't help... do you have any idea how i could make this work?

Reply With Quote
Old November 16th, 2012, 10:37 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
IMO you are going about it the wrong way. You should be doing the checks before they submit the form in javascript. then have PHP checks when they submit just to be safe.

Ideally what you want is a function called when the form is submitted. If you provide some code for the contact form, i can help you with that. But if that is what you want, you would be better asking to have this thread moved to "Client side Things" where javascript is dealt with (I answer questions there too)

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php4 - 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