如何在PHP中获取/获取HTML5 Range Slider的值? [英] How to get/fetch HTML5 Range Slider's value in PHP?

查看:204
本文介绍了如何在PHP中获取/获取HTML5 Range Slider的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得位于表单中的范围滑块的值?



我不能从名称中获取值。

p>

我使用这个JavaScript函数输出滑块旁边表单中的值

  function showValue(newValue){
document.getElementById(range)。innerHTML = newValue; }

我可以从div或类似的东西打电话吗?

编辑!
好​​的,我们走吧,对不起,如果我混淆你的话,但英语不是我的母语。我会尝试解释。



我在HTML5中有一个联系表单,它将数据提交给 mail.php

 < input type =textname =name/> 
< input type =emailname =email/>

mail.php 从输入框输入

  $ name = $ _POST ['name']; 
$ email = $ _POST ['email'];

然后进一步处理以发送实际邮件。



到目前为止,这么好?



我有一个Range Slider,用于确定用户想要预订的乘客数量。

 < input type =rangemin =1max =12step =1value =1name =passengersonchange = showValue(this.value)/> 
< span id =range> 1< / span>< / p>< / div>

我使用JavaScript函数,因为我想向用户显示滑块的当前选定值,因为他/ b
$ b 但我自己当然希望将 mail.php 中的这个值改为发送邮件也是如此。我不能要求范围名称中的值。所以我想知道如果也许我可以从div id范围访问值?或者什么?

解决方案

所以,你想要一个滑块,它显示当前的值,当表单提交时,你的动作文件(mail.php)获取/检索Slider的选定值以进一步处理。正确??



我相信这是因为:



您标题为发送HTML 5范围滑动值通过php 发送邮件,我将它解释为如何获得mail.php中此范围滑块的值。



你说你通过对它们执行$ _POST [foo]来获得输入文本框的值。



<因此,同样,Range Slider的值也可以在 $ _ POST 数组中使用。我假设你使用 action = POST ,因为你提到了 $ name = $ _POST ['name']


因此,要获得这个特定范围滑块的值,请使用:

  $ range_slider_value = $ _POST [passengers]; 

当然,您应该考虑清除表单输入和所有其他类型的外部输入。

全功能片段,在用户的计算机上显示该值,因为他/她更改滑块并在Form-提交给你的mail.php是:

 < form action =method =POST> 
< input type =textname =barid =barvalue =Slider Value = 1disabled />
< br />
< input type = submit value = Submit />
< / form>

<?php
if(isset($ _ POST [passengers])){
echo选择的乘客人数是:。$ _ POST [passengers ]。
//你的Slider值在这里,做你想要的。邮件/打印任何内容..
}其他{
回声请滑动滑块栏并按提交。;
}
?> b


$ b

noreferrer>在Codepad.viper-7.com进行现场演示



引用 http://www.html5tutorial.info/html5-range.php

值是常用属性的输入元素。该值可以是任何有效的浮点数,不一定必须是整数。默认值是最小值加上最大值的一半。



不要将Javascript功能与PHP功能混淆。 PHP Works服务器端并且一旦生成页面就不能改变任何东西。 Javascript可以在客户端使用,甚至可以在页面呈现后改变页面。



你说如果我可以访问div id范围或其他 ..

在jQuery中,可以获取 Div 的值,并可以提交以及表格数据,但你不需要走这条路线。简单的 $ _ POST [passengers]; 就可以了。


How do I get the value of my range slider that sits in a form?

I cant get a value from it by just asking from the name.

I use this JavaScript function to type out the value in the form beside the slider

    function showValue(newValue)    {
    document.getElementById("range").innerHTML=newValue;    }

Could I call from the div or something like that?

Edit! All right here we go, I'm sorry if I'm confusing you all, but English is not my native language. I will try and explain.

I have a contact form in HTML5, that submits the data to mail.php.

<input type="text" name="name"/>
<input type="email" name="email"/>

In mail.php I fetch the value from the input boxes by

$name = $_POST['name'];
$email = $_POST['email'];

And then processing further to send the actual mail.

So far, so good?

I have a Range Slider that determines how many passengers user want to book.

<input type="range" min="1" max="12" step="1" value="1" name="passengers" onchange="showValue(this.value)" />
<span id="range">1</span></p></div>

I use JavaScript function because I want to show the current selected value of the slider to the user as he/she progresses through the form.

But I myself of course want to get this value in mail.php to the send mail as well. I can`t request value from the range name. So I was wondering if maybe I could access the value from the div id range or something?

解决方案

So, You want a slider, which displays its current value alongside itself and when form is submitted, your action file (mail.php) gets/retrieves Slider's selected value to process further. Right??

I believe that because:

You titled your question Send HTML 5 range slider value to mail via php, I interpret it to How to get the value of this range-slider in mail.php.

You said that you get the Input text boxes' value by doing a $_POST["foo"] on them.

So, in the same way, Range Slider's value is also available in $_POST array. I assume that you are using action=POST , because you mentioned $name = $_POST['name']

So, to get the value of this particular Range Slider, use:

$range_slider_value = $_POST["passengers"];

Of course, you should look into sanitizing form input and all other types of foreign input.

A fully functional snippet, which displays the value on User's computer, as he/she changes the slider and on Form-submit, gives it to your mail.php is:

<form action="" method="POST">
    <input type="range" min="1" max="12" step="1" value="1" id="foo" name="passengers" onchange='document.getElementById("bar").value = "Slider Value = " + document.getElementById("foo").value;'/>
<input type="text" name="bar" id="bar" value="Slider Value = 1" disabled />
<br />
<input type=submit value=Submit />
</form>

<?php
if(isset($_POST["passengers"])){
    echo "Number of selected passengers are:".$_POST["passengers"];
    // Your Slider value is here, do what you want with it. Mail/Print anything..
} else{
Echo "Please slide the Slider Bar and Press Submit.";
}
?>

Live Demo at Codepad.viper-7.com

To quote http://www.html5tutorial.info/html5-range.php,
Value is a common attribute of "Input" element. The value can be any valid floating point number, not necessary must be an integer number. Default value is minimum value plus half of the maximum value.

Do not confuse Javascript functionality with PHP functionality. PHP Works Server-side and can't alter anything once a page is generated. Javascript works on Client-side, and can alter the page even after it is rendered.

You said if maybe I could access the value from the div id range or something..
In jQuery, it is possible to fetch the value of a Div and can submit along with the Form data, but you don't need to go that route. A simple $_POST["passengers"]; will do.

这篇关于如何在PHP中获取/获取HTML5 Range Slider的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆