Passing values buttons-checkbox in php handler?

Good day!

Am Using Bootstrap. On the page there are form elements buttons-checkbox.

The form results are passed to a php handler that sends an email.


The problem is that the elements buttons-checkbox are not a checkbox, so the classical means are not transmitted.

So the question is: how to send value of the clicked buttons in the php handler?
<form class="form form-horizontal" method="POST" action="callback.php">
 <div class="controls">
 <div class="btn-group" data-toggle="buttons-checkbox">
 <div class="btn btn-mini" value="value_1">Option 1</div>
 <div class="btn btn-mini" value="value_2">Option 2</div>
 <div class="btn btn-mini" value="value_3">Option 3</div>
 <div class="btn btn-mini" value="value_4">Option 4</div>
 <div class="btn btn-mini" value="value_5">Option 5</div>
</div>
</div>
 <button class="btn btn-success" type="submit">Send</button>
</form>


UPD:

Solved the problem using hidden checkbox's.
<form class="form form-horizontal" method="POST" action="callback.php">
 <div class="controls">
 <div class="btn-group" data-toggle="buttons-checkbox">
 <input id="option_1" type="checkbox" name="checkbox[]" value="value_1">
 <label class="btn btn-mini" for="option_1">Option 1</label>
 <input id="option_2" type="checkbox" name="checkbox[]" value="value_2">
 <label class="btn btn-mini" for="option_2">Option 2</label>
 <input id="option_3" type="checkbox" name="checkbox[]" value="value_3">
 <label class="btn btn-mini" for="option_3">Option 3</label>
 <input id="option_4" type="checkbox" name="checkbox[]" value="value_4">
 <label class="btn btn-mini" for="option_4">Option 4</label>
 <input id="option_5" type="checkbox" name="checkbox[]" value="value_5">
 <label class="btn btn-mini" for="option_5">Option 5</label>
</div>
</div>
 <button class="btn btn-success" type="submit">Send</button>
</form>
October 3rd 19 at 02:51
2 answers
October 3rd 19 at 02:53
Solution
Hidden checkboxes? When clicking on the div, the value of the checkbox changes
I think it should be more simple and elegant solution. No wonder buttons-checkbox in bootstrap enabled.
Hidden checkboxes in the most extreme case) - Garnett_Deckow commented on October 3rd 19 at 02:56
Standard simple solution.
github.com/twitter/bootstrap/issues/1161 and the link from there jsfiddle.net/charettes/SauLj/ - Ron_Larson commented on October 3rd 19 at 02:59
October 3rd 19 at 02:55
<form class="form form-horizontal" method="POST" action="callback.php">
 <div class="controls">
 <div class="btn-group" data-toggle="buttons-checkbox" name="my_name">
 <div class="btn btn-mini" value="value_1">Option 1</div>
 <div class="btn btn-mini" value="value_2">Option 2</div>
 <div class="btn btn-mini" value="value_3">Option 3</div>
 <div class="btn btn-mini" value="value_4">Option 4</div>
 <div class="btn btn-mini" value="value_5">Option 5</div>
</div>
</div>
 <button class="btn btn-success" type="submit">Send</button>
</form>


$(function(){
$('.btn-group[data-toggle="buttons-checkbox"]').each(function(){
 var name = $(this).attr('name');
 var def_val= $(this).find('btn:eq(0)');
$(this).add('input').attr({'name':name,'type':'hidden'}).vla(def_val);
});
});
$('.btn-group .btn').live('click',function(){
$(this).parent().find('input').val($(this).val());
});


Something like this. Input can be manually added.
<form class="form form-horizontal" method="POST" action="callback.php">
 <div class="controls">
 <div class="btn-group" data-toggle="buttons-checkbox">
 <div class="btn btn-mini" value="value_1">Option 1</div>
 <div class="btn btn-mini" value="value_2">Option 2</div>
 <div class="btn btn-mini" value="value_3">Option 3</div>
 <div class="btn btn-mini" value="value_4">Option 4</div>
 <div class="btn btn-mini" value="value_5">Option 5</div>
</div>
 <input type="hidden" name="my_name" value>
</div>
 <button class="btn btn-success" type="submit">Send</button>
</form>


$('.btn-group .btn').live('click',function(){
$(this).parent().find('input[name="my_name"]').val($(this).val());
});
- Garnett_Deckow commented on October 3rd 19 at 02:58

Find more questions by tags HTMLBootstrapPHP