您好我的表格在我的表格末尾附近,我的幻灯片中的php中的集合值有点问题。滑块代码结构:
<section1>
<label class="label">Simple <p style="float:right">Complex</p></center></label>
<div id="slider1" name="slider1"></div>
</section1>
<section1>
<label class="label">Playful <p style="float:right">Serious</p></center></label>
<div id="slider2" name="slider2"></div>
</section1>
Javascript
$(function()
{
// Regular slider
$('#slider1').slider({
min: 0,
max: 100,
values: [50],
slide: function(event, ui)
{
$('#slider1-value').text(ui.value);
}
});
$('#slider2').slider({
min: 0,
max: 100,
values: [50],
slide: function(event, ui)
{
$('#slider1-value').text(ui.value);
}
});
PHP:
我没有从slider1
获得任何值,使用此代码结构,我该怎么办?我不熟悉php,任何javascript或jquery?
提前致谢
答案 0 :(得分:1)
您的POST请求中没有slider1
值,因为没有form field slider1
。
您需要做的是添加hidden form element
并在移动滑块时填充它。
像这样:
HTML:
<section1>
<label class="label">Simple <p style="float:right">Complex</p></center></label>
<div id="slider1" name="slider1"></div>
<input type="hidden" id="slider1-value" name="slider1-value" />
</section1>
<section1>
<label class="label">Playful <p style="float:right">Serious</p></center></label>
<div id="slider2" name="slider2"></div>
<input type="hidden" id="slider2-value" name="slider2-value" />
</section1>
使用Javascript:
$(function()
{
// Regular slider
$('#slider1').slider({
min: 0,
max: 100,
values: [50],
slide: function(event, ui)
{
$('#slider1-value').val(ui.value);
}
});
$('#slider2').slider({
min: 0,
max: 100,
values: [50],
slide: function(event, ui)
{
$('#slider2-value').val(ui.value);
}
});
PHP:
<?php
if(isset($_POST['name'])) {
$to = 'myemail@gmail.com';
$subject = 'My Form';
$headers = 'From: ' . $_POST['email'] . "\r\n" . 'Reply-To: ' . $_POST['email'];
$message = 'Name: ' . $_POST['name'] . "\n" .
'Surname: ' . $_POST['surname'] . "\n" .
'E-mail: ' . $_POST['email'] . "\n" .
'Phone: ' . $_POST['phone']. "\n" .
'Country: ' . $_POST['country']. "\n" .
'Web Site : ' . $_POST['url']. "\n" .
'Simple vs Complex : ' . $_POST['slider1-value']. "\n";
mail($to, $subject, $message, $headers);
if($_POST['copy'] == 'on') {
mail($_POST['email'], $subject, $message, $headers);
}
}
?>
答案 1 :(得分:1)
The .text() method cannot be used on form inputs or scripts。之后
<div id="slider1" name="slider1"></div>
添加
<input type='hidden' name='slider1val' id='slider1val' value='0' /> <!-- change value to initial -->
然后改变
$('#slider1-value').text(ui.value);
到
$('#slider1val').val(ui.value);
在您的PHP中$_POST['slider1val']
将获得值。