Answer the question
In order to leave comments, you need to log in
How to submit data on a button?
Dear colleagues. I have a form
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => 'form-Office-reservd',
'enableAjaxValidation' => false,
'action' => "/site/Ocenka31",
'method' => "POST"
)); ?>
<div class="container container-brd-none">
<h2>Оцените качества обслуживания</h2>
<div class="containers">
<div class="tr">
<div class="table tbl_reserv">
<div class="td">В какое подразделение Вы бращались?</div>
<div class="td">
<select id="Office_type" class="default-field" name="Office[Office_type_id]">
<?php foreach ($Office_types as $Office_type): ?>
<option
value="<?php echo $Office_type->id ?>"
<?php echo ($selected_type->id == $Office_type->id) ? 'selected="selected"' : '' ?>
capacity="<?php echo $Office_type->capacity ?>"
>
<?php echo $Office_type->name; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="container reserv_info">
<button id="room-reservd2" type="button" class="button"
onclick="Ocenka($(this))">
<span class="btn-text">Неудовлетворительно</span>
</button>
<button id="Office-reservd" type="button" class="button"
onclick="Ocenka3($(this))">
<span class="btn-text">Удовлетворительно</span>
</button>
<button id="room-reservd4" type="button" class="button"
onclick="Ocenka($(this))">
<span class="btn-text">Хорошо</span>
</button>
<button id="room-reservd5" type="button" class="button"
onclick="Ocenka($(this))">
<span class="btn-text">Отлично</span>
</button>
<h2>Спасибо за вашу оценку!</h2>
</div>
<?php $this->endWidget(); ?>
</div>
function Ocenka3($el) {
console.log($el);
$el.jax(
function () {
//complete
}, function (data) {
//alert('Спасибо за Вашу оценку. мы учтем это в нашей работе.');
//$('#reserved_captha_button').click();
//$('#reserved_captha input').val('');
// $('#form-room-reservd input').val('');
},
function (data) {
// $('#reserved_captha_button').click();
// $('#reserved_captha input').val('');
for (key in data.message) {
// alert(data.message[key]);
}
});
}
$.fn.jax = function (complete, success, success_error) {
var $element = $(this);
var data, url;
var $form = $('#form-' + $element.attr('id'));
console.log($form);
if ($form.length !== 0) {
data = $form.serialize();
url = $form.attr('action')
}
button.disable($element);
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: data,
success: function (data) {
if (data != null)
if (data.status === 'success') {
if (typeof success !== "undefined") {
success(data);
}
} else {
if (typeof success_error !== "undefined") {
success_error(data);
} else {
for (key in data.message) {
alert(data.message[key]);
}
}
}
},
complete: function () {
button.undisable($element);
if (typeof complete !== "undefined") {
complete();
}
},
error: function () {
button.undisable($element);
alert("Непредвиденная ошибка");
}
});
return $element;
};
public function actionOcenka31($id=3)
{
$ocenka = new ocenka();
//if($_POST) { echo ''; print_r($_POST); echo ''; }
$ocenka->date_from=new CDbExpression('NOW()');
$ocenkas=OfficeType::model()->findByPk($_POST['Office']['Office_type_id']);
$ocenka->full_name=$ocenkas->name;
//$ocenka->ocenka='3';
$ocenka->save();
Yii::app()->user->setFlash('success',"Спасибо за Вашу оценку. мы учтем это в нашей работе");
$respons3 = array('status' => 'success');
echo json_encode($respons3);
}
<?php echo CHtml::button('Button Text', array('submit' => array('site/Ocenka3'))); ?>
<button id="Office-reservd" type="button" class="button" data-ocenka="3"
onclick="Ocenka3($(this))">
<span class="btn-text">Удовлетворительно</span>
</button>
public function actionOcenka31($id=3)
{
$ocenka = new ocenka();
if($_POST) { echo ''; print_r($_POST); echo ''; }
$ocenka->date_from=new CDbExpression('NOW()');
$ocenkas=OfficeType::model()->findByPk($_POST['Office']['Office_type_id']);
$ocenka->full_name=$ocenkas->name;
//$ocenka->ocenka='3';
$ocenka->ocenka=$_POST['Office']['Ocenka'];
$ocenka->save();
Yii::app()->user->setFlash('success',"Спасибо за Вашу оценку. мы учтем это в нашей работе");
$respons3 = array('status' => 'success');
echo json_encode($respons3);
}
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then by setting the name and value attributes for the buttons, you can solve the problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question