<?php
class SignupController extends Zend_Controller_Action
{
function indexAction()
{
if ($this->_request->isPost())
{
echo "Your email address is: " . $this->_request->getPost('email');
}
$this->render("signup");
}
}
This is my controller
this is my view
<html>
<body>
<form action="/signup" method="post">
Email: <input name="email" type="text" />
<input name="btnSubmit" value="Click me" type="submit" />
</form>
</body>
</html>
when I tried to run the view
I am getting result
blank/signup
why this happens
please rectify that error, and tell me the reason for that error
If you are using signup view then replace your render code from this :-
$this->_helper->viewRenderer('signup');
Try it with else:
if ($this->_request->isPost()) {
echo "Your email address is: " . $this->_request->getPost('email');
} else {
$this->render("signup");
}
Related
I am new to CodeIgniter 3, I am trying to create a static page from this tutorial https://codeigniter.com/userguide3/tutorial/static_pages.html
http://localhost/index.php/pages/view It is work.
but my actual is like this C:\xampp\htdocs\application\views\pages
? (and not work)
why the folder is not /views/pages ?
I am getting confuse.
Also need help ! i am new to codeIgniter 3, I want to create a simple form, but they not work in the views
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
welcome.php
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
both added the controllers
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('welcome');
}
}
class Form extends CI_Controller {
public function index()
{
$this->load->view('form');
}
}
I tried these, but they not work.
You have not mentioned form action correctly. The form action should be look like this
action="<?php echo base_url(); ?>form"
and in the route.php add route for your action.
Example:
$route['form'] = 'form/index';
Then you can have $_POST values in your Form controller.
This is my view/login/loginform.php
<?php echo form_open('scheduler/login');
?>
<label for="username">username</label>
<input type="text" name="username"/><br/>
<label for="password">password</label>
<input type="password" name="password"></input><br/>
<input type="submit" name="submit" value="log in" />
</form>
This is my controllers/Scheduler.php
<?php
class Scheduler extends CI_Controller {
public function login()
{
$this->load->helper('form');
echo"not logged in";
$username=$this->input->post("username");
$password=$this->input->post("password");
if($username=="123" && $password="abc"){
$data['username']=$username;
$this->load->view('login/login_success_message',$data);
//$this->input->set_cookie('123','abc','15');
// redirect('home');
}
else {
$this->load->view('login/login_failure_message');
//$this->load->view('login/loginform');
}
}
}
?>
However, there is no form shown when I go the http://localhost/project/scheduler/login
//$this->load->view('login/loginform');
You are not loading the login form. So, Uncomment the above line
$this->load->view('login/loginform');
if the problem is still same then try to call $this->load->view('login/loginform');out side if else statement
Iam a newbie in Codeigniter , Iam learning it from watching videos , the instructor did the same what I did , But it gives me an error like this "The action you have requested is not allowed." ,and it worked with him, I don't know why, any help ! .
this is my Controller code
public function index(){
if($this->input->post('submit')){
echo $this->input->post('first_name');
}
$this->load->view('forms');
}
this is my View code
<form method="POST">
<input type="text" name="first_name" />
<input type="submit" name=submit" />
</form>
Use form_open() helper which automatically adds hidden input with CSRF value.
So your view should be:
<?php echo form_open('action_url'); ?>
<input type="text" name="first_name" />
<input type="submit" name=submit" />
<?php echo form_close(); ?>
Disabling CSRF protection also works but it's a bad idea.
you almost right, you need to add some parts like action in your form, and isset or empty in your controller like
class Test_form extends CI_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->load->view('form_test');
}
//using your example. good
public function check_form(){
if( isset($this->input->post('first_name', TRUE))){
echo "success <br>$$this->input->post('fisrt_name', TRUE)";
}
else{
echo "error";
}
}
//using form_validation. best
public function check_form_validation(){
$this->load->library('form_validation');
$this->form_validation->set_rules('first_name', 'first Name', 'trim|required|xss_clean');
if( ! $this->form_validation->run()){
echo "error <br>" . validation_errors();
}
else{
echo "success <br>$$this->input->post('fisrt_name', TRUE)";
}
}
}
form_test.php
first method
<form method="post" action="<?= base_url()?>index.php/test_form/check_form">
<input type="text" name="first_name">
<input type="submit" value="test">
</form>
<hr>
second method
<form method="post" action="<?= base_url()?>index.php/test_form/check_form_validation">
<input type="text" name="first_name">
<input type="submit" value="test">
</form>
I'm new to opencart. I have to write a custom Log-in form for users. Then i design a small code for log-in form in opencart like below. path is (MyTheme/temlate/auth/Sign.tpl)
<form action="<?php echo $Sub; ?>" method="GET" enctype="multipart/form-data">
Name:<Input type="text" name="txtUser">
<br>
Password:<input type="password" name="txtPassword"><br>
<input type="submit">
and controller is like (Path is controller/auth/Sign.php)
<?php
class ControllerAuthSign extends Controller{
public function index() {
$data['Sub']=$this->url->link('auth/result','','SSL');
if(file_exists(DIR_TEMPLATE . $this->config->get('config_template'). '/template/auth/sign.tpl')){
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/auth/sign.tpl',$data));
}
else{
$this->response->setOutput($this->load->view('default/template/account/login.tpl'));
}
}
}
?>
when a user submit the form have to navigate to Result page (Path is /auth/result.tpl)
<?php
echo "Welcome : Mr./Mrs. ".$User;
?>
<br><p>Your are Loged-In</p>
and the controller for Result is.. (Path is /auth/result.php)
<?php
class ControllerAuthResult extends Controller{
public function index() {
$data['User']=$_REQUEST['txtUser'];
$data['Password']=$_REQUEST['txtPassword'];
if(isset($data)){
$this->response->redirect($this->url->link('auth/sign', '', 'SSL'))
}
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/auth/result.tp',$data));
}
}
?>
but the problem is when i click on submit , page navigate to
http://localhost/opencart/index.php?txtUser=Narayana&txtPassword=narayana
and displayed index page. Can any one help how to navigate to result page...?
Thanks in Advance.
Use this
<form action="<?php echo $Sub; ?>" method="POST" enctype="multipart/form-data">
Name:<Input type="text" name="txtUser">
<br>
Password:<input type="password" name="txtPassword"><br>
<input type="submit">
my filename is contacts.php that have two submit buttons;i want that if insert button is pressed insert function is called and if select is pressed select is called.i have written following code:
//contacts.php
<?php
if(isset($_REQUEST['select']))
{
select();
}
else
{
insert();
}
?>
<html>
<body>
<form action="contacts.php">
<input type="text" name="txt"/>
<input type="submit" name="insert" value="insert" />
<input type="submit" name="select" value="select"/>
</form>
<?php
function select()
{
//do something
}
function insert()
{
//do something
}
?>
but it is not working .please help
<?php
if (isset($_REQUEST['insert'])) {
insert();
} elseif (isset($_REQUEST['select'])) {
select();
}
Your code is calling insert() even if no button is clicked, which will happen when the page is first displayed.
use post method because it is secure
//contacts.php
<?php
if(isset($_POST['select']))
{
select();
}
else
{
insert();
}
?>
<html>
<body>
<form action="contacts.php" method="post">
<input type="text" name="txt"/>
<input type="submit" name="insert" value="insert" />
<input type="submit" name="select" value="select"/>
</form>
<?php
function select()
{
//do something
}
function insert()
{
//do something
}
?>
If you are using return inside function to return the result , you have to use echo to print the result while calling function.
if(isset($_REQUEST['select']))
{
echo select();
}
elseif(isset($_REQUEST['insert']))
{
echo insert();
}
As has been described by several people (summarizing the previous comments), you have two options.
The first is to send the data via POST or GET to the server directly and reserve (refresh) the page based on whatever you do inside select() and insert().
While this is not the right place for a POST v GET discussion, convention is to use POST when sending data to the server. POST is slightly more secure because the information is not stored in the browser. Read more about the two here: http://www.w3schools.com/tags/ref_httpmethods.asp
The second option is to use AJAX to accomplish your task without refreshing the web page. In short, AJAX uses Javascript methods that you place on your page to communicate with your server, thus avoiding the need for the PHP on the server to actually change anything on the page (which would require a refresh). A code example of AJAX can be found here: http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first
<?php
$insert = $_POST['insert'];
$select = $_POST['select'];
if ($insert) {
insert();
}
if ($select) {
select();
}
else {
echo 'press any button...';
}
?>
<html>
<body>
<form action="contacts.php" method="post">
<input type="text" name="txt"/>
<input type="submit" name="insert" value="insert" />
<input type="submit" name="select" value="select"/>
</form>
<?php
function select() {
echo 'you pressed the [select] button';
exit;
}
function insert() {
echo 'you pressed the [insert] button';
exit;
}
?>