phpformsradio-buttonmailing

send mail form - get value from radio button


I have already tried many solutions I found on this site but I can't seem to figure this out.

My radio buttons:

<input type="radio" id="radio1" name="apartman" />
<label for="radio1">Apartman 1</label>
<input type="radio" id="radio2" name="apartman" />
<label for="radio2">Sunny Shit 2</label>
<input type="radio" id="radio3" name="apartman" />
<label for="radio3">Penthouse</label>
<input type="radio" id="radio4" name="apartman" />
<label for="radio4">Rupčaga</label>
<input type="radio" id="radio5" name="apartman" />
<label for="radio5">Štala Gold Class</label>

And this is the PHP I got in mailing script:

$apartman = $_POST['apartman'];

The result I keep geting in my mail is:

Apartman: on

Result I want to get:

Apartman: [value of selected radio button]


Solution

  • The only thing that differenciates each of your radio buttons is the id attribute, however the ID is not used in calculating the form data, you also need to add a value attribute to each of your radio buttons, and you will get the desired effect:

    <input type="radio" id="radio1" name="apartman" value="radio1" />
    <label for="radio1">Apartman 1</label>
    <input type="radio" id="radio2" name="apartman" value="radio2" />
    <label for="radio2">Sunny Shit 2</label>
    <input type="radio" id="radio3" name="apartman" value="radio3" />
    <label for="radio3">Penthouse</label>
    <input type="radio" id="radio4" name="apartman" value="radio4" />
    <label for="radio4">Rupčaga</label>
    <input type="radio" id="radio5" name="apartman" value="radio5" />
    <label for="radio5">Štala Gold Class</label>