Welcome Guest, Not a member yet? Register   Sign In
form_submit() does not post
#1

(This post was last modified: 04-19-2015, 08:54 AM by Edwin.)

Hi all,

i found that codeigniter 3 has not submit my input submit value, when i declare the name. example as below:-

controller :

PHP Code:
// set page rules
        
$this->form_validation->set_rules(
            array(        
                array(
'field'=>'title','label'=>'Page Title','rules'=>'trim|required'),
            )
        );
    
        if(
$this->form_validation->run() == FALSE)
        {
        
            
            
$data['page_title_input'] = array(
                
'name' => 'title',
                
'value' => set_value('title',$item['page_title']),
                
'class' => 'form-control input-sm',
                
'id' => 'title',
                
'placeholder' => 'Page Title'
            
);
            
            
            
$data['save_btn'] = array(
                
'name' => 'save',
                
'value' => 'Save',
                
'class' => 'btn btn-default'
            
);
            
            
$data['publish_btn'] = array(
                
'name' => 'publish',
                
'value' => 'PUBLISH',
                
'class' => 'btn btn-primary btn-block'
            
);
            
            
$data['discard_btn'] = array(
                
'content' => ' Discard',
                
'type' => 'button',
                
'class' => 'btn btn-default',
                
'id' => 'discardPage'
            
);
            
            
            
$this->load->view('template/header');
            
$this->load->view('template/sidebar_left');
            
$this->load->view('edit',$data);
            
$this->load->view('template/footer');
        }
        else
        {
            
print_array($_POST); die;
            
        } 

view :

PHP Code:
<label for="title">Page Title</label>
<
form action="<?php echo site_url('pages/testing') ?>" method="POST">                        
<?
php echo form_input($page_title_input); ?>


<?php echo form_submit($save_btn); ?>
<?php 
echo form_submit($publish_btn); ?>
</form> 


result :

Code:
Array
(
    [title] => Carly Rae Jepsen - I Really Like You
)

in the result, it only shows me the title post variable. It should be show the result as :

PHP Code:
Array
(
    [
title] => Carly Rae Jepsen I Really Like You
    
[save] => Save  // or [publish] => PULISH


i had tested with native PHP, it work and keep my submit value. i don't know this consider as bug or i did something wrong?

Please help~ Thanks!!!
Reply
#2

Add type="submit" to your buttons
PHP Code:
$data['save_btn'] = array(
                ......
                
'type' => 'submit',
                ........
            ); 
Reply
#3

(04-19-2015, 06:21 PM)webnaz Wrote: Add type="submit" to your buttons

PHP Code:
$data['save_btn'] = array(
 
               ......
 
               'type' => 'submit',
 
               ........
 
           ); 

Thanks Webnaz for reply, it doesn't work and i not generate a button, i usually generate a submit button which is according to codeigniter user guide form_submit() it does help me auto add in type="submit".

and i missing one very informative info which is i using codeigniter 3 HMVC. i also tested codeingiter 3 without HMVC. Its work, but HMVC doesn't.
Reply
#4

(04-20-2015, 06:15 AM)Edwin Wrote: Thanks Webnaz for reply, it doesn't work and i not generate a button, i usually generate a submit button which is according to codeigniter user guide form_submit()  it does help me auto add in type="submit".

and i missing one very informative info which is i using codeigniter 3 HMVC. i also tested codeingiter 3 without HMVC. Its work, but HMVC doesn't.

This makes it seem likely that there could be an error in the HMVC Loader. If you're calling other controllers from within any of your views, though, you could just be overwriting variables in the loader or the view.
Reply
#5

I would guess it actually has to do with your form_validation library. This is a known challenge with WireDesignz' HMVC code. According to his docs at BitBucket:

wiredesignz Wrote:When using form validation with MX you will need to extend the CI_Form_validation class as shown below,


Code:
<?php
/** application/libraries/MY_Form_validation **/
class MY_Form_validation extends CI_Form_validation
{
   public $CI;
}

before assigning the current controller as the $CI variable to the form_validation library. This will allow your callback methods to function properly. (This has been discussed on the CI forums also).


Code:
<?php
class Xyz extends MX_Controller
{
   function __construct()
   {
       parent::__construct();

       $this->load->library('form_validation');
       $this->form_validation->CI =& $this;
   }
}
Reply
#6

(This post was last modified: 04-22-2015, 11:47 PM by Edwin.)

Hi, Guys i found the issue. is not codeigniter and HMVC problem.

The problem is my JAVASCRIPT function causing that!!!

i try make the form prevent multiple click submit button. so, the moment user submit the form then i disable the submit.

when the submit button is disable, it actually DO NOT POST.

anyway, thanks for reply and help~
Reply
#7

put your disable code on the SUBMIT button after you click it, so once they submit the form it disables the submit button.
Reply
#8

(04-23-2015, 08:13 AM)CroNiX Wrote: put your disable code on the SUBMIT button after you click it, so once they submit the form it disables the submit button.

Hi CroNix, Thanks for solution~ but that also is not working i had tried before, when the form is submitting the disable submit button is not posting as well. Unless you are using ajax.

i have used several method to do prevent multiple submit also not working as well.

method 1 ( Not Working )

$('#submit_btn').click(function(e) {
e.preventDefault();

// disable button
$(this).attr('disabled','disabled');

// submit form
$('#form').submit();
});

method 2 ( Not Working )

$('form').submit(function() {

// disable button
$('#submit_btn').attr('disabled','disabled');
});

Eventually, what i done is don't disabled the button, you can use overlay to cover it or set css to button pointer-events: none;
Reply




Theme © iAndrew 2016 - Forum software by © MyBB