Answer the question
In order to leave comments, you need to log in
Passing buttons-checkbox values to php handler?
Good afternoon!
I am using Bootstrap. There is a form on the page, with buttons-checkbox elements .
The results of the form are passed to the php handler, which sends an email.
The problem is that the buttons-checkbox elements are not checkbox , so they are not passed by classical means.
Therefore, the question is: how to pass the value of the pressed buttons to 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">Опция 1</div>
<div class="btn btn-mini" value="value_2">Опция 2</div>
<div class="btn btn-mini" value="value_3">Опция 3</div>
<div class="btn btn-mini" value="value_4">Опция 4</div>
<div class="btn btn-mini" value="value_5">Опция 5</div>
</div>
</div>
<button class="btn btn-success" type="submit">Отправить</button>
</form>
<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">Опция 1</label>
<input id="option_2" type="checkbox" name="checkbox[]" value="value_2"/>
<label class="btn btn-mini" for="option_2">Опция 2</label>
<input id="option_3" type="checkbox" name="checkbox[]" value="value_3"/>
<label class="btn btn-mini" for="option_3">Опция 3</label>
<input id="option_4" type="checkbox" name="checkbox[]" value="value_4"/>
<label class="btn btn-mini" for="option_4">Опция 4</label>
<input id="option_5" type="checkbox" name="checkbox[]" value="value_5"/>
<label class="btn btn-mini" for="option_5">Опция 5</label>
</div>
</div>
<button class="btn btn-success" type="submit">Отправить</button>
</form>
Answer the question
In order to leave comments, you need to log in
Hidden checkboxes? When you click on the div, the value of the checkbox changes
<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">Опция 1</div>
<div class="btn btn-mini" value="value_2">Опция 2</div>
<div class="btn btn-mini" value="value_3">Опция 3</div>
<div class="btn btn-mini" value="value_4">Опция 4</div>
<div class="btn btn-mini" value="value_5">Опция 5</div>
</div>
</div>
<button class="btn btn-success" type="submit">Отправить</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());
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question