php - 如何从按钮中获取值

标签 php html css

我有一个包含三个步骤的表单。在第 2 步中,我要求用户通过单击相应的按钮来选择专业。如果他们点击一个按钮,他们应该移动到第 3rd 也是最后一步。

这是按钮代码:

<button class="btn btn-primary nextBtn btn-proffessional "
        type="button" name="hair_stylist" >HAIR STYLIST</button>
<button class="btn btn-primary nextBtn btn-proffessional " 
        type="button" name="cosmetologist" >COSMETOLOGIST</button>
<button class="btn btn-primary nextBtn btn-proffessional " 
        type="button" name="makeup_artist" >MAKEUP ARTIST</button>
<button class="btn btn-primary nextBtn btn-proffessional " 
        type="button" name="barber" >BARBER</button>
<button class="btn btn-primary nextBtn btn-proffessional " 
        type="button" name="esthetician" >ESTHETICIAN</button>
<button class="btn btn-primary nextBtn btn-proffessional " 
        type="button" name="nail_technitian" >NAIL TECHNITIAN</button>

我认为名称在这里不起作用。 data-* 有什么可以做的吗?提交表单时如何在 PHP 中发送和获取此值?

最佳答案

有一个名字是好的,也是必要的。

有两个问题。

  1. 您实际上需要有一个值才能发送一个值
  2. 您需要将按钮设为提交按钮才能提交表单

这样的:

<button 
    class="btn btn-primary nextBtn btn-proffessional"
    type="submit" 
    name="profession"
    value="hair_stylist">
        Hair Stylist 
</button>

然后在 PHP 中你可以简单地:

do_something_with($_POST["profession"]);

关于php - 如何从按钮中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38952591/

相关文章:

javascript - jQuery:出列特定动画

php - PHP 中的单例模式....如何在请求之间保存状态

Jquery 简写 IF-ELSE

html - 以 Angular 将自定义宽度应用于 html 模板中的 primeng p 列

javascript - 轮播的分类系统?

css - 如何包含不同语言的 webfont

javascript - 重新调整有效 JSON 时调用的 Ajax 错误回调

PHP Mysql自动报价?

php - Javascript - 在页面加载期间且仅在页面加载期间发生的 Onclick 事件

html - 输入元素占用额外空间