Complete HTML and PHP Form Walk-Through
I recently coded a landing/splash page for a client of mine that has a form the user fills out and then submits via email to the client. I have coded forms before, but had never learned how the actual submission of data happens via PHP on the server-side. I wanted to share how my simple form works and the code behind it.
Coding the form in HTML is relatively simple. Below is the code used on the client’s live site at nuanced.com/domains.
And here’s basically what the above code looks like without CSS being applied:
Full Name
Domain
Comments (Optional)
So far, it’s all pretty simple and straightforward HTML. However, to get the data being entered on the form from the website to the client, we’ll need PHP. The PHP file gets called in the line below.
The “process.php” file is a separate file that lives in the root directory on the web server that contains our PHP code. Here’s the file below:
As you can see, the form accepts the data being entered after it validates that the inputs are filled out and then parses that data into an email. I added a few comments in the code to explain what some of the lines are doing.
If you’d like to use the above code in your project, just switch out the field names (like fullname, email, etc… ) with your own.
I hope this tutorial helps and if you have a better/more semantic way to do it, let everyone know in the comments.