HTML/PHP Contact Form Tutorial with Validation and Email Submit
Vložit
- čas přidán 1. 11. 2016
- Upgrade your Clever Techie learning experience:
/ clevertechie
UPDATE! (9/13/19) New features and improvements for Clever Techie Patreons:
1. Download full source code with detailed comments - easy to learn and understand code
2. Weekly source code file updates by Clever Techie - every time I learn new things about a topic I will add it to the source file and let you know about the update - keep up with the latest coding technologies
3. Library of custom Clever Techie functions with descriptive, easy to understand comments - skyrocket coding productivity, code more efficiently by using Clever library of custom re-usable functions
4. Syntax code summary - memorize and review previously learned code faster
4. Organized file structure - access all Clever Techie lessons, source code, graphics, diagrams and cheat sheet from a single workspace - no more searching around for previously covered material and source code - save enormous amount of time and effort
5. Outline of topics the source file covers - fast review of all previously learned coding lessons
6. Access to all full HD 1080p videos with no ads
7. Console input examples - interactive examples that make it easier to understand and learn coding
8. Access to updated PHP Programming Book by Clever Techie
Download this video's source code and additional files here:
/ html-php-contact-20812527
`````````````````````````````````````````````````````````````````````````````````````````````
This is a fast way to create your own HTML contact form with PHP validation rules and email submit. We use codepen.io which is a great web site for downloading existing code for web developers. We then modify the code to suit our needs and include PHP validation rules. You can use this same process to create just about any HTML form with CSS and PHP validation rules and submit the email using PHP. By knowing how the process of submitting the form and validation works, you'll be able to create your own custom HTML contact, registration and login forms and validate them with PHP. - Jak na to + styl
This was an excellent video. I am a pretty experienced coder who has been struggling with godaddy nonsense and I want you to know that your explanation of PHP mail functionality was excellent. Anyone watching this, like most videos, I suggest having the doc's open so you can go threw each line of code with him and really understand what he's saying.
There is a lot of information on how to set-up the form and to even make the form dynamic, but nothing that actually showed the PHP information. Bravo. I actually understood it.
Two days of research to find a way to use my own pre-existing form and integrate it with mail chimp! Everything I was finding involved creating a form through mail chimp and embedding it in my site. I already have my site designed and just needed the functionality of the opt in box to work with my autoresponder list. Finally found your video that gave me the ground work to make it happen! Kudos to you sir, and thank you so much for making this video!
Outstanding tutorial, even after 4 years. Thanks, CT!!!
This video made me understand a whole lot more PHP and how it's working! I can't thank you enough sir!
I did not know codepen, you changes my live forever!!! Thank you. Cheers
Thank you for the tutorial. How would i use this method if I had to choose at least one checkbox in my contact form or an option from a drop down.
thank you for the tutorial, it really help me understanding how the validation works
Great Tutorial thank you!. In order to call itself we could use $_SERVER['PHP_SELF'] or the name of the php file directly. Which one is the better/more secure option? What are the differences?
Thanks
Hey, thanks for this tutorial. I'd really like to be able to add the option to upload images, pdfs and doc attachments before hitting submit. Is there a way to add this ability to this existing form?
Hi there!!! Thank you for this video, it's really great. I have one question. If I have one page site and my contact form is on the end of the page, how to prevent page to go back to the top if there are some error or the message is sent and make it stay on the form section? Thanks!!!
Thanks a lot for making this, I have been looking for a good php form tutorial all day. Glad I found this! Stuff works ^^
Thanks! You helped me a lot!!
By the way, what if I let the "action" property empty? Is this a bad practice?
They way you explain how to edit the ini file and retrieve your smtp from ur ispn SAVED ME!!!!!
Hi there! thanks for taking the time to explain in detail. Please is there a way to record the same contact form data into mysql database at the same time? will the php connection script go into; form.css, form.php, or form_process.php? thanks
Hey Techie! This video is great! What text editor are you using and how do you open it in the browser from the text editor. I am using VS code but I can only open HTML files through a live server in Google chrome. I would really appreciate your help.
Thank you very much! You made it easier for me to understand the steps and how they work. :)
Just a thanks to clever techie, am an old HTML and PHP user, any recommendations of what video to watch doing a refresher course of doing html and php again, was stuck doing oracle and java for a long time. Videos like these helps. BTW where do you download the software your using.
what if i have more than One form on the same page to validate using action="" How will i be able to differentiate the form
Very good tutorial! I built my contact form with your help and it works :) Thanks
Thank You for the the tutorial.
Please help me with some doubts.
What should come at "sendmail_from" in php.ini file ?
what should come at $to variable in form_process.php ?
Help me
Bingo... the way you explained it was absolutely simple and to the point.... Keep on the good work mates.... :)
I live in the UK and had a problem with both the $phone validation and the $url validation you're using. So I switched to (!filter_var($phone, FILTER_SANITIZE_NUMBER_INT)) for the $phone and (!filter_var($url, FILTER_VALIDATE_URL)) for the $url, which both work fine. Very well explained tutorial, thank you.
Thanks very much, Clever Techie. Picked up a couple of sound ideas from you. I appreciate.
Glad to help
great job man, I would like to change on the settings the phone number you are using and maybe using a more complex tool that would detect from the ip the country list, and validate the phone number, do you know how can i do that? THanks
Great tutorial, thanks for the help - did a bit of customization and got it all working!
I have noticed one issue however while testing... OK so validation & form submit both work correctly. After a successful submit, the variables get cleared and page refreshes. NOW at this point - when I refresh the page again manually (all fields empty!!) and wait a minute or two, I receive another email from the form with the previous variable intact from before they were cleared.... Any thoughts?
sir i am not getting color after adding
Just a couple of questions
1) I am making a forum and value="" only works for but the values in and are not remembered so is there any way around that?
2) Is there a way to remember "toggle state" so that a section of a page that is opened by clicking a button remains open after page reloads due to error?
this was really helpful !! but how do you preview within the server? I am using brackets and for some reason, it will not allow me to preview the php file
Great video Vladimir! Thank you for sharing this tutorial in such an awesome style! Really enjoyed it.
i guess Im asking the wrong place but does someone know of a way to log back into an instagram account..?
I stupidly forgot my password. I would appreciate any assistance you can offer me.
@Albert Calvin instablaster ;)
@Atlas Cayden thanks for your reply. I found the site through google and Im waiting for the hacking stuff now.
Takes a while so I will get back to you later with my results.
@Atlas Cayden It did the trick and I actually got access to my account again. Im so happy:D
Thank you so much, you saved my account !
@Albert Calvin No problem :)
Netbeans...would there be any other platform/editor that would suffice for these purposes?
Thanks!
there is XAMPP, which allows you to host a full website locally on your machine to test
Thanks, do you know how to prevent page reload after submitting with AJAX?
Hello. Can any help with how i would send the completed form to my workbench DB table instead of sending to an email account like the video shows?
Hello @clever Techie thank you for this, I was run ragged for weeks trying to do email form submits using ruby on rails and it was a fucking nightmare with the MVC architecture. PHP done this in 3 files whilst ruby had about 15. Thank you once again
Thank you very much for the help! I have subscribed and liked this video!
Hey Clever Techie, I am working on a website for a class right now and really wanted to incorporate something similar to what you've done here, but when i try and submit the form, the page loads constantly and never actually loads anything. It also never shows me the success message or send the email. Would you know any way around this?
Well explained thanks goodwork..... hope you will do one on re-captcha
Thank you brother
Can you do think same video using Adobe Dreamweaver 2018...im not sure how to implement some of the things you do into my site on dreamweaver. Thanks!
he php.ini file is it in the same folder with the files you are using? If yes are we linking the page as we have done with the css and php files?
Thank you for this video, it is really helpful. But I also want to validate textarea field (show error message if it is empty). I applied the same logic as applied for other fields but it does not work. I am not getting error message after textarea. Please suggest something.
Hello! Can you add a Part 2 video on which you add a confirm screen, and a complete screen with or without sessions?
Very well explained. Thks a lot!!
Hi Thanks for the great post. How would I include an email address that the sender of the message receives?
You just call another mail function with sender's email address and different body message.
You have answered a w3schools question which they never answered after their same pho form code on how to display an error message. Awesome. I then learnt jquery and if filling out boxes wrong validation worked, only if i never filled out boxes and just clicked submit on a blank form, error messages would appear in all the form boxes and you'd stay on the html form page, only I wiuld receive an email to. Blank fields. This is obviously because php was waiting untill submit button selected as jquery was. Any obvious solution ...?
Why didnt you get the values input (e-mail, phone...)in the outlook e-mail? Thanks
Ok so your telling me that once this has fully been coded once information has been submitted all the information goes to your email address if not then what's that called?
Thanks for this! Great video.
Working!! Finally a good source!!
Awesome tutorial. Thans bro!!!
Hey I am getting unknow variable $data when I try to load my page. Is it because I didn't make if statements for all variables?
Hey Clever Techie, I am using Atom Editor; So where to find php.ini file?
Good morning,
I would like to know how do you open php.ini this file. Where It is found?
Then you restart Apache in the services in the windows.
I wait you an answer.
Thanks a lot for a video.
This was well explained..thank you so much.
Validation seems to work and an e-mail got send with all the inputs but my mailbox says it's coming from an unknown sender. Why is that?
after all the validation my question is how would you insert it in the database? because sending the message to an email is not what im after for but its about on how could i save it into the database after checking or validating all data.
Hi, can you please help me add code few more input fields to my existing contact form if I send you my php files? I am struggling at the moment. Thanks
"value=" is not a valid argument for "textarea" tag....after a little research I found the right way to make it work (stackoverflow):
Thank you very much ! I am a beginner and I just learned a lot from your video!
Why I got the php value code, shown up in the text bar in the form?
Like where I got the input type text area, my website shows the code: for example. What am I doing wrong?
You got me for a moment, I was skipping for 5sec getting to one part and I saw you typed in Vladimir... my name is Vladimir.
I upload the file on my hosting server, but whenever i send mail, it say mail sent successfully but not sending to my mail id plz help
I am not getting Apache service in my services, where else should I find it?
Hi! Great Tuto. But i still have a problem. I did everything as you did. But when i sens the message the message area is cleared but not the other txt areas i.e name, email...and the confirmation message is not displayed. Coule you help please...
Good stuff. Thanks man ✊🏽
Hi, I already have a html and css design and I need the php code so that the emails can be sent through my web page. When I paste the code that you link, it sends me to another page with a new design of contact.
Thank you for the video.
I have a question
I downloaded XAMPP but it does not work because I have windows x86 and all versions of XAMPP in the website are for Windows x64
Could you please help me?
how to fix this error when submitting
{"code "methodNotAllowedError", "message":POST is not allowed"}
Which text editor do u use?
hello Clever Techie, Subscribed!
;)
oh man thanks a lot it worked, you save my day Kudos! :)
Well I had to subscribe/patreon to get the code and it doesn't work at stopping anything. Have you tried your own code to see if you can input fake emails and url's and phones and still send it? Would be curious to know if you have tried to spam yourself.
Thank you Clever Techie! I'm new to coding. The files worked after renaming my contact.html page (started with html and css) to contact.php and transferring them to the server. Had to tweak them a bit, but my contact page works great! Did catch the $message_body variable. Also added between tags (instead of inside the opening tag) in order to keep my message (textarea) from getting cleared. Watched the video again to catch the at the end that shows you how to display $success. I'll definitely subscribe to your channel!
plz give php codeing ....
Thank you for the info. However, my error are not being caught. How can I send you the code I'm using (which is mostly yours) so you can check it out?
Very Helpful. Thanks man. : )
the video helped a lot but the localhost has the wrong stmp values, how would i find the right values
save my day! thank you so much :)
hi, can someone help me? i need the contact form not to be on a single page by itself, but on a page for example, at the end of the page. How can that be done? thanks alot!
where should we include that php code in the html website. I mean in the body or head ??
Hi, i did everything right but when I click submit I get this error on my browser "Forbidden
You don't have permission to access /form/< on this server."
Hi just watched your video, great tutorial by-the-way. Is there a way I can change the $success div element (on line 65 of the form_process.php), so the background changes color after the form has been submitted. Any help would be appreciated, thanks!
jQuery
Can't seem to get the words "Message" to display in the form.php. If I can get this on issue resolved it would be great. Great video!
Thank you!
It really helped me a lot.
You're welcome!
Its great to see that there are still people as clever and helpful as yourself on the internet...
Awesome video! Thanks a lot
i am using the Dreamviwer and their is no loacthost for run this an you suggest which local host i will install for testing the code.
Try installing spellcheck first. Do you charge for your services, how much?
Wow. Rude. There's a way to get subscribers dude. Are you serious?
seriously ? Thats really rude. No one is perfect and Its not his mother language as well.. Even you have done mistakes during this tutotrial
the php.ini file is it in the same folder with the files you are using? If yes are we linking the page as we have done with the css and php files?
HELP! when i click on submit just to check if my errors will appear nothing happens, and i checked my code for like 1000 times and everything is ok.
It does not work in Dreamweaver at all. So what program did u use?
Hi!, you don't send the message_body to your email, just the $message textarea.
You need to put $message_body in mail function, don't $message var.
Yes, you're correct! I noticed this mistake after I already uploaded the video, thank you for mentioning this :)
Is this why only the comments get sent? My contact form works, but in the email I received in my test, there was no name, email, ph# or website, just comments, so I have no clue who sent the message.
thanks
Yeah good spot. I actually noticed it in the video right away because he said "message body" out loud, while typing "message" so that made it apparent if you really paid attention ^^
thank you for the correction.
can you tell me how can I send an acknowledgment mail to the person who fills the inquiry form ?
As in :
Thank your filling up the form, the XYZ team will contact you withing 24 hours.
this message should be sent after the user clicks on submit button. is it possible ?
Thank you, helps me solve the problem!
hi clever techie thank you for this video i"m getting success message but i"m not getting the email. I'm using local host and i put SMTP = smtp.gmail.com and smtp port to 465. please helpme!
i dont get the css here:( what is the next in line after container?
Great tutorial, thanks a lot for sharing it has helped me a bunch!! FYI, you forgot a closing php tag on the form_process code. May confuse someone who is just starting out.
where do I download the PHP file from
very nice helped me a lot brother
good kedep going brother
How to Quickly learn php ? what are Differences between these languages AJAX XML DOM ? Please tell briefly !
hey guys, I have problem. Everything on page work fine but I don't receive any Emil.
i change only email. I need to do something more ?
Thanks for reply
Will this validation method STOP spam email? In regards to the comment below me and your issues with godaddy, I have had the same issues with hostgator. So kudos to the creator of this video!
Maybe I'm seeing it wrong, but in the email send to you, where do you see the sender's name, url & phone number?
same problem
It's because he sent only the $message instead of the $message_body
@@wethekidsz thank you I was stuck on this
hi i found your teaching so interesting but i didn't understand it very well because am a beginner in website, i want to know different between PHP and Html? please help
Hi, I did what you did. I modified php.ini. But it never send the e-mail. It writes an error like:"Warning: mail(): Failed to connect to mailserver at "smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\PhpProject1\form\form_process.php on line 64"
I also watched various videos on CZcams to solve this problem but nothing worked for me. Also I want to ask some questions regarding your video?
1. Where did you write your email account pass? Is not it necessary?
2. In other videos people used sendmail.ini file. But you never mentioned it. Which one is correct?
Thanks in advance.
I have the same issue and I am guessing OP is running a mail service in parallel with WAMP that intercepts the mail and makes the connection. The password is set in that parallel mail system, methinks. Other vids refer to variables set with the password, where this .ini does not.
He said set it to port 25 not 587, try that......
I had to upgrade my hosting account. At the base shared server acccount, I didn't have access to all the controls you really need to send emails.
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in G:\xampp\htdocs\lessons\formcontact\form_process.php on line 64-----i have this error to i am fed up
I think google disabled support for such test emails on gmail
thanks for this..but why I am getting this error? Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\contactform\form_process.php on line 53
nice and clear video. thanks