PHP获取选择选项值 [英] PHP get select option value
问题描述
我有一个javascript函数,我必须将它切换到php。
但是在php中,我不知道如何使它工作。
该功能在页面的选择框中获取值,并在按下提交时将其转换为url链接
。
$ b $在JavaScript中很容易,您可以在不提交或刷新页面的情况下获得选择框的值,并将值直接放入函数中。
但在PHP
示例:
< form name =formmethod =postaction =<?php getUrlValues('car','31231h3',quantity ='***')?>
< option value =1>< / option>
< option value =2>< / option>
< / select>
无论我在选择框中选择什么,都会直接显示到函数中。
getUrlValues('car','31231h3',quantity = option value
有没有办法做到这一点?
没有刷新页面
在没有客户端提交表单的情况下,PHP没有办法获得表单域的值,但是您可以提交例如,假设您的目标网域/网页是www.mydomain.com/process.php:
<?php
$ redirect_url =http://www.mydomain.com/process.php?car=。$ _GET ['car']。 & 31231h3 =。$ _GET ['31231h3']。& quantity =。$ _POST ['quantity'];
header(Location:。$ redirect_url);
? >
I have a javascript function that I have to switch it into php.
But in php I don't know how to make it work.
The function is getting value in a select box in the page and convert it into a url link when submit is pressed.
In javascript it's easy you can get the value of a select box without submitting or refreshing the page and put the value directly into the function.
But in PHP I can't get the select value without refreshing the page.
Example:
<form name="form" method="post" action="<?php getUrlValues('car', '31231h3', quantity='***') ?>"
<select name="quantity">
<option value="1"></option>
<option value="2"></option>
</select>
Whatever I select in the select box will directly display into the function. getUrlValues('car', '31231h3', quantity=option value
Is there a way to do that? Without refreshing page.
PHP doesn't have any way to get the value of a form field without the client submitting the form. But you could submit to an alternate page, process the value, and redirect to the correct url. For example, assuming your target domain/page is "www.mydomain.com/process.php":
<?php
$redirect_url = "http://www.mydomain.com/process.php?car=" . $_GET['car'] . "&31231h3=" . $_GET['31231h3'] . "&quantity=" . $_POST['quantity'];
header("Location: " . $redirect_url);
?>
这篇关于PHP获取选择选项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!