Skip to content

Instantly share code, notes, and snippets.

@KalobTaulien
Last active January 13, 2019 16:10
Show Gist options
  • Save KalobTaulien/255fdafb7c2fb2db78aad6c49bb05bba to your computer and use it in GitHub Desktop.
Save KalobTaulien/255fdafb7c2fb2db78aad6c49bb05bba to your computer and use it in GitHub Desktop.
<?php
$name = (isset($_POST['name']) ? $_POST['name'] : '');
$email = (isset($_POST['email']) ? $_POST['email'] : '');
$password = (isset($_POST['password']) ? $_POST['password'] : '');
$notification = ''
if( ! empty ( $name ) && !empty ( $email ) && ! empty( $password) ) {
$notification = "<div class='alert alert-success' role='alert'>
<h4 class='alert-heading'>Well done!</h4>
<p>Aww yeah, you have successfully signed up and following are your details.</p> <hr>
<p class='mb-0'>Name: <strong>$name</strong></p>
<p class='mb-0'>Email: <strong>$email</strong> </p>
<p class='mb-0'>Password: <strong>$password</strong> </p>
</div>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Project</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- container -->
<div class="container">
<!-- top area row -->
<div class="row title">
<div class="col-12">
<h1 class="text-center">PHP For Everybody &dash; Final Project</h1>
</div>
</div>
<hr>
<div class="row sign-up">
<div class="col-12">
<h3 class="text-center">Sign Up</h3>
</div>
</div>
<!-- /.row -->
<!-- form -->
<div class="row form">
<div class="col-8 offset-3">
<form action="index.php" method="POST">
<div class="form-group">
<label for="name" class="col-2">Name:</label>
<input type="text" value="<?php echo $name; ?>" name="name" id="name" placeholder="Enter your name" class="col-6 form-controls">
<?php if ( isset( $_POST["name"]) && empty( $_POST["name"]) ) {
echo "<div class='col-6 offset-2 alert alert-danger' role='alert'>Missing your name </div>";
} ?>
</div>
<div class="form-group">
<label for="email" class="col-2">Email:</label>
<input type="email" name="email" value="<?php echo $email; ?>" id="email" placeholder="Enter your email" class="col-6 form-controls">
<?php if ( isset( $_POST["email"]) && empty( $_POST["email"]) ) {
echo "<div class='col-6 offset-2 alert alert-danger' role='alert'>Missing your email </div>";
} ?>
</div>
<div class="form-group">
<label for="password" class="col-2">Password:</label>
<input type="password" name="password" id="password" placeholder="Set your password" class="col-6 form-controls">
<?php if ( isset( $_POST["password"]) && empty( $_POST["password"]) ) {
echo "<div class='col-6 offset-2 alert alert-danger' role='alert'>Missing your password </div>";
} ?>
</div>
<div class="form-group">
<input type="submit" value="Submit" name="submit" class="offset-2 form-controls btn btn-info">
</div>
<div class="form-group">
<div class="col-8">
<?php ?>
</div>
</div>
</form>
<div class="col-8 offset-1">
<?php echo $notification(); ?>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</body>
</html>
@KalobTaulien
Copy link
Author

I removed the function to allow variables to be in the global scope.

The function would be more necessary if the function needed to run 2 or more times.

Note: This code is untested. May have typos. ¯_(ツ)_/¯

@Abd-Ur-Rehman
Copy link

I got it. Thank you @KalobTaulien 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment