Reputation: 141
I am using codeigniter 3.1 .
How to return or get posted email after submit data from different function?
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"));
}
Upvotes: 0
Views: 67
Reputation:
This may answer your question better.
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"));
}
Upvotes: 1
Reputation:
What you are doing is called routing. That means that it makes no sense to get the email in index, because no data has been sent to index. What you can do is redirect the user to index and pass a post argument to index.
To put it another way. Let's say you open a web page and give it your name. You cannot expect another page to know your name as well, because that page does not exist yet (it has not been generated yet by php).
But you can send the user to another page and tell that page the user's name.
For instance, in your case:
in valid()
redirect(site_url("index.php?email=".$email));
and in index()
$email = $this->input->get("email")
Upvotes: 1