您是否在 form_validation 之后发布输入值?

发布于 2024-11-05 23:37:21 字数 209 浏览 1 评论 0原文

Codeigniter 问题:

我刚刚使用 $this->form_validation->set_rules(etc 等) 设置了我的第一个表单,在验证运行正确后,我应该使用 $email = $this->input->; 发布值吗?发布('电子邮件',TRUE);或者表单验证是否已经发布了值?如果是这样 - 我如何返回这些值?

谢谢, 沃克

Codeigniter question:

I've just setup my first form with $this->form_validation->set_rules(etc etc), after the validation runs corrects should I post the values using $email = $this->input->post('email', TRUE); or is did the form validation already post the values? If so - how do I return those values?

Thanks,
walker

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

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

发布评论

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

评论(3

风筝有风,海豚有海 2024-11-12 23:37:21

执行验证后,这些值仍然存在于 $_POST 数组中,因此根据您的应用和您的需求,您可能需要也可能不需要将它们分配给变量。

延伸-
如果您要进行进一步处理,那么建议执行 $email = $this->input->post('email');,但您同样可以通过例如,将整个 $_POST 数组发送到模型,而无需执行任何额外的输入 -

$this->my_model->do_something($this->input->post())

当然取决于你的要求。

After your validation is performed, the values still exist in the $_POST array, so depending on your app and your needs, you may or may not need to assign them to variables.

To extend -
If you are going to do further processing, then it would be advisable to do $email = $this->input->post('email');, but you could equally just pass the entire $_POST array to a model, for instance, without having to do any extra typing -

$this->my_model->do_something($this->input->post())

Depending on your requirements of course.

余罪 2024-11-12 23:37:21

input->post 表示 PHP 中 $_POST 超全局数组中的内容。这是在 Codeigniter 对脚本执行任何操作之前设置的 - 这也意味着 Codeigniter 从 $_POST 填充 input->post 。因此,当您“发布”值时,您只需提交一个方法设置为 POST 的表单。有道理吗?

从那里 CI_Controller 类处理其余的事情,并且您应该能够在验证之前、期间或之后的任何时间访问 input->post 。

input->post means whatever is in the $_POST superglobal array in PHP. This is set before Codeigniter does anything with your script - and it also means Codeigniter populates input->post from $_POST. So when you "post" values, you're simply submitting a form with the method set to POST. Make sense?

From there the CI_Controller class handles the rest, and you should be able to access input->post at any time before, during or after validation.

谎言 2024-11-12 23:37:21

是的你是对的。

您希望使用以下语法检索发布值:

处理表单中更新数据的一种简单方法是:

// the if syntax is incorrect, i forget the exact wording
if ($this->form->valid()){
   $updateData = array(
      'email' => $this->input->post('email'),
      'username' => $this->input->post('username'),
      'password' => $this->input->post('password')
   );
   // check uniqueness of email
   $this->db->where('email', $updateData['email']);
   $uniqueQuery = $this->db->get('accounts');
   if ($uniqueQuery->num_rows() == 0){
       $this->db->insert('accounts', $updateData);
   }
}

Yes -- you are right.

Yout want to retrieve post values with the following syntax:

An easy way to handle update data from a form would be:

// the if syntax is incorrect, i forget the exact wording
if ($this->form->valid()){
   $updateData = array(
      'email' => $this->input->post('email'),
      'username' => $this->input->post('username'),
      'password' => $this->input->post('password')
   );
   // check uniqueness of email
   $this->db->where('email', $updateData['email']);
   $uniqueQuery = $this->db->get('accounts');
   if ($uniqueQuery->num_rows() == 0){
       $this->db->insert('accounts', $updateData);
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文