Sending HTML form data to PHP

myForm.html

<!DOCTYPE HTML> 
<html>
<head>
<link rel="stylesheet" type="text/css" href="form.css"/>
<script>
function msg()
{
alert("Hello world!");
}
</script>
</head>
<body>
<form class="myForm" method="post" action="processForm.php">
	<fieldset>
	<legend>My Form:</legend>
   	<label>text</label><input type="text" name="textinput"><br>
   	<label>password</label><input type="password" name="pwd"><br>
   	<label>radio</label>
   	<input type="radio" name="gender" value="male">Male
	<input type="radio" name="gender" value="female">Female<br>
	
	<label>checkbox</label>
	<input type="checkbox" name="planguage[]" value="cpp">C++
	<input type="checkbox" name="planguage[]" value="java">Java
	<input type="checkbox" name="planguage[]" value="php">PHP
	<input type="checkbox" name="plagnuage[]" value="javascript">Javascript<br>

	<label>dropdown menu</label>
	<select name="nyc">
		<option value="bronx">Bronx</option>
		<option value="brooklyn">Brooklyn</option>
		<option value="manhattan">Manhattan</option>
		<option value="queens">Queens</option>
		<option value="statenisland">Staten Island</option>
	</select><br>
	
	
	<label>button</label>
	<input type="button" value="Hello world!" onclick="msg()"><br>
	
	<label>color</label>
	<input type="color" name="favcolor"><br>
	
	<label>date</label>
	<input type="date" name="bday"><br>
	
	<label>datetime</label>
	<input type="datetime-local" name="bdaytime"><br>
	
	<label>time</label>
	<input type="time" name="usr_time"><br>
	
	<label>week</label>
	<input type="week" name="year_week"><br>
	
	<label>month</label>
	<input type="month" name="bdaymonth"><br>
	
	<label>number</label>
	<input type="number" name="quantity" min="1" max="10"><br>
	
	<label>range</label>
	<input type="range" name="points" min="1" max="10"><br>
	
	
	<label>email</label>
	<input type="email" name="usremail"><br>
	
	<label>url</label>
	<input type="url" name="webaddress"><br>
	
	<label>image</label>
	<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48"><br>
	
	<label>text area</label>
	<textarea name="message" rows="10" cols="30">
	</textarea><br>
	
	<label>file attachment</label>
    <input type="file" name="attach1" id="attach1" /><br>
    
   	<label>reset</label>
   	<input type="reset" value="Reset"><br>
   	
   	<label>submit</label>
   	<input type="submit" name="submit" value="Submit">
   	</fieldset>
</form>
</body>
</html>

form.css

.myForm
{
    font-family: Verdana, Arial, sans-serif;
    width:550px;
}
.myForm label
{
    float: left;
    text-align: right;
    margin-right: 15px;
    width: 150px;
    height: 20px;
    padding-top: 5px;
}
.myForm input{
    height:20px;
    margin: 5px 0px 10px 0px;
    font-family: Helvetica, sans-serif;
}
.myForm select{
    height:25px;
    margin: 5px 0px 10px 0px;
    font-family: Helvetica, sans-serif;
}

processForm.php

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
	echo "<h2>Your Input:</h2>";
	echo "<strong>text:</strong> ".filterInput($_POST["textinput"])."<br>";
	echo "<strong>gender:</strong> ".filterInput($_POST["gender"])."<br>";
	echo "<strong>planguage:</strong> ";
	foreach($_POST["planguage"] as $language){echo filterInput($language)." ";}
	echo "<br>";
	echo "<strong>nyc borough:</strong> ".filterInput($_POST["nyc"])."<br>";
	echo "<strong>color:</strong> ".filterInput($_POST["favcolor"])."<br>";
	echo "<strong>birth date:</strong> ".filterInput($_POST["bday"])."<br>";
	echo "<strong>datetime:</strong> ".filterInput($_POST["bdaytime"])."<br>";
	echo "<strong>time:</strong> ".filterInput($_POST["usr_time"])."<br>";
	echo "<strong>week:</strong> ".filterInput($_POST["year_week"])."<br>";
	echo "<strong>month:</strong> ".filterInput($_POST["bdaymonth"])."<br>";
	echo "<strong>quantity:</strong> ".filterInput($_POST["quantity"])."<br>";
	echo "<strong>range:</strong> ".filterInput($_POST["points"])."<br>";
	echo "<strong>email:</strong> ".filterInput($_POST["usremail"])."<br>";
	echo "<strong>url:</strong> ".filterInput($_POST["webaddress"])."<br>";
	echo "<strong>message:</strong> ".filterInput($_POST["message"])."<br>";
}

function filterInput($data)
{
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
}

Search within Codexpedia

Custom Search

Search the entire web

Custom Search