我想知道如何将下面 index.php 中的 my_name 值发送到 result.php。
下面是输入表单后检查错误的php代码。以及如何将没有错误的表单结果发送到 result.php
这是 index.php
<?php
if ($_POST["_submit_check"]) {
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
process_form();
}
} else {
show_form();
}
function process_form() {
//if doesnt makes error
//i want to send result "my_name" to result.php
header('Location: result.php');
}
function show_form($errors = '') {
if ($errors) {
print implode('</li><li><br>', $errors);
print '</li></ul>';
}
print<<<_HTML_
<form method="POST" action="$_SERVER[PHP_SELF]">
Your name: <input type="text" name="my_name">$errors[0];
<br/>
<input type="submit" value="Submit">
<input type="hidden" name="_submit_check" value="1">
</form>
_HTML_;
}
function validate_form() {
$errors = array();
if (strlen($_POST['my_name']) < 3) {
$errors[] = "Your name must be at least 3 letters long.";
}
return $errors;
}
?>
这是结果.php
<?php
//prints result form from index.php
?>