In: Computer Science
log in form
Requirements:
//code to adjust
//code
<?php
if(isset($_GET['submit'])){
//sanitize the input
/* Check the error from the input:
if input from user is empty
-> get an error string variable
if input is not empty
-> use preg_match() to match the pattern
$pattern = "/^[1-9][0-9]{2}(\.|\-)[0-9]{3}(\.|\-)[0-9]{4}$/";
-> if it's a matched, get a success string variable
*/
}
?>
<!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.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous">
<link rel="stylesheet" href="">
<title>Lab 2-Part1</title>
</head>
<body>
<form action="" class="main-form
needs-validation">
<div class="form-group">
<label for="numbers">Phone Number</label>
<input type="text" id="numbers" class="form-control"
value=<?php //use PHP to print out the value the use typed in if
any ?>>
<small class="form-text text-muted">xxx.xxx.xxx or
xxx-xxx-xxxx</small>
<!-- Set a condition
if there is an error string variable, print out the string in
PHP
if there is a success string variable, print out the string in
PHP
-->
<div class="alert
alert-danger">
Must enter a valid
phone number! <!-- should be from an error string variable
-->
</div>
<div class="alert
alert-success">
Phone number is valid!
<!-- should be from an error string variable -->
</div>
</div>
<button type="submit" class="btn btn-primary"
>Submit</button>
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS
-->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
</body>
</html>
Here is the answer for your question in PHP and HTML Languages.
Kindly upvote if you find the answer helpful.
#####################################################################
CODE :
loginForm.php
<?php <!-- Bootstrap CSS --> <form action="<?php echo
$_SERVER['PHP_SELF'];?>" class="main-form needs-validation"
method="GET"> <!-- Optional JavaScript --> |
#########################################################################
welcome.html
<!DOCTYPE html> <html> <head> <title>WELCOME PAGE</title> </head> <body> <center> <h1 style="color:green;">Congratulations</h1> <h1 style="color:yellow;">Logged In successfullt</h1> </center> </body> </html> |
#################################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
loginForm.php
###########################################################################
welcome.html
############################################################################
OUTPUT :
Initially the page looks like,
When you give any username and password but empty phone number,
when you click "submit",
When you give any user name and password but invalid Phone number,
Whe you click on "submit",
Whe you give valid phone number but invalid username and passwords.
An alert message wil be displayed
Given all valid values,(Please check the arrays in code to enter valid values)
Redirected to welcome.html page,
Any doubts regarding this can be explained with pleasure :)