Register Advertise with usHelp Desk Today's Posts Search

Thread Tools Search this Thread
Unread 12th Feb 2019, 01:26 PM   #1
Active Warrior
 
Join Date: 2009
Posts: 95
Thanks: 111
Thanked 8 Times in 7 Posts
Default
Making the Fields required in a Contact Form
Share on: 
fb share twitter share gplus share more share

<?php
if(isset($_POST['submit'])) {

$myemail = "your-email-address@here.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From:Contact Form <$myemail>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";

echo "Your message has been sent successfully!";
mail($myemail, $subject, $message, $headers);

} else {

echo "An error occurred during the submission of your message";

}
?>

Anyone have any suggestions on what code I could add to make the fields in the above contact form required?

Thanks!

dansbanners is offline   Reply With Quote
Unread 9th Mar 2019, 09:31 AM   #2
Howdy
War Room Member
 
Valdor Kiebach's Avatar
 
Join Date: 2008
Location: England
Posts: 683
Thanks: 103
Thanked 150 Times in 124 Posts
Default
Re: Making the Fields required in a Contact Form
Share on: 
fb share twitter share gplus share more share

Use javascript to check form field validation
https://www.w3schools.com/js/js_validation.asp


or PHP
https://www.w3schools.com/php/php_form_validation.asp
Valdor Kiebach is offline   Reply With Quote
The Following User Says Thank You to Valdor Kiebach For This Useful Post:
Unread 10th Mar 2019, 02:27 PM   #3
Active Warrior
 
Join Date: 2009
Posts: 95
Thanks: 111
Thanked 8 Times in 7 Posts
Default
Re: Making the Fields required in a Contact Form
Share on: 
fb share twitter share gplus share more share

Originally Posted by Valdor Kiebach View Post

That's on the right track.

Now, I'm trying to figure out how to combine the following:
https://www.w3schools.com/php/php_form_required.asp

With the php code shown in the op, whereas the form mail gets sent only after all required fields have been filled?

Thanks again!

dansbanners is offline   Reply With Quote
Unread 13th Mar 2019, 04:38 AM   #4
ANJAN KUMAR DHALI
 
ANJANBD's Avatar
 
Join Date: 2014
Location: Bangladesh
Posts: 73
Thanks: 3
Thanked 18 Times in 12 Posts
Default
Re: Making the Fields required in a Contact Form
Share on: 
fb share twitter share gplus share more share

please checkout Create Contact form using php mysql

ANJANBD is offline   Reply With Quote
The Following User Says Thank You to ANJANBD For This Useful Post:
Unread 11th Apr 2019, 12:55 PM   #5
Active Warrior
 
Join Date: 2009
Posts: 95
Thanks: 111
Thanked 8 Times in 7 Posts
Default
Re: Making the Fields required in a Contact Form
Share on: 
fb share twitter share gplus share more share

Which brings the next question, I'm wondering that rather than just having the message "Your message has been sent successfully!" written as shown in the op, I rather that it be taken to a thank you page after the form submission. How to do so? Thanks again in advance!

dansbanners is offline   Reply With Quote


Bookmarks

Tags
contact, fields, form, making, required


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:33 AM.