2012-03-25 110 views
0

GET變量我有有一些得到它的變量,比如一個網址:笨表單提交將刪除URL

domain.com/[email protected]&token=abc123 

內恢復控制器我打開一個表格POST方法

所以,當我提交我再次加載的形式恢復控制器,但我GET變量消失,返回到

domain.com/recover 

那麼,如何確保GET變量在提交表單後保留在URL中?

HTML:

<?php echo form_open('recover'); ?> 
    <label for="password1" class="fl" style="width:160px;">Your new Password</label> 
    <input type="text" value="" id="password1" name="password1" style="width:308px;margin-top:0;margin-left:10px;" /> 
    <label for="password2" class="fl" style="width:160px;">Retype your new Password</label> 
    <input type="text" value="" id="password2" name="password2" style="width:308px;margin-top:0;margin-left:10px;" /> 
    <input type="submit" value="Recover password" class="button_ui" name="submit" /> 
<?php echo form_close(); ?> 

控制器:

$data = array(
    'errors' => '', 
    'show_password_form' => false 
); 
$get_email = $this->input->get("email") ? trim($this->input->get("email")) : ""; 
$get_token = $this->input->get("token") ? trim($this->input->get("token")) : ""; 
if ($get_email != "" && $get_token != ""){ 
    $this->load->model("recover_model"); 
    $data["show_password_form"] = true; 
    //check new passwords and update 
    $submit = $this->input->post("submit_change") ? trim($this->input->post("submit_change")) : ""; 
    if ($submit){ 
     $password1 = $this->input->post("password1") ? trim($this->input->post("password1")) : ""; 
     $password2 = $this->input->post("password2") ? trim($this->input->post("password2")) : ""; 
     //if password1 is valid 
     if ($this->recover_model->valid_password($password1)){ 
      //if password2 is valid 
      if ($this->recover_model->valid_password($password2)){ 
      //if both are equal 
       if ($password1 == $password2){ 
        //update password 
       }else{ 
        $data["errors"] = 'Your passwords do not match.'; 
       } 
      }else{ 
      $data["errors"] = 'Your password must be at least 6 characters.'; 
      } 
     }else{ 
      $data["errors"] = 'Your password must be at least 6 characters.'; 
     } 
    } 
} 
$this->load->view("account/recover/recover", $data); 
+0

請寫出控制器的源代碼。你如何創建郵政形式? – safarov 2012-03-25 10:40:41

+0

@safarov更新與控制器的問題和形式 – fxuser 2012-03-25 10:47:47

回答

2

改變這一行:<?php echo form_open("recover"); ?>

<?php echo form_open('recover', $_GET); ?>

它會創建所有得到的值作爲隱藏的輸入。當你提交表單時,他們會用你爲表單定義的方法發送。

或者你可以手動寫:

<?php echo '<form method="post" accept-charset="utf-8" action="'.base_url().'recover?email='.$_GET['email].'&abc='.$_GET['token'].'" />'; ?> 
+0

這將在

標記中添加_GET參數,但是當我提交表單時,它不包含它們在url中? – fxuser 2012-03-25 10:55:05

+0

更新,再次檢查 – safarov 2012-03-25 11:05:03

0

手動呈現在PHP或HTML表單標籤,並添加一些JavaScript

<script type="text/javascript"> 
    document.write("<form method=\"POST\" action=\""); 
    document.write(window.location.href); 
    document.write("\">"); 
</script> 

好多JS都可以寫這個...