• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An Error Was Encountered

#1
I wrote the below code for form validation. When a mandatory field is not entered then is shows proper message, but when I press F5 and resubmit my form then I get error "An Error Was Encountered - The action you have requested is not allowed.". How shall I remove this error? Below is my code. Thank you In advance

View:
Code:
<?php
                   $argument = array(
                                       'role'      =>  'form',
                                       'class'     =>  'form-horizontal form-groups-bordered',
                                       'method'    =>  'POST',
                                       'enctype'   =>  'multipart/form-data'
                                   );
                   echo form_open(base_url().'admin/add_department',$argument);
               ?>
                   <div class="form-group">
                       <label for="field-1" class="col-sm-3 control-label"><?php echo get_phrase('name'); ?></label>

                       <div class="col-sm-5">
                           <input type="text" name="name" class="form-control" id="field-1" value="<?php echo set_value('name'); ?>" required>
                       </div>
                   </div>

                   <div class="form-group">
                       <label for="field-ta" class="col-sm-3 control-label"><?php echo get_phrase('description'); ?></label>

                       <div class="col-sm-9">
                           <textarea name="description" class="form-control wysihtml5" id="field-ta" data-stylesheet-url="<?php echo base_url(); ?>assets/css/wysihtml5-color.css" required><?php echo set_value('description'); ?></textarea>
                       </div>
                   </div>

                   <div class="col-sm-3 control-label col-sm-offset-2">
                       <input type="submit" class="btn btn-success" value="Submit">
                   </div>
                   <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash();?>" />
               </form>

           </div>

config/form_validation.php
PHP Code:
$config = array(
 
                'department' => array(
 
                                   array(
 
                                           'field' => 'name',
 
                                           'label' => 'Name',
 
                                           'rules' => 'required'
 
                                        ),
 
                                   array(
 
                                           'field' => 'description',
 
                                           'label' => 'Description',
 
                                           'rules' => 'required'
 
                                        )
 
                                                     
               
); 

Controller
PHP Code:
if ($this->form_validation->run('department') == FALSE)
{
 
       $page_data['page_name'    'xxxx';
 
       $page_data['page_title'   'xxxx';
 
       $this->load->view('xxxx'$page_data);
}
 else if (
$this->form_validation->run('department') == TRUE)
{
 
       $this->department('create');

Reply

#2
Hi,
can you upload a thumb so that we can see how the error is displayed ?
NexoPOS 2.6.2 available on CodeCanyon.
Reply

#3
Hi,
you should check the following config item:

PHP Code:
$config['csrf_regeneration'] = TRUE

modify it to FALSE may work.
See more http://www.codeigniter.com/user_guide/li...rgery-csrf
Reply

#4
(06-06-2015, 11:25 AM)pdthinh Wrote: Hi,
you should check the following config item:


PHP Code:
$config['csrf_regeneration'] = TRUE

modify it to FALSE may work.
See more http://www.codeigniter.com/user_guide/li...rgery-csrf

Kindly let me know is there any way where I can enable the CSRF_REGENERATION and the error will get resolved
Reply

#5
The idea with CSRF is exactly for you not to resubmit the same form twice. The alternative solution would be to do a redirect (to the same controller/function if you want to return tot the form after submitted some data) after you saved the form data.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.