PHP
×

Notice

JW_PLG_SIG_NOTICE_02

PHP Function

<?php

function get_input_value($field, $errorMessage = null, $trimInput = true) {
    return
    (
            ( isset ($_GET[$field]) ) ?
                (   ($trimInput)  ?
                    ((trim($_GET[$field] ) == "") ?
                        $errorMessage
                    :
                        $_GET[$field]
                    )
                : (($_GET[$field]  == "") ?
                    $errorMessage
                :
                    $_GET[$field]
                ))
        :
            ((isset($_POST[$field])) ?
                (    ($trimInput) ? 
                    ((trim($_POST[$field]) == "") ? $errorMessage : $_POST[$field])
                :
                    (($_POST[$field] == "") ? $errorMessage : $_POST[$field]))
            :
                $errorMessage)
    );
}

?>

Usage

<html>
<head>
    <title>
        Hello <?=get_input_value("name", "Guest")?>
    </title>
</head>
<body>
    Post:
    <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
        Name
        <input type="text" name="name" id="name" value="<?=get_input_value("name", "Guest", false)?>" />
        <input type="submit" />
    </form>
    <hr />
    Get:
    <form method="get" action="<?=$_SERVER['PHP_SELF']?>">
        Name
        <input type="text" name="name" id="name" value="<?=get_input_value("name", "Guest", false)?>" />
        <input type="submit" />
    </form>
    <hr />

    <?php
    if (get_input_value("name",null,false) != null  ) {
        printf ("Hello \"%s\"", get_input_value("name", "Guest", false));
    }
    ?>

</body>
</html>