开发者

How to post the name or id of a textbox, like the way we post the value of it

开发者 https://www.devze.com 2023-03-01 15:51 出处:网络
I have two textboxes called text1 and text2, and variables value1 and value2. When the user submits the form, I want to create a url like below

I have two textboxes called text1 and text2, and variables value1 and value2.

When the user submits the form, I want to create a url like below

mydomain.开发者_JS百科com/?text1=value1&text2=value2

How can I pass the name of the texbox or a dropdown list?


I assume you know how to use $_GET. If not, you need to learn about the difference between get and post.

Otherwise, if you really must use $_POST, you can use http_build_query() or if it's not available, something like this after the form submit:

$url = '?';
foreach ($_POST as $k => $v)
{
     $url .= "&".urlencode($k).'='.urlencode($v);
}
header("Location: mydomain.com/$url");

The most sensible solution is to use $_GET, which will do this for you automatically.

<form method="get" action="mydomain.com">


Assuming I understood your question, you should set the method attribute in your form to "get". Once the form is submitted you'll see the form fields' submitted values in the url.

0

精彩评论

暂无评论...
验证码 换一张
取 消