Display error message at top of form
- by moustafa
Hello,
I'm trying to get the following error to show when some once presses the submit button and has not filled in the required field/s.
My PHP code is.
<?php
require_once("includes/database.php");
require_once("includes/functions.php");
if(isset($_POST['full_name'])) {
$required = array('full_name','user_name','email','pwd','pwd2');
$missing = array();
$validation = array(
'full_name' => 'Please provide your full name',
'user_name' => 'Please provide your username',
'email' => 'Please provide your valid email address',
'pwd' => 'Please provide your password',
'pwd2' => 'Please confirm your password',
'userdup' => 'Username already registered',
'emaildup' => 'Email address already registered',
'mismatch' => 'Passwords do not match'
);
//Sanitise and clean function
$full_name = escape($_POST['full_name']);
$user_name = escape($_POST['user_name']);
$email = escape($_POST['email']);
$pwd = escape($_POST['pwd']);
$pwd2 = escape($_POST['pwd2']);
foreach($_POST as $key => $value) {
$value = trim($value);
if(empty($value) && in_array($key,$required)) {
array_push($missing,$key);
} else {
${$key} = escape($value);
}
}