php提交表单验证不通过返回填写内容的相关问题
<?php/***registepage*/if(isset($_POST["submit"])){processForm();}else{displayForm(arr...
<?php
/**
* registe page
*/
if (isset($_POST["submit"])) {
processForm();
} else {
displayForm(array());
}
function setField($nameField) {
if (isset($_POST[$nameField])) {
echo $_POST[$nameField];
}
}
function processForm() {
$requiredFields = array('username', 'userpwd', 'userpwd2');
$missingFields = array();
foreach ($requiredFields as $requiedField) {
if (!isset($_POST[$requiedField]) or !$_POST[$requiedField]) {
$missingFields[] = $requiedField;
}
}
if ($missingFields) {
displayForm($missingFields);
} else {
displayThanks();
}
}
function displayForm($missingFields) {
echo "<h1>Register Page</h1><hr>";
if ($missingFields) {
echo "<h3>Sorry, there is some field for you to sign, please check it again</h3>";
} else {
echo "<h3>Welcome to register our party, you would be our member, just afer sign this message dowm...</h3>";
}
?>
<form action="" method="post">
<table>
<tr>
<td>用户名*:</td>
<td><input type="text" name="username" id="username" value="<?php setField("username")?>"></td>
</tr>
<tr>
<td>密 码 *:</td>
<td><input type="password" name="userpwd" id="userpwd" value=""></td>
</tr>
<tr>
<td>确 认 *:</td>
<td><input type="password" name="userpwd2" id="userpwd2" value=""></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="提交"></td>
</tr>
</table>
<?php
}
function displayThanks() {
echo "<h3>Thanks for resgisting our party...</h3>";
}
?>
现在问题是:我全部输入值了,却无法显示displayThanks()函数,我找不到原因了,希望phper帮我看下哪里错了,小弟也没分了,只要请求好心人帮助了,谢谢 展开
/**
* registe page
*/
if (isset($_POST["submit"])) {
processForm();
} else {
displayForm(array());
}
function setField($nameField) {
if (isset($_POST[$nameField])) {
echo $_POST[$nameField];
}
}
function processForm() {
$requiredFields = array('username', 'userpwd', 'userpwd2');
$missingFields = array();
foreach ($requiredFields as $requiedField) {
if (!isset($_POST[$requiedField]) or !$_POST[$requiedField]) {
$missingFields[] = $requiedField;
}
}
if ($missingFields) {
displayForm($missingFields);
} else {
displayThanks();
}
}
function displayForm($missingFields) {
echo "<h1>Register Page</h1><hr>";
if ($missingFields) {
echo "<h3>Sorry, there is some field for you to sign, please check it again</h3>";
} else {
echo "<h3>Welcome to register our party, you would be our member, just afer sign this message dowm...</h3>";
}
?>
<form action="" method="post">
<table>
<tr>
<td>用户名*:</td>
<td><input type="text" name="username" id="username" value="<?php setField("username")?>"></td>
</tr>
<tr>
<td>密 码 *:</td>
<td><input type="password" name="userpwd" id="userpwd" value=""></td>
</tr>
<tr>
<td>确 认 *:</td>
<td><input type="password" name="userpwd2" id="userpwd2" value=""></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="提交"></td>
</tr>
</table>
<?php
}
function displayThanks() {
echo "<h3>Thanks for resgisting our party...</h3>";
}
?>
现在问题是:我全部输入值了,却无法显示displayThanks()函数,我找不到原因了,希望phper帮我看下哪里错了,小弟也没分了,只要请求好心人帮助了,谢谢 展开
展开全部
/*将以下代码*/
foreach ($requiredFields as $requiedField) {
if (!isset($_POST[$requiedField]) or !$_POST[$requiedField]) {
$missingFields[] = $requiedField;
}
}
if ($missingFields) {
displayForm($missingFields);
} else {
displayThanks();
}
/*---------------------------------------------------------------*/
改写成:
foreach ($requiredFields as $key => $value) {
if (empty($value)) {
$missingFields[] = $key;
}
}
if (count($missingFields)>0) {
displayForm($missingFields);
} else {
displayThanks();
}
foreach ($requiredFields as $requiedField) {
if (!isset($_POST[$requiedField]) or !$_POST[$requiedField]) {
$missingFields[] = $requiedField;
}
}
if ($missingFields) {
displayForm($missingFields);
} else {
displayThanks();
}
/*---------------------------------------------------------------*/
改写成:
foreach ($requiredFields as $key => $value) {
if (empty($value)) {
$missingFields[] = $key;
}
}
if (count($missingFields)>0) {
displayForm($missingFields);
} else {
displayThanks();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你写的这是什么呀,....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询