10c06-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 45 行
PHP
45 行
<?php// An array of our required elements, and their real names:$required = array('phone' => 'Phone Number', 'state' => 'State');// If we had a POST, then check the data:if (count($_POST)) { $errors = ''; // Loop over all required fields, and ensure they exist: foreach ($required as $field => $desc) { // If it is not even set, or is blank after trimming: if (!isset($_POST[$field]) || (trim($_POST[$field]) === '')) { $errors .= "<br />{$desc} is a required field!\n"; } } // If we had any errors, echo them out now: if ($errors) { echo "<p style=\"color: red\">The following errors were found:{$errors}</p>\n"; } else { // Here, if this were a real program, you would save your data or // do whatever else you would normally do with it. Probably // redirecting to a different page afterwards. }}// Create our form autopopulating the POST variables back into place if// they exist. Using @ to hide errors if they didn't exist.?><form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="f1"><p>Please enter your contact information:</p><p>Name:<input name="name" type="text" value="<?= @$_POST['name'] ?>" /></p><p>Phone:<input name="phone" type="text" value="<?= @$_POST['phone'] ?>" /></p><p>Email:<input name="email" type="text" value="<?= @$_POST['email'] ?>" /></p><p>Address:<input name="address" type="text" value="<?= @$_POST['address'] ?>" /></p><p>City:<input name="city" type="text" value="<?= @$_POST['city'] ?>" /></p><p>State:<input name="state" type="text" value="<?= @$_POST['state'] ?>" /></p><p><input type="submit" /></p></form>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?