2011-04-12 17:13
浏览 103

cURL + PHP:提交具有相同表单名称的重复表单的表单

I am trying to POST to a page that has two forms with duplicate name elements. The problem is that one form gets the password value and the other form gets the login value. (I can see this by printing out curl_exec($ch);) I will include my code for the target URL and the formdata. How do I fix this?

// my target url and form data
$target = "";
$formdata = "id=$login&password=$password&Submit=Log In";


<form id="login" name="login" method="post" action="login">

            <label for="id">LOGIN ID</label>  <input type="text" value="" name="id" maxlength="50" size="30"><br>
            <label for="password">Password ID</label>  <input type="password" name="password" maxlength="12" size="30">
            <div align="center"><button class="siteSprite signInSm" value="Log In" name="Submit" type="submit"></button></div>

<form section="login" id="loginform" name="loginform" action="" method="post">
<input type="text" size="20" value=" Log-in" onfocus="this.value=''" name="id"></td>
<input type="password" value="Password" maxlength="15" size="12" onfocus="this.value=''" name="password">
<input type="submit" class="siteSprite signInSm" value="Sign-In">

图片转代码服务由CSDN问答提供 功能建议

我正在尝试POST到具有两个具有重复名称元素的表单的页面。 问题是一个表单获取密码值,另一个表单获取登录值。 (我可以通过打印出curl_exec($ ch)来看到这个;)我将包含目标URL和formdata的代码。 我该如何解决这个问题?

 $ target =“";
$  formdata =“id = $ login&amp; password = $ password&amp; Submit = Log In”; 


 <  code>&lt; form id =“login”name =“login”method =“post”action =“login”&gt; 
&lt; label for =“id”&gt; LOGIN ID&lt; / label&gt;  &lt; input type =“text”value =“”name =“id”maxlength =“50”size =“30”&gt;&lt; br&gt; 
&lt; label for =“password”&gt;密码ID&lt; / label&gt  ;  &lt; input type =“password”name =“password”maxlength =“12”size =“30”&gt; 
&lt; div align =“center”&gt;&lt; button class =“siteSprite signInSm”value =“Log 在“name =”提交“type =”提交“&gt;&lt; / button&gt;&lt; / div&gt; 
&lt; / form&gt; 
&lt; form section =”login“id =”loginform“name =  “loginform”action =“”method =“post”&gt; 
&lt; input type =“text”size =“20”value =“登录”onfocus =“this  .value =''“name =”id“&gt;&lt; / td&gt; 
&lt; input type =”password“value =”Password“maxlength =”15“size =”12“onfocus =”this.value ='  '“name =”password“&gt; 
&lt; input type =”submit“class =”siteSprite signInSm“value =”Sign-In“&gt; 
&lt; / form&gt; 
   \  n 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanhan8757 2011-04-12 17:19

    You'll have to do something to indicate which of the two forms got submitted. You can either submit a field with the same name but different values in each one, or use the submit button:

    <form ...>
        <input type="hidden" name="whichform" value="1" />
        <input type="submit" name="Submit" value="form 1" />
    <form ...>
        <input type="hidden" name="whichform" value="2" />
        <input type="submit" name="Submit" value="form 2" />

    and then

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        if (($_POST['Submit'] == 'form 1') || ($_POST['whichform'] == '1')) {
            .... handle form #1 ....
        if (($_POST['Submit'] == 'form 2') || ($_POST['whichform'] == '2')) {
            .... handle form #1 ....

    using either method works the same, just pick the one that makes most sense/is easiest and go from there.

    点赞 打赏 评论
  • dongpei2835 2011-04-12 17:20

    $formdata = "id=$login&password=$password&Submit=Sign-In"; might do the trick; note the fact that the second form has a submit button with a value, and the first form has a <button> which won't send a value (or, maybe, sends a different value via script or something)

    I just noticed that the submit button doesn't have a name; try passing it with NO submit parameter, i.e.:

    $formdata = "id=$login&password=$password
    点赞 打赏 评论

相关推荐 更多相似问题