php表单中,服务器端验证失败,需要检索输入的表单数据进行显示

发布于 2024-12-23 03:49:01 字数 239 浏览 2 评论 0原文

我有两种形式,第一种形式的数据被发送到第二种形式。

在将第一个表单数据发送到第二个表单之前,它会在服务器上进行验证。

第一个表单数据包含大量信息,因此在验证失败时,用户需要因为一个小错误而重新输入所有数据。

那么,是否有任何解决方案可以在表单中预先填写验证失败的数据,以便用户轻松填写缺失的数据呢?

我在 ZEND 框架和 MVC 架构中使用 PHP 和 MySQL,但无法使用 Zend_Form。

I have two forms where the data from the first is being sent to the second.

Before the first form data is sent to the second form it is validated on the server.

The first form data consists of a lot of information, so on validation failure, the user needs to enter all the data back again because of a small mistake.

So, is there any solution to pre-fill the form with data on validation failure, so that it makes user comfortable to just fill in the missing data?

Im using PHP with MySQL in ZEND framework and MVC architecture, but I am unable to use Zend_Form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻安 2024-12-30 03:49:01

如果您使用 Zend_Form 类,则在表单中出现失败的发布请求后,所有数据都应自动填充。下面的示例代码:

$form = new CLASS_EXTENDING_ZEND_FORM;

if($this->getRequest()->isPost()) {
    if($form->isValid($this->getRequest()->getPost()) {
    }
}

$this->view->form = $form;

If you use a Zend_Form class all data should automatically populated after post request with failures in form. Below example code:

$form = new CLASS_EXTENDING_ZEND_FORM;

if($this->getRequest()->isPost()) {
    if($form->isValid($this->getRequest()->getPost()) {
    }
}

$this->view->form = $form;
寄与心 2024-12-30 03:49:01
<?php
// your input will validate in the php in your own code then....
$good = 1;
foreach($_POST as $k => $v){
$k = $v; // this will create variables for your submitted names to post back
if($k==''){$k = "needs an entry";$good=0;}
}

if(!$good){
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type=text name=demofieldname value='<?php echo $demofieldname ?>'>
- etc- 
</form>


<?php
}else{

//finish processing
}
?>

这是一个简单的方法。还有其他方法可能与您现有的代码更加集成,并且取决于您的会话管理,好吧,如果您以向导方式等继续进行购买篮安排,事情可能会变得更加复杂。

请记住 - 这在这里很简单,如果您使用数据库,那么相关查询可能会更复杂。

===编辑注释
将 if($k=='') 更改为 if($$k=='')

<?php
// your input will validate in the php in your own code then....
$good = 1;
foreach($_POST as $k => $v){
$k = $v; // this will create variables for your submitted names to post back
if($k==''){$k = "needs an entry";$good=0;}
}

if(!$good){
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type=text name=demofieldname value='<?php echo $demofieldname ?>'>
- etc- 
</form>


<?php
}else{

//finish processing
}
?>

this is a simple method. there are other ways that may be more integrative with your exisiting code and depending on your session management, well, if you are continuing a purchase basket arrangement as in a wizard fashion etc, things can get more complex.

bear in mind - this is simple here and if you have db use then it can be more complicated regarding related queries.

===EDIT NOTE
changed if($k=='') to if($$k=='')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文