Last active
September 13, 2024 20:24
-
-
Save ConnorFM/505bef68fd1fefca1073ae9d1c0d330b to your computer and use it in GitHub Desktop.
Contact Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | |
<title>Hello, world!</title> | |
</head> | |
<body> | |
<?php | |
include ('test.php'); | |
?> | |
<h3>All fields are required</h3> | |
<br /><br /> | |
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post"> | |
<div class="form-group"> | |
<label for="name">Last Name</label> | |
<input type="text" class="form-control" id="lastName" placeholder="Name" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$" required="required" name="user_name"><span class="error">* <?php echo $nameErr;?></span> | |
</div> | |
<div class="form-group"> | |
<label for="firstName">First Name</label> | |
<input type="text" class="form-control" id="firstName" placeholder="First Name" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$" required="required" name="firstName"><span class="error">* <?php echo $firstnameErr;?></span> | |
</div> | |
<div class="form-group"> | |
<label for="phone">Phone Number</label> | |
<input type="tel" class="form-control" id="phone" placeholder="+33612131415" pattern="^(?:0|\(?\+33\)?\s?|0033\s?)[1-79](?:[\.\-\s]?\d\d){4}$" required="required" name="phone"><span class="error">* <?php echo $phoneErr;?></span> | |
</div> | |
<div class="form-group"> | |
<label for="mail">Email address</label> | |
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="[email protected]" required="required" name="user_mail"><span class="error">* <?php echo $emailErr;?></span> | |
</div> | |
<div class="form-group"> | |
<label for="exampleFormControlSelect1">My Problem?</label> | |
<select class="form-control" id="exampleFormControlSelect1" required="required"> | |
<option>Algorythm problems</option> | |
<option>PHP problems</option> | |
<option>HTML problems</option> | |
</select> | |
</div> | |
<div class="form-group"> | |
<label for="message">My message</label> | |
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" required="required" name="user_message"></textarea><span class="error">* <?php echo $commentErr;?></span> | |
</div> | |
<button type="submit" class="btn btn-primary">Submit</button> | |
</form> | |
<?php | |
if($nameErr ==''&& $firstnameErr ==''&& $emailErr ==''&& $phoneErr ==''&& $commentErr =='' && !empty($_POST)){ | |
header("Location:https://www.youtube.com/watch?v=5eLcHJLDlI8"); | |
exit; | |
} | |
?> | |
<!-- Optional JavaScript --> | |
<!-- jQuery first, then Popper.js, then Bootstrap JS --> | |
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
</head> | |
<body> | |
<?php | |
// define variables and set to empty values | |
$nameErr = $emailErr = $firstnameErr = $phoneErr = $commentErr = ""; | |
$name = $email = $firstName = $comment = $phone = ""; | |
function test_input($data) { | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
if ($_SERVER["REQUEST_METHOD"] == "POST") { | |
if (empty($_POST["user_name"])) { | |
$nameErr = "Name is required"; | |
} else { | |
$name = test_input($_POST["user_name"]); | |
if (!preg_match("/^[a-zA-Z ]*$/",$name)) { | |
$nameErr = "Only letters and white space allowed"; | |
} | |
} | |
if (empty($_POST["firstName"])) { | |
$firstnameErr = "First name is required"; | |
} else { | |
$firstName = test_input($_POST["firstName"]); | |
} | |
if (empty($_POST["user_mail"])) { | |
$emailErr = "Email is required"; | |
} else { | |
$email = test_input($_POST["user_mail"]); | |
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
$emailErr = "Invalid email format"; | |
} | |
} | |
if (empty($_POST["phone"])) { | |
$phoneErr = "Phone number is required"; | |
} else { | |
$phone = test_input($_POST["phone"]); | |
} | |
if (empty($_POST["user_message"])) { | |
$commentErr = "Post a message"; | |
} else { | |
$comment = test_input($_POST["user_message"]); | |
} | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment