【问题标题】:Curl and javascript submit卷曲和 javascript 提交
【发布时间】:2011-07-06 20:27:50
【问题描述】:

我尝试使用 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> 

还有我的 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;
    }

感谢您的输入,上面的代码没有验证表单,我想我在提交验证过程中遗漏了一些东西......

【问题讨论】:

    标签: php javascript forms curl submit


    【解决方案1】:

    如果您只需要发布表单@logic-unit 具有执行页面的正确方式

    在您的 php 代码中,您似乎做得很好,只要确保您确定何时调用 功能

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

    只要确保你不要混淆你的 GET 和你的 POST,你似乎在传递用户、密码数据,这些数据应该在 php 的 _POST 对象上,或者你甚至可以考虑使用 _REQUEST

    【讨论】:

      【解决方案2】:

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

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

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

      可能会起作用。

      不过,使用 JQuery 和 AJAX 发布帖子然后返回结果可能是更好的选择。

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

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

      【讨论】:

      • 表单不是我的,但在我想使用 curl 函数 affiliatevista.com 的网站上,您可以看到他们没有在输入中添加 onclick,所以我必须处理它并调用curl里面的vallogin不是吗?
      • @henri 你让我有点不知所措。您不能在 php.ini 中执行 javascript。一个是客户端,另一个是服务器端。你的意思是你无法访问javascript和html,所以你试图从服务器调用提交函数?
      • 所以如果我理解我不能使用 CURL 和 javascrip 的表单验证,即使我找到了表单验证的目的地:/index.php?vallogin=1?感谢逻辑单元!
      猜你喜欢
      • 2016-01-18
      • 2013-04-12
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      • 2018-05-02
      • 2011-05-21
      相关资源
      最近更新 更多