【问题标题】:How to get posted value from different function?如何从不同的功能中获取发布的价值?
【发布时间】:2016-10-12 04:48:03
【问题描述】:

我正在使用 codeigniter 3.1。

从不同功能提交数据后如何返回或获取已发布的电子邮件?

HTML

<form action="settings/valid" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8">
    <input type="email" name="email" value="<?php echo $email ?>" />
    <input type="submit"/>
</form>

PHP

public function index() {
    // how to get post email ? 
   $email = $this->input->post("email"));

   $this->template->loadContent("settings/index.php", array(
    "email" => $email
    )
    );

}

public function valid() {
    $email = $this->input->post("email"));

    $this->user->add($this->user->ID, array(
        "email" => $email
    ));

    redirect(site_url("index.php"));

}

【问题讨论】:

标签: php codeigniter


【解决方案1】:

这可能会更好地回答您的问题。

public function index() {
    // how to get post email ? 
   $email = $this->session->flashdata("email");

   $this->template->loadContent("settings/index.php", array(
    "email" => $email
    )
    );

}

public function valid() {
    $email = $this->input->post("email"));

    $this->user->add($this->user->ID, array(
        "email" => $email
    ));

    $this->session->set_flashdata("email",$email);

    redirect(site_url("index.php"));

}

【讨论】:

【解决方案2】:

您所做的称为路由。这意味着在索引中获取电子邮件是没有意义的,因为没有数据被发送到索引。您可以做的是将用户重定向到索引并将 post 参数传递给索引。

换一种说法。假设您打开一个网页并为其命名。你不能指望另一个页面也知道你的名字,因为那个页面还不存在(它还没有由 php 生成)。

但是您可以将用户发送到另一个页面并告诉该页面用户的姓名。

例如,在您的情况下:

valid()

redirect(site_url("index.php?email=".$email));

index()

$email = $this->input->get("email")

【讨论】:

  • 什么时候调用索引?
  • http://localhost/settings/index 和发布网址 http://localhost/settings/valid 。发布后返回索引。
  • Hyy 工作,但有什么方法可以从 url 隐藏已发布的电子邮件?
  • 我添加了另一个答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-03
相关资源
最近更新 更多