2011-11-11 21 views
0

我想使用CodeIgniter的recaptcha。我遵循了一些在线指令,最后我只用了一步就完成了,只是将recaptcha传递给视图,但我无法验证用户输入。recaptcha与codeigniter,我可以把它放在视图中..但不能验证它

这里是我的控制器:

function download_application() 
{ 
    //load the libraries 
    $this->load->library('form_validation'); 
    $this->load->library('recaptcha'); 
    $this->lang->load('recaptcha');  
    //common data 
    $data['title'] = $_POST['application_name']; 
    $data['header'] = $_POST['application_name']; 
    $data['sub_header'] = 'تحميل استمارة قبول المشروع';  
    $data['title'] = $_POST['application_name']; 
    $data['recaptcha'] = $this->recaptcha->get_html();  
    //form validation 
    $this->form_validation->set_error_delimiters('<span class="notification">', '</span>'); 
    $this->form_validation->set_message('required', 'هذا الحقل مطلوب ولا يمكن تجاهله'); 
    $this->form_validation->set_rules('name', 'لابد من ادخال اسمك بالكامل', 'required'); 
    $this->form_validation->set_rules('email', 'لابد من ادخال بريدك الالكترونى', 'required|email'); 
    $this->form_validation->set_rules('country', 'لابد من ادخال بلدك', 'required'); 
    $this->form_validation->set_rules('phone', 'لابد من ادخال رقم تليفونك', 'required'); 

    //form submitted 
    if($this->input->post('recaptchasubmit')){ 
     if($this->form_validation->run() == FALSE) 
     { 

      $this->load->view('header', $data); 
      $this->load->view('download', $data); 
      $this->load->view('footer', $data); 


     } 
     else 
     { 

      $this->load->view('header', $data); 
      $this->load->view('download', $data); 
      $this->load->view('footer', $data); 

     } 
    }  
    else{ 

      $this->load->view('header', $data); 
      $this->load->view('download', $data); 
      $this->load->view('footer', $data); 

    } 

} 

,这里是我的观点

<?php 
    $form_attributes = array(
     'class' => 'form' 
    ); 
    $btn_download = array(
     'type'  => 'image', 
     'src'  => base_url().'images/download.gif', 
     'name'  => 'recaptchasubmit', 
     'width'  => '103', 
     'height' => '33', 
     'value'  => 'تحميل' 
    ); 
    $name = array(
     'type' => 'text', 
     'name' => 'name', 
     'id' => 'name', 
     'value' => set_value('title') 
    );      
    $email = array(
     'type' => 'text', 
     'name' => 'email', 
     'id' => 'email', 
     'value' => set_value('email') 
    );        
    $country = array(
     'type' => 'text', 
     'name' => 'country', 
     'id' => 'country', 
     'value' => set_value('country') 
    );         
    $phone = array(
     'type' => 'text', 
     'name' => 'phone', 
     'id' => 'phone', 
     'value' => set_value('phone') 
    ); 
?>      
<?php echo form_open($base_url . 'arabia/download_application', $form_attributes); ?> 
<fieldset> 
    <div class="input_container"> 
     <label class="required">الاسم بالكامل</label> 
     <div class="input"><?php echo form_input($name); ?></div> 
     <?php echo form_error('name'); ?> 
    </div> 
    <div class="input_container"> 
     <label class="required">البريد الالكترونى</label> 
     <div class="input"><?php echo form_input($email); ?></div> 
     <?php echo form_error('email'); ?> 
    </div> 
    <div class="input_container"> 
     <label class="required">البلد</label> 
     <div class="input"><?php echo form_input($country); ?></div> 
     <?php echo form_error('country'); ?> 
    </div> 
    <div class="input_container"> 
     <label class="required">التليفون</label> 
     <div class="input"><?php echo form_input($phone); ?></div> 
     <?php echo form_error('phone'); ?> 
    </div> 
    <?php echo $recaptcha; ?> 
    <?php echo form_error('recaptcha_response_field'); ?> 

    <?php echo form_hidden('application_name', $title); ?> 
    <?php echo form_hidden('generated_id', $title); ?> 
</fieldset> 
<span class="download"><?php echo form_submit($btn_download);?></span>      
<?php echo form_close();?> 
+2

旁注:如果你使用常见的意见,和普通的数据,为什么你在每个条件内重复它们?只要把它们放在外面,代码就会变得更加可读另外,为什么你混合$ _POST和$ this-> input-> post()? –

+0

你是对的,这是因为我在这里写了一个代码和代码...当我处理这个表单时,我现在修复了它 – ahmedsaber111

回答

2

你什么意思,你无法验证用户输入?提交表单时发生了什么?你在哪里重定向?你看到了什么?

我可以从你的问题看迄今为止的唯一的事情是,你是通过

$data['recaptcha'] = $this->recaptcha->get_html(); 

无论是否验证通过与否 - 所以你会看到的ReCaptcha字母/数字框两种方式。你需要覆盖,如果验证通过类似的东西:

$data['recaptcha'] = "validation passed"; 
相关问题