开发者

Display error message at top of form

开发者 https://www.devze.com 2023-02-04 18:52 出处:网络
I\'m trying to get the following erro开发者_Python百科r to show when some once presses the submit button and has not filled in the required field/s.<?php

I'm trying to get the following erro开发者_Python百科r to show when some once presses the submit button and has not filled in the required field/s.


<?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); //Why exacly do you need to have extra stuff?
        }
    }
    //iterate over the missing elements, and display them
    foreach ($missing as $m){
        echo echo "<strong>Error: </strong>: " . $validation[$m] . "<br>";
    }
    //You need to do some more stuffs, like query the DB to check if the username is a duplicate or not.
}
//...rest of your code ..
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号