我有一个包含三个步骤的表单。在第 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 中发送和获取此值?
最佳答案
有一个名字是好的,也是必要的。
有两个问题。
- 您实际上需要有一个值才能发送一个值
- 您需要将按钮设为提交按钮才能提交表单
这样的:
<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/