2014-02-06 70 views
0

我有一個註冊表單,用於收集用戶數據, 名稱,姓氏,電子郵件等,並將其發送到電子郵件。 但是,驗證似乎不起作用。表單驗證和表單操作不起作用

我的問題是,當用戶點擊提交,即使沒有 輸入任何內容,頁面將重定向到表單動作腳本頁面,而不是隻執行該頁面中的腳本。

任何幫助,歡迎。 邁克

形式:

<?php 
echo form_open('viewer_registration_email/signup_validation'); 


echo validation_errors(); 
    $name_data = array( 
    'name' => 'viewerFirstName', 
    'id' => 'viewerFirstName', 
    'value' => $this->input->post('viewerFirstName'), 
    'placeholder' =>" First Name", 
    'class' => 'customInputFieldSmallHome' 
); 

$email_data = array(
    'name' => 'viewerEmail', 
    'id' => 'viewerEmail', 
    'value' => $this->input->post('viewerEmail'), 
    'placeholder' =>" Your Email", 
    'class' => 'customInputFieldHome' 
); 

echo form_hidden('submit_viewer', 1); 
echo '<span style="float:left">'; 
echo form_input($name_data); 
echo '</span><br>'; 
echo form_input($email_data); 

echo form_submit("submit", "", 'class="signUpBtn"'); 

echo form_close(); 
?> 

控制器:

<?php 
if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Viewer_registration_email extends CI_Controller { 
    public function index() 
    { 
    } 
    public function signup_validation() 
    { 
     $this->load->library('form_validation'); 
     $this->form_validation->set_rules('viewerFirstName','First Name','required|trim'); 
     $this->form_validation->set_rules('viewerEmail','Email','required|trim|valid_email'); 
     if($this->form_validation->run()) 
     { 
      $this->load->library('email', array('mailtype' => 'html')); 
      $this->email->from('[email protected]','My site Registration'); 
      $this->email->to('[email protected]'); 
      $this->email->subject('New registered user'); 
      $birthday = $this->input->post('viewerBirthDay')."/".$this->input->post('viewerBirthMonth') ."/". 
      $this->input->post('viewerBirthYear'); 
      $message = '<div style="width:100%; height:35px; background-color:#558F61;"></div> 
         <br><br><br> 
         <h1> A new user has registered as a <span style="font-weight:bold">Viewer</span> on Your website.</h1> 
         <br><br><br> 
         <table style="border:none"> 
          <tr> 
           <td> 
            <span style="font-weight:bold">Name: </span> 
           </td> 
           <td> 
            '.$this->input->post('viewerFirstName').' 
           </td> 
          </tr> 
          <tr> 
           <td> 
            <span style="font-weight:bold">Last name: </span> 
           </td> 
           <td> 
            '.$this->input->post('viewerLastName').' 
           </td> 
          </tr> 
           <tr> 
           <td> 
           <span style="font-weight:bold">Email: </span> 
           </td> 
           <td> 
            '.$this->input->post('viewerEmail').' 
           </td> 
          </tr> 
         </table>  
         <br><br><br><br> 
         <div style="width:100%; height:35px; background-color:#558F61;"></div>'; 
      $this->email->message($message); 
      //send email to user 
      if($this->email->send()){ 
       //echo "Email has been sent."; 
       $this->load->view('confirm_registration_email'); 
      }else{ 
       echo 'email failed!'; 
      } 
     }else{ 
      $this->load->view('home_main'); 
     } 
    } 
} 
+0

我忘了說,該網址更改爲:「viewer_registration_email/signup_validation」和頁面是空白。即使數據輸入到字段中也是如此,所以我的猜測是它沒有通過驗證,因爲它好像不存在。 –

+0

表單的操作是'viewer_registration/signup_validation',但控制器名稱是'Viewer_registration_email'。這是一個錯字嗎? – Samutz

+0

它只是在這裏一個錯字,他們都是「\t \t \t \t \t \t「viewer_registration_email」 –

回答

0

顯然的問題是與我的託管服務設置。使用GoDaddy。我發現這裏 解決方案:Godaddy-Installation-Tips

感謝所有的答覆,

邁克