gpt4 book ai didi

php - CakePHP问题: How can i check whether there is an empty field or not after submitting form?

转载 作者:行者123 更新时间:2023-11-29 14:43:53 24 4
gpt4 key购买 nike

假设电子邮件字段为空。

  Array
(
[Comment] => Array
(
[post_id] => 10
[name] => name6
[email] =>
[body] => body6
)

)

这是添加操作。

function add($id) {
$temp = $this->data;
debug($temp);

if (!empty($this->data)) {
$this->Comment->create();
if ($this->Comment->save($this->data)) {
$this->Session->setFlash('Your comment has been saved.');
$this->redirect(array('controller'=>'posts','action' => 'index'));
}
}
}

现在我如何检查电子邮件字段是否为空。如果任何字段为空,那么它将显示消息并重定向到另一个操作。

最佳答案

function add($id) {

if(!isset($this->data['Comment'][email]))
{
$this->Session->setFlash('Email is empty. Please try again !!');
$this->redirect(array('controller'=>'posts','action' => 'index'));

}

您的添加代码位于此处...

但我建议您将所有验证放入各自的模型中。

关于php - CakePHP问题: How can i check whether there is an empty field or not after submitting form?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7401638/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com