2011-03-01 98 views
0

我嘗試使用javascript提交流程來捲曲頁面,但沒有任何運氣......所以我要求社區提供一些幫助!捲曲和javascript提交

這裏是形式:

<script> 
    <!-- 
    function vallogin(){ 
     document.formlogin.action = "./index.php?vallogin=1"; 
     document.formlogin.submit(); 
    } 
    --> 
</script> 


<form name="formlogin" method="post"> 
<div class="headerblocgris"> 
<span class="txtnoir12">| Accès |</span> 
</div> 
<table width="100%" border="0" cellspacing="0" cellpadding="0">      
<tr> 
<td class="txtnoir12">Login</td> 
<td><input name="txtlogin" type="text" size="15" /></td> 
<td><span class="txtnoir12">Password</span></td> 
<td> 
<input name="txtmdp" type="password" size="15" /> 
<input type="image" name="vallogin" src="images/bt_go.gif" align="absmiddle" /> 
</td> 
</tr> 
</table> 
</form> 

我的捲曲功能:

{ 
     /** 
     * Connexion 
     */ 
     $URL = 'http://www.affiliatevista.com/index.php?vallogin=1'; 

     $data = array(
        'txtlogin' => $this->login, 
        'txtmdp' => $this->passe, 
        'formlogin' => '', 
        'vallogin' => '', 

       ); 
     curl_setopt($this->ch, CURLOPT_URL, $URL); 
     curl_setopt($this->ch, CURLOPT_HEADER, true); 
     curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->implode_array($data)); 
     curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->_getCookie()); 
     curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->_getCookie()); 
     curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); 
     $String = curl_exec($this->ch); 
     echo $String; 
    } 

感謝您的輸入,上面的代碼不驗證的形式,我覺得我會錯過什麼用提交驗證過程...

回答

2

我想你需要調用vallogin()函數?

我沒有看到你的代碼提交按鈕,所以像:

<input type="submit" value="Login" onclick="vallogin(); return false" /> 

可能會奏效。

使用JQuery和AJAX做一個帖子,然後返回結果可能是一個更好的選擇。

http://api.jquery.com/jQuery.post/

或者它可能是你需要一個的onsubmit = 「vallogin()」 在您的表單屬性。

+0

表單不是我的,而是我想要的一個網站e捲曲函數http://www.affiliatevista.com/,因爲你可以看到它們不會在輸入內添加onclick,所以我必須處理它並調用curl內的vallogin不是嗎? – 2011-03-01 23:25:21

+0

@henri你已經在那裏迷失了我。你不能在php中執行javascript。一個是客戶端,另一個是服務器端。你的意思是你沒有訪問JavaScript和HTML,所以你試圖從服務器調用提交功能? – 2011-03-01 23:50:02

+0

因此,如果我明白我不能使用表單驗證javascrip的CURL,即使我找到表單驗證的目標:/index.php?vallogin=1?感謝邏輯單元! – 2011-03-02 11:34:50

0

,如果你需要的是發佈形式@邏輯單元有你似乎在做的事情確定你的PHP代碼執行的頁面

的正確方法,只是確保你確定何時調用 功能

if(isset($_GET['vallogin']) && $_GET['vallogin'] === 1){ 
//execute function here 
} 

只是確保你不要混淆你的GET和你的帖子,你似乎是通過用戶名,密碼數據,這應該是PHP的_POST對象上,或者你甚至可以考慮使用_REQUEST