Hkm Sadek Hossain Hkm Sadek Hossain - 3 months ago 7
CSS Question

How to get values from a button

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?

Answer

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"]);
Comments