PHP Forms

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function lintUserNameFor($stringName, &$hasError) {
$name = test_input($stringName);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
$hasError = true;
echo $nameErr;
}
}
function lintEmailFor($stringEmail, &$hasError) {
$email = test_input($stringEmail);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
$hasError = true;
echo "<h1>" . $emailErr . "</h1>";
}
}
function lintURL($url, &$hasError) {
$website = test_input($_POST["website"]);
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
$websiteErr = "Invalid URL";
$hasError = true;
}
}
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<input type="text" name="email" value="<?
echo $_POST['editthis'] ? $_POST['email'] : $email;
?>">

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store