<

Introduction to PHP: Building the Form

Posted on
6,643 Points
443 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

PHP is a popular programming language that is widely used for web development. One of the key features of PHP is its error and exception handling system, which allows developers to handle unexpected events in a structured way. In this article, we'll…
This article presents an AutoHotkey (V1) script that detects when a USB drive is inserted or removed. It displays a pop-up dialog and makes a logfile entry in each case. It provides a system tray (notification area) icon with context menu choices to…
Next Video:

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month