<

Introduction to PHP: Building the Form

Posted on
6,646 Points
446 Views
2 Endorsements
Last Modified:
Published
Experience Level: Beginner
5:07
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

2
Author:Jason Baker
0 Comments

Suggested Videos

In configurations with multiple monitors, it can be difficult and time-consuming to move the mouse pointer to a particular monitor. This article presents a script written in AutoHotkey that defines hotkeys — such as Alt+Ctrl+1, Alt+Ctrl+2, etc. — to…
Presenting data tables with the ability to interact with the DIVs or cells of information and allowing the first column and the first row to remain in place while scrolling through the data. No HTML tables... just DIVs in columns

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month