-
Sending a Form 20.02.09
This morning I was thinking back to when I started tinkering with HTML back in the 90’s – and how I was always frustrated with forms. I remember wanting to be able to submit data, but not knowing how (as there’s no way using HTML alone). So I thought I’d write a really simple tutorial for those of you who want to dabble in PHP (it’s easy, trust me) to submit data from a form…
View a demo
index.html

We start with writing the standard HTML markup for the form itself, nothing too drastic here. You’ll notice, however, that we’ve got an action and a method – this is the driving force of our form. Post means that the data will be carried (posted) onto the next page, and action is the postal address, in our case, it’s send.php
The only other thing you’ll have to make sure of, is that each item in your form (that you want submitted anyway) has a name. So you’ll see in the above code that we’ve given the first input a ‘name’ and the second an ‘email’.send.php

When the user hit’s the submit button, they get sent to the action, which is send.php in our case. So the use of PHP on this page is to drag the data from our form (index.html) onto our new page. In the above code, we’re telling the PHP what form items to define (i.e. The name and the email) and what we’re going to refer to them as (i.e. ‘users_name’ and ‘users_email’).Below, we can see a practical use for the submitted details – as we use something called ‘echo’ to simply display the value submitted.
send.php

And it’s as simple as that to take a form value from one page to another. However, you’ll probably want to do more with the data than just display it on the second page…. something like populate a MySQL database, or email the submitted details to yourself, for example. Well that’s another story for another day, but I’ve written a tutorial which contains the PHP code that enables you to email the inputted data to yourself, great for a ‘Contact Me’ section on your website.
Have a play, it’s amazing what you can achieve and learn by just messing around!
See the working version here
Download the fully-tutorialized files
Download the basic PHP files
wanna say something?