Welcome Guest, Not a member yet? Register   Sign In
problem form_open
#1

hello dev,

I have a problem to retrieve data from a form CI3.1.13
Here is the code.
if I am in UPDATE mode it works perfectly
in add mode the inputs are empty

PS I am blocked, I never had this PB

Code:
<div class="row">
            <div class="col-sm-12">
                <div class="panel panel-bd lobidrag">
                    <div class="panel-heading">
                        <div class="panel-title">
                            <h4><?php echo $title ?> </h4>
                        </div>
                    </div>
                    <div class="panel-body">
<?php echo form_open(base_url('designation_form/').$designation->id,'class="" id="add_designation"' )?>

<div class="form-group row">
<label for="designation" class="col-sm-2 text-right col-form-label"><?php echo display('designation')?> <i class="text-danger"> * </i>:</label>
<div class="col-sm-4">
<input type="text" name="designation" class="form-control" id="designation" placeholder="<?php echo display('designation')?>" value="<?php echo $designation->designation?>">
</div>
</div>

<div class="form-group row">
<label for="details" class="col-sm-2 text-right col-form-label"><?php echo display('details')?> <i class="text-danger"> </i>:</label>
<div class="col-sm-4">
<input type="text" name="details" class="form-control" id="details" placeholder="<?php echo display('details')?>" value="<?php echo $designation->details?>">
</div>
</div>
<div class="form-group row">
<div class="col-sm-6 text-right">
<button type="submit" class="btn btn-success ">
<?php echo (empty($designation->id)?display('save'):display('update')) ?></button>
</div>
</div>
<?php echo form_close();?>
</div>
</div>
</div>
</div>

controller


PHP Code:
        public function designation_form($id '')
    {
        $data['title'] = display('add_designation');
        #-------------------------------#
        $this->form_validation->set_rules('designation',display('designation'),'required|max_length[200]');
        $this->form_validation->set_rules('details'display('details') ,'max_length[250]');
        #-------------------------------#
        $data['designation'] = (object)$postData = [
            'id'            => $id,
            'designation'    => $this->input->post('designation',true),
            'details'        => $this->input->post('details',true),
        ]; 

        #-------------------------------#
        if ($this->form_validation->run()) {

            #if empty $id then insert data
            if (empty($id)) {
                if ($this->hrm_model->create_designation($postData)) {
                    #set success message
                  $this->session->set_flashdata('message'display('save_successfully'));
                } else {
                $this->session->set_flashdata('exception'display('please_try_again'));
                }
                redirect("designation_list");
            } else {
                if ($this->hrm_model->update_designation($postData)) {
                  $this->session->set_flashdata('message'display('update_successfully'));
                } else {
                  $this->session->set_flashdata('exception'display('please_try_again'));
                
                redirect("designation_list");
            }
            } else { 
                if(!empty($id)){
                $data['title']      display('designation_update_form');
                $data['designation'] = $this->hrm_model->single_designation_data($id);  
                
}
                $data['module']      "hrm";  
                $data
['page']        "hrm/designation_form";  
                
echo Modules::run('template/layout'$data); 
          
            

    
thank you for your help
Reply




Theme © iAndrew 2016 - Forum software by © MyBB