dongzhunqiu4841
2014-06-20 12:02
浏览 50
已采纳

使用GET数据提交PHP表单的问题

I am working with PHP forms. The opening form tag looks like this:

<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">

This generated the following HTML:

<form name="adv_search_form" action="index.php?&amp;rel=common_listing&amp;module=company&amp;sort_option=&amp;search_option=&amp;show_max_row=15" method="GET">

When I submit this form, I land on a URL:

http://localhost/projectcode12may2014/ampanel/index.php?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit

But what I want is that

?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit

should be appended to the action URL on the landing page. Can anyone suggest any good method for doing this? Thanks in advance.

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

我正在使用PHP表单。 开始表单标记如下所示:

 &lt; form name =“adv_search_form”action =“&lt;?php echo $ targetpage;?&gt;”  method =“GET”&gt; 
   
 
 

这会生成以下HTML:

 &lt; form name =“  adv_search_form“action =”index.php?&amp; amp; rel = common_listing&amp; amp; module = company&amp; amp; sort_option =&amp; amp; search_option =&amp; amp; show_max_row = 15“method =”GET“&gt; 
    
 
 

当我提交此表单时,我会找到一个URL:

  http:// localhost / projectcode12may2014 / ampanel  /index.php?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
   
 
 

但我想要的是

?field%5B%5D = broker_name&amp; adv_operation%5B%5D = LIKE&amp; value%5B%5D = &amp; query_type%5B%5D = AND&amp; submit = Submit

应附加到着陆页上的操作网址中。 任何人都可以提出任何好方法吗? 提前谢谢。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duan5801 2014-06-20 12:06
    已采纳

    If you are using method="get" the parameters in action are overwritten. Only what is in the from will be transmitted.

    You need to add hidden fields for all these values. For example:

    <input type="hidden" name="module" value="company" />
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongpao1083 2014-06-20 12:07

    That is your from data.

    You have method="get" in your form tag. This means that the form data is concatinated to the URL. Use method="post" to have send form data as a POST request and keep your URI clean.

    So change this line

    <form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
    

    to this

    <form name="adv_search_form" action="<?php echo $targetpage; ?>" method="post">
    

    Then you can access your form data in PHP with the global $_POST var which holds an array with the submitted data.

    评论
    解决 无用
    打赏 举报
  • dongmubi4444 2014-06-20 12:08

    This is a normal behavior. Using GET method discard all parameters specified directly in action attribute.

    Use POST method instead or move parameters from action attribute of the form to input fields with type="hidden".

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题