Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/12/2021 in all areas

  1. Hmm! Method A or method B? When you are caught on the horns of a dilemma, look for a third way Consider a sticky registration form. When first loaded the input values are blank, but if the validation fails you want to show the user's values. In this situation I like the "null coalesce" operator, ie "??". Example <?php $fname = $_POST['fname'] ?? ''; $lname = $_POST['lname'] ?? ''; $email = $_POST['email'] ?? ''; $mobile = $_POST['mobile'] ?? ''; $error_message = ''; if ($_SERVER['REQUEST_METHOD']=='POST') { $errors = []; // array for any error messages // validate input here if (!$errors) { // update database here header("location: thispage.php"); // reload page exit; } else { $error_message = 'yada yada'; } } ?> <html> <body> <form method='POST'> First name : <input type='text' name='fname' value='<?=$fname?>'> <br> Last name : <input type='text' name='lname' value='<?=$lname?>'> <br> Email : <input type='text' name='email' value='<?=$email?>'> <br> Mobile : <input type='text' name='mobile' value='<?=$mobile?>'> <br> <br> <button type='submit'>Submit</button> </form> <?=$error_message?> </body> </html>
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.