为什么模态数据没有发布到控制器


Why modal data is not posted to controller

我正试图将数据从引导程序中的模态发布到代码点火器中的控制器。但数据并未公布。

public function save()
{
     if (!empty($_POST['UserName'])){
         $data = $this->input->post('UserName');
         echo $data;
     }
     else
     {
         echo "Not posted";
     }
}

在视图中,

 <div class="modal-body"> 
    <?php echo form_open('Supplier/save'); ?>
    <table>
        <tr>    
                <td>User Name
                <input id="UserName" name="UserName" type="text" class="validate" required></td>
        </tr>       
    </table>
    <?php echo form_close(); ?>
</div> 

也许你需要?

echo form_submit('mysubmit', 'Submit Post!');

也可以考虑使用isset()而不是!empty()。例如,当您为数字0检查数值empty()时,将返回true。

首先,您需要使用如@Mateusz Petkiewicz所说的提交。那么为什么不使用像那样的CI输入post和form_validator

public function save(){
    $this->form_validation->set_rules('UserName', 'Username', 'trim|required|xss_clean');
    if( $this->form_validation->run()){
        echo $data;
    }
    else{
        echo validation_errors();
        echo "<hr>Not posted";
    }
}