php - Curl 和 javascript 提交

标签 php javascript forms curl submit

我尝试使用 javascript 提交过程来 curl 页面,但没有成功......所以我向社区寻求一些帮助!

这是表格:

<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> 

还有我的curl函数:

{
         /**
         * 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;
    }

感谢您的输入,上面的代码没有验证表单,我想我错过了提交验证过程的一些内容...

最佳答案

我认为您需要调用 vallogin() 函数?

我在您的代码中没有看到提交按钮,因此类似于:

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

可能有用。

使用 JQuery 和 AJAX 进行发布然后返回结果可能是更好的选择。

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

或者您的表单属性中可能需要 onsubmit="vallogin()"。

关于php - Curl 和 javascript 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5160718/

相关文章:

html - 将 CSS 星级评定集成到 HTML 表单中

php - Twig_Error_Loader : Template is not defined - Drupal

php - 如何在php的矩阵表中显示数组

javascript - 如何显示图片

javascript - Gulp/Browserify 的 Redux NODE_ENV 错误

java - Struts 表单和变量声明

javascript - 从一个表单获取值并在另一个 jsp 中使用它

PHP 通知 : Use of undefined constant type

php - MySQL 查询的 $_GET 导致未知列错误

javascript - 使用curl 的Webdav 与Javascript