1

I am using HMVC Codeigniter pattern for my project. And In my project I need to set the value on form where input type of field is file.So, I feel greatful for them who help me to solve out this problem.

My associate controller is apply.php

<?php
class Career extends Controller{
function __construct(){
        parent::__construct();

        $this->load->Model('career_model','',TRUE);
        $this->load->model('welcome/Mwelcome','',TRUE);     
        //session_start();
    }
finction index(){
redirect('career/apply');
}
  function apply(){
        $this->load->library('form_validation');
        $this->load->helper('url');
        $this->form_validation->set_rules('fname','First Name','required|trim');
        $this->form_validation->set_rules('mname','Middle Name','required|trim');
        $this->form_validation->set_rules('lname','Last Name','required|trim');
        $this->form_validation->set_rules('date','Date','required|trim');
        $this->form_validation->set_rules('pAddress','Permanent Address','required|trim');
        $this->form_validation->set_rules('cAddress','Contact Address','required|trim');
    $this->form_validation->set_rules('gender','Gender','required|trim');

        if (empty($_FILES['cv']['name']))
        {
            $this->form_validation->set_rules('cv', 'Attach Your CV', 'required');
        }
        if($this->form_validation->run($this)){

                    $_SESSION['msg']="Your form has been submitted succesfully!!";
                    redirect('career/apply');
                }
                else
                {

                    $_SESSION['err']="Opp! There was some wrong to fill up a form so try again!!!";
                    redirect('career/apply');


                }

            }
        $data=array('body'=>'apply');
        $data['pgtitle']='Apply';       
        $this->load->view('temp',$data);
        } 
}

My associate view file is apply.php

<form action="<?php echo site_url()?>career/apply" method="post" enctype="multipart/form-data" onsubmit="return confirm('Do you really want to submit the form?');">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">


    <tr>
      <td width="">Name</td>
      <td width="158"><label for="fname"></label>
      <input type="text" name="fname" id="fname" placeholder="First Name" class='input-row' value="<?php echo set_value('fname')?>"/><span class="required"><?php echo form_error('fname');?></span></td>
      <td width="158"><label for="mname"></label>
      <input type="text" name="mname" id="mname" placeholder="Middle Name" class='input-row' value="<?php echo set_value('mname')?>"/></td>
      <td width="158"><label for="lname"></label>
      <input type="text" name="lname" id="lname" placeholder="Last Name" class='input-row' value="<?php echo set_value('lname')?>"/><span class="required"><?php echo form_error('lname');?></span></td>
    </tr>

    <tr>
      <td>Date of Birth</td>
      <td width="158"><label for="date"></label>
      <input type="text" name="date" id="date" class='input-row' value="<?php echo set_value('date')?>" placeholder="yyyy-mm-dd"/><span class="required"><?php echo form_error('date');?></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
   <tr>
      <td>Gender</td>
      <td><div class="customSel">
        <label>
        <select name="gender" id="select" class='input-row' value="">

         <option value="Female"<?php echo  set_select('gender', 'Female', TRUE); ?>>Female</option>
         <option value="Male"<?php echo  set_select('gender', 'Male', TRUE); ?>>Male</option>
         <option value="Please Selection"<?php echo  set_select('gender', 'Please Selection', TRUE); ?>>Please Selection</option>
         <?php /*?><option value="Other"<?php echo  set_select('gender', 'Other', TRUE); ?>>Other</option><?php */?>
      </select></label></div><span class="error"><?php echo form_error('gender')?></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Address</td>
      <td><label for="pAddress"></label>
      <input type="text" name="pAddress" id="pAddress" placeholder="Permanent Address" class='input-row' value="<?php echo set_value('pAddress')?>"/><span class="required"><?php echo form_error('pAddress');?></span></td>
      <td><label for="cAddress"></label>
      <input type="text" name="cAddress" id="cAddress" placeholder="Contact Address" value="<?php echo set_value('cAddress')?>"/><span class="required"><?php echo form_error('cAddress');?></span></td>
      <td>&nbsp;</td>
    </tr> 
    <tr>
      <td>Attach Your CV</td>
      <td colspan="2"><label for="cv"></label>
      <input type="file" name="cv" id="cv" value="<?php echo set_value('cv')?>"/><span class="error"><?php echo form_error('cv')?></span></td>
    </tr>
    <tr>

      <td><input type="submit" name="submit" id="submit" value="Submit" class="Button" />

        <input type="reset" name="reset" id="reset" value="Reset" class="Button" /></td>

      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form >
pau cha
  • 132
  • 8
  • Please show us your controller, and do you get an error? – PJ Bergeron Mar 10 '15 at 05:05
  • There is no error but the name of uploaded file does not set after the submission of incomplete form. but set value is worked on input type text(input type="text"). – pau cha Mar 10 '15 at 05:11
  • 1
    And can you show your controller? – PJ Bergeron Mar 10 '15 at 05:15
  • 1
    you can not, due to security purposes. imagine a browser crawling your filesystem ! [ref1](http://stackoverflow.com/questions/4205634/restoring-the-value-of-a-input-type-file-after-failed-validation) [ref2](http://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html). you may use other workarounds to repopulate item name in a text field. – Karan Thakkar Mar 10 '15 at 05:15

0 Answers0