如何将可切换的html按钮发布到php
我正在尝试制作一个html/php电子邮件表单,其中包括多个文本字段、4个可切换按钮和一个提交按钮。我成功地让按钮在单击时改变状态,但我不知道如何检查按钮是否在PHP中被按下 这是我所有按钮的html代码。它们包装在一个包含submit按钮和其他文本字段的表单中。我还尝试将按钮标记更改为输入标记如何将可切换的html按钮发布到php,php,html,Php,Html,我正在尝试制作一个html/php电子邮件表单,其中包括多个文本字段、4个可切换按钮和一个提交按钮。我成功地让按钮在单击时改变状态,但我不知道如何检查按钮是否在PHP中被按下 这是我所有按钮的html代码。它们包装在一个包含submit按钮和其他文本字段的表单中。我还尝试将按钮标记更改为输入标记 <section> <button class="btn service-button" name="app" value="Web App" type="button">
<section>
<button class="btn service-button" name="app" value="Web App" type="button">Web App</button>
<button class="btn service-button" name="brand" value="Branding" type="button">Branding</button>
<button class="btn service-button" name="design" value="Web Design" type="button">Web Design</button>
<button class="btn service-button" name="other" value="Other" type="button">Other</button>
</section>
我尝试了一个vardump($\u POST);但它们显然甚至没有被添加到$u帖子中。
你知道我能做些什么让他们把数据提交到$\u的帖子上吗?我在考虑做一些事情,比如:
if(class_exists('active-button')) {
$service .= //Set data here somehow.
}
但我不太确定我会怎么做,因为有四个不同的按钮,可以选择它们的任何组合
此外,我认为这不会影响任何事情,但下面是我的jquery,用于更改按钮:
if(isset($_POST['app'])) {
$service .= $_POST['app'];
}
if(isset($_POST['brand'])) {
$service .= ", " . $_POST['brand'];
}
if(isset($_POST['design'])) {
$service .= ", " . $_POST['design'];
}
if(isset($_POST['other'])) {
$service .= ", " . $_POST['other'];
}
$(".btn").click(function() {
//Add/remove active-button and service-button. Replaces one with the
//other depending on the current state.
$(this).toggleClass("active-button").toggleClass("service-button");
});
active button和service button类只在css中使用,将按钮的样式更改为添加隐藏输入,并在单击按钮时更改隐藏值并提交隐藏字段 HTML PHP
你为什么不在工作中使用单选按钮呢?不确定我是否只是被误导了,但我希望我的按钮有某种风格,而我还不能用单选按钮做到这一点。下面是它们目前的样子:你可以按照你想要的样式设计单选按钮,但是,基于javascript的解决方案也是可能的。不用担心。找到了如何使用按钮的方法。看下面的答案。是的。gr8一切都解决了。这正是我想要的。非常感谢你。我做了一些更改,使其在再次单击按钮时删除属性值。我会立即为其他和我有相同问题的人编辑你的帖子。
<section>
<input class="selected_button" name="selected_button" value="" type="hidden">
<button class="btn service-button" name="app" value="Web App" type="button">Web App</button>
<button class="btn service-button" name="brand" value="Branding" type="button">Branding</button>
<button class="btn service-button" name="design" value="Web Design" type="button">Web Design</button>
<button class="btn service-button" name="other" value="Other" type="button">Other</button>
</section>
//On button click
$(".btn").click(function() {
//The string to add to the selected-button value
var toAdd = $(this).attr("value");
//Add/remove active-button and service-button. Replaces one with the
//other depending on the current state.
$(this).toggleClass("active-button").toggleClass("service-button");
//Checks if the button has already been added in case the user deselects the button
if($(".selected_button").val().indexOf(toAdd) >= 0) {
//Removes the comma and text
$(".selected_button").val($(".selected_button").val().replace((', ' + toAdd), ''));
//If the button is being added for the first time
} else {
//Adds the comma and text
$(".selected_button").val($(".selected_button").val() + ", " + toAdd);
}
});
<?php
$selected = $_POST['selected_button'];
if(isset($_POST['selected_button'])) {
$service .= $selected;
}
?>
you use radio buttons by using css style you can display like button