dousi2553 2016-08-15 09:31 采纳率: 0%
浏览 22
已采纳

如何从按钮获取值

I have a form which goes through three steps. In step 2, I am asking the user to select a speciality by clicking the corresponding button. If they click a button, they should move to the 3rd and final step.

Here is the button code:

<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>

I don't think name will work here. Is there anything that can be done with data-*? How can I send and grab this value in PHP when the form is submitted?

  • 写回答

3条回答 默认 最新

  • doutang2017 2016-08-15 09:34
    关注

    Having a name is fine and necessary.

    There are two problems.

    1. You need actually have a value in order to send a value
    2. You need the button to be a submit button in order to submit the form

    Such:

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

    Then in PHP you can simply:

    do_something_with($_POST["profession"]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?