<

Introduction to PHP: Building the Form

Posted on
6,424 Points
325 Views
1 Endorsement
Last Modified:
Experience Level: Beginner
5:09
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing.

Video Steps

1. Set up your basic HTML file. Open your form tag and set the method and action attributes.


<!DOCTYPE html>
<html>
	<head>
		<title>My first php script</title>
	</head>
	<body>
		<form method="post" action="process.php">

Open in new window

2. Set up your first few inputs one for the name and the gender.

A simple set of radio buttons will do here.
<label>Name: <input type="name" name="fullname" placeholder="Enter your name here."></label>
<label>Gender: <input type="radio" name="gender" value="M" checked>Male  <input type="radio" name="gender" value="F">Female</label>

Open in new window

3. Label the date of birth field, setup a few select boxes that will use PHP to loop through respectively to get the month, day and year.


<label>Birthday: <select name="month">
				<?php for($m=1; $m<=12; $m++){
							echo "<option value=".$m.">".$m."</option>";
				} ?>
				</select>/
				<select name="day">
				<?php for($d=1; $d<=31; $d++){
							echo "<option value=".$d.">".$d."</option>";
				} ?>
				</select>/
				<select name="year">
				<?php for($y=1880; $y<=2014; $y++){
							echo "<option value=".$y.">".$y."</option>";
				} ?></select>
			</label>

Open in new window

4. Set up a field for the email address.


<label>E-mail: <input type="email" name="emailaddy" placeholder="Enter your best email address."></label>

Open in new window

5. Label the randomized ID # as ID #. Set the variable for this ID number and put it into a hidden field.


<label>My ID #: <?php $nyid=rand(0,199999); echo $myid; ?>
			<input type="hidden" value="<?php echo $myid; ?>"></label>"][/step]
[step="6" title="Set your submit button and close out the form and page.

			<label><input type="submit" name="saveme" value="Send Profile"></label>
		</form>
	</body>
</html>

Open in new window

1
Comment
Author:Jason Baker
0 Comments

Featured Post

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

Join & Write a Comment

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month