I have the following problem. I have a form where I can choose from three options. The problem is that it does not send the selected option while the other sections Name, surname, etc. send. Below I am sending the code: thank you in advance
我有以下问题。我有一个表格,我可以从三个选项中选择。问题是它不发送选定的选项,而其他部分名称,姓氏等发送。下面我发送代码:提前谢谢你
<div class="col-sm-4">
<div class="dropdown">
<button class="btn btn-dropdown dropdown-toggle" type="button" id="service-type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="drp-name" data-bind="label">Choose</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="service-type">
<li><a href="#">x1</a></li>
<li><a href="#">x2</a></li>
<li><a href="#">x3</a></li>
</ul>
</div>
</div>
php code:
php代码:
<?php
$to = 'xxx@xx.com';
$subject = "Appointment Form";
$servicetype = stripslashes($_REQUEST['service-type']);
$msg = "";
$msg .= "Service Type: ".$servicetype."\r\n\n"; // add sender's sources to the message
$mail = @mail($to, $subject, $msg, "From:".$email);
if($mail) {
header("Location:index.html");
} else {
echo 'Message could not be sent!';
}
?>
I also added JS but it still does't work
我还添加了JS,但它仍然无法正常工作
Dropdown Select
$( document.body ).on( 'click', '.dropdown-menu li', function( event ) {
var $target = $( event.currentTarget );
$target.closest( '.dropdown' )
.find( '[data-bind="label"]' ).text( $target.text() )
.end()
.children( '.dropdown-toggle' ).dropdown( 'toggle' );
return false;
});
3 个解决方案
#1
1
HTML:
HTML:
<div class="col-sm-4">
<div class="dropdown">
<button class="btn btn-dropdown dropdown-toggle" type="button" id="service-type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="drp-name" data-bind="label">Rodzaj usługi</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="service-type">
<li><a href="#">x1</a></li>
<li><a href="#">x2</a></li>
<li><a href="#">x3</a></li>
</ul>
</div>
<input type='hidden' name='service-type'> <!-- ADD THIS -->
</div>
JavaScript:
JavaScript的:
$(document.body).on('click', '.dropdown-menu li', function(event) {
event.preventDefault();
var $target = $(event.currentTarget);
$target.parents('.dropdown').sibling('[name=service-type]').val($target.text());
});
});
#2
0
you cant pass values to php without name attribute and form tag . you can directly set it with select
tag
你不能将值传递给没有名称属性和表单标签的PHP。你可以用select标签直接设置它
<form action="file.php" method=POST>
<select name=option>
<option value=0 selected>0</option>
<option value=1> 1</option>
</select><input type=button value=submit>
</form>
#3
0
Suppose the name of form is mail_form
, and there is a hidden form element to hold the choice information with id service-type-holder
and name service-type
. Then the following code could be used with inline Javascript:
假设表单的名称是mail_form,并且有一个隐藏的表单元素来保存具有id service-type-holder和name service-type的选择信息。然后以下代码可以与内联Javascript一起使用:
<form name="mail_form" id="mail_form" action="" method="post">
<input type="hidden" name="service-type" id="service-type-holder">
<div class="col-sm-4">
<div class="dropdown">
<button class="btn btn-dropdown dropdown-toggle" type="button" id="service-type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="drp-name" data-bind="label">Choose</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="service-type">
<li onclick="$('#service-type-holder').val('x1'); $('#mail_form').submit()"><a href="#">x1</a></li>
<li onclick="$('#service-type-holder').val('x2'); $('#mail_form').submit()"><a href="#">x2</a></li>
<li onclick="$('#service-type-holder').val('x3'); $('#mail_form').submit()"><a href="#">x3</a></li>
</ul>
</div>
</div>
#1
1
HTML:
HTML:
<div class="col-sm-4">
<div class="dropdown">
<button class="btn btn-dropdown dropdown-toggle" type="button" id="service-type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="drp-name" data-bind="label">Rodzaj usługi</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="service-type">
<li><a href="#">x1</a></li>
<li><a href="#">x2</a></li>
<li><a href="#">x3</a></li>
</ul>
</div>
<input type='hidden' name='service-type'> <!-- ADD THIS -->
</div>
JavaScript:
JavaScript的:
$(document.body).on('click', '.dropdown-menu li', function(event) {
event.preventDefault();
var $target = $(event.currentTarget);
$target.parents('.dropdown').sibling('[name=service-type]').val($target.text());
});
});
#2
0
you cant pass values to php without name attribute and form tag . you can directly set it with select
tag
你不能将值传递给没有名称属性和表单标签的PHP。你可以用select标签直接设置它
<form action="file.php" method=POST>
<select name=option>
<option value=0 selected>0</option>
<option value=1> 1</option>
</select><input type=button value=submit>
</form>
#3
0
Suppose the name of form is mail_form
, and there is a hidden form element to hold the choice information with id service-type-holder
and name service-type
. Then the following code could be used with inline Javascript:
假设表单的名称是mail_form,并且有一个隐藏的表单元素来保存具有id service-type-holder和name service-type的选择信息。然后以下代码可以与内联Javascript一起使用:
<form name="mail_form" id="mail_form" action="" method="post">
<input type="hidden" name="service-type" id="service-type-holder">
<div class="col-sm-4">
<div class="dropdown">
<button class="btn btn-dropdown dropdown-toggle" type="button" id="service-type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="drp-name" data-bind="label">Choose</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="service-type">
<li onclick="$('#service-type-holder').val('x1'); $('#mail_form').submit()"><a href="#">x1</a></li>
<li onclick="$('#service-type-holder').val('x2'); $('#mail_form').submit()"><a href="#">x2</a></li>
<li onclick="$('#service-type-holder').val('x3'); $('#mail_form').submit()"><a href="#">x3</a></li>
</ul>
</div>
</div>