Welcome Guest, Not a member yet? Register   Sign In
Form Error on Post
#1

[eluser]juggernautsei[/eluser]
I am trying to create a simple basic form that will post to itself. However when I click the submit button I get the

An Error Was Encountered
The asction you have requested is not allowed.

I can't find anything in the documentation that would help me trouble shoot this code error.

I was expecting just to simply have the form post and display what I put in the box.

Action is left blank so that it post back to itself but I have also tried to put in

echo base_url('index.php/childtest/search') and I still receive the same error message.

Thanks for the help.

controller Code
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

         session_start(); //we need to call PHP's session object to access it through CI
class ChildTest extends CI_Controller {
  
  
  public function search(){
  
   $this->load->helper('form');
   $keyword = $this->input->post('keyword');
  
   echo $keyword;
  
     $this->load->view('childsearch');  
  
  
  }
  
}

View Code:

Code:
<div id="search">
          &lt;form id="search" method = "post" acti&gt;
              <label id="familyname">Child Family Name</label>
              &lt;input type="text" size="20" id="keyword" name="keyword"/&gt;
              &lt;input type="submit" value="Search" /&gt;          
          &lt;/form&gt;
          
        </div>
#2

[eluser]joergy[/eluser]
The Error is typical for a failure due to "Cross-site request forgery (CSRF)". See Security Class for details.
But I'm not sure if this is the reason. On a first glance I don't see an error but that one:

echo $keyword;
$this->load->view('childsearch');

You can't successfully load a view AFTER You've made some output with echo.
#3

[eluser]juggernautsei[/eluser]
So I was doing some more research trying to find my particular error.

I read this post on StackOverFlow.com http://stackoverflow.com/questions/20086...niter?rq=1

So I changed my controller code to this:

Code:
class ChildTest extends CI_Controller {
  
  public function index(){
  
   $this->search();
  
  }
  public function search(){
  
   $this->load->helper('form');
   $this->load->library('form_validation');
    
   $this->form_validation->set_rules(array(
     array(
       'field' => 'keyword',
       'label' => 'Child Family Name',
       'rules' => 'required',
     )
   ));
   $this->form_validation->set_error_delimiters('<div class="alert alert-error">', '</div>');
    
   if(!$this->form_validation->run()){
              $this->load->view('childsearch');  
   }else{
    $keyword = $this->input->post('keyword');
         echo $keyword;
   }
  
    }
    }

So now I am calling the search function form the index method I believe and not directly.

But I still get the same error message

An Error Was Encountered

The action you have requested is not allowed.

Still trying to figure out what action is not allowed. Not a very descriptive error message.




Theme © iAndrew 2016 - Forum software by © MyBB