set_value不适用于HMVC Codeigniter上的输入类型文件

时间:2015-03-10 05:02:22

标签: php html codeigniter

我正在为我的项目使用HMVC Codeigniter模式。在我的项目中,我需要在表单上设置值,其中输入类型的字段是file.So,我觉得很有帮助我解决这个问题的人。

我的助理控制器是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);
        } 
}

我的关联视图文件是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 >

0 个答案:

没有答案