How to know form submit sucessfully in yii - yii

i want to submit button disable when form submitted sucessfully, because user click submit button so many times when page loading so its saved the same records so many times.so i want to decided to when form submit sucessfully mean disable that submit button.i am also using aftervalidate function but it can't correct form submit successfull.
My Coding:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'question-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
'afterValidate' => 'js:buttondisable',
),
));
?>
<div class="form-group">
<?php echo $form->labelEx($model, 'question_title'); ?>
<?php echo $form->textField($model, 'question_title', array('size' => 50, 'maxlength' => 250, 'class' => 'form-control')); ?>
<?php echo $form->error($model, 'question_title'); ?>
</div>
<?php if ($tileAssigned == Yii::app()->const->FLAG_ZERO) { ?>
<div class="form-group">
<?php echo $form->labelEx($model, 'type', array('label' => 'Is Multiple Choice')); ?>
<?php echo $form->radioButtonList($model, 'type', $yesnoList, array('separator' => '', 'onchange' => 'questionTypeChange(this.value);', 'class' => '')); ?>
<?php echo $form->error($model, 'type'); ?>
</div>
But After validation function calling when validation done in every time,but i want to form submit sucessfully at this time disable button.

Related

Yii2 How can I display Activeform radioList data on screen?

I have not experience with Yii2.
I would like to be able to show the result of a form on the screen.
With the fields name and email I have no problem but I can not show the selection
that I make of my radioList.
I have tried many methods but none works.
Can you help me please?
These are my files.
SiteController.php
public function actionEntry()
{
$this->layout = 'print';
$model = new EntryForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
return $this->render('entry-confirm', ['model' => $model]);
} else {
return $this->render('entry', ['model' => $model]);
}
}
EntryForm.php
namespace app\models;
use Yii;
class EntryForm extends \yii\db\ActiveRecord
{
public $name;
public $email;
public $category;
public function rules()
{
return [
[['name', 'email'], 'required'],
['email', 'email'],
];
}
entry.php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'category')->radioList([
1 => 'radio 1',
2 => 'radio 2'
]);
?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
entry-confirm.php
<p>You have entered the following information:</p>
<ul>
<li><label>Name</label>: <?= Html::encode($model->name) ?></li>
<li><label>Email</label>: <?= Html::encode($model->email) ?></li>
<li><label>Category</label>: <?= Html::encode($model->category) ?></li>
</ul>
This is the image with the problem:
In model extending ActiveRecord you must never explicitly define properties that are the same as names of columns in DB.
You must define at least one validation rule for each attribute that is set by the end user, otherwise system will not allow to set it.

Onsubmit call function in yii

I want to call function when submit form in yii. In my form I enabled validateOnSubmit.
when in call function form Onsubmit mean it will call function in twice.
My Coding,
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'question-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
),
'htmlOptions' => array('onsubmit' => 'return checkmultiple()',),
));
?>
<div class="form-group">
<?php echo $form->labelEx($model, 'question_title'); ?>
<?php echo $form->textField($model, 'question_title', array('size' => 50, 'maxlength' => 250, 'class' => 'form-control')); ?>
<?php echo $form->error($model, 'question_title'); ?>
</div>
<?php if ($tileAssigned == Yii::app()->const->FLAG_ZERO) { ?>
<div class="form-group">
<?php echo $form->labelEx($model, 'type', array('label' => 'Is Multiple Choice')); ?>
<?php echo $form->radioButtonList($model, 'type', $yesnoList, array('separator' => '', 'onchange' => 'questionTypeChange(this.value);', 'class' => '')); ?>
<?php echo $form->error($model, 'type'); ?>
</div>
I am calling function checkmultiple mean it will call twice.
function checkmultiple()
{
}

YiiBooster modal Dataprovider Undefined

I am trying to load the index view from another model view in a modal window using yiibooster but the dataprovider of this model looks like it is undefined:
<?php $this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'documentacion')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Documentación</h4>
</div>
<?php
$doc = new ZfDocumentacionInmueble;
$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc));
?>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Cerrar',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
ERROR: Undefined variable: dataProvider
thanks!
ERROR:
C:\APP\htdocs\yii\yiitest\protected\views\zfDocumentacionInmueble\index.php(6)
1 <?php
2 /* #var $this ZfDocumentacionInmuebleController */
3 /* #var $dataProvider CActiveDataProvider */
4
5 $this->widget('zii.widgets.CListView', array(
6 'dataProvider'=>$dataProvider,
7 'itemView'=>'_view',
8 )); ?>
CONTROLLER CODE:
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('ZfDocumentacionInmueble');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
If the "real url" works, then the ZfDocumentacionInmueble::actionIndex()-function is creating a $dataProvider and passing it to the view.
In your renderPartial call, you do not pass on a $dataProvider. If you have created it in your controller action, be sure to pass it along (or otherwise you might have to copy the code from the other controller):
$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc, 'dataProvider' => $dataProvider));

CJuiDialog not closing in Ajax success

Im trying to close CJuiDialog in Ajax success but its not closing, only iframe contents gets cleared popup not closing,
CJuiDialog Coding:
<?php
$this->beginWidget('zii.Widgets.jui.CJuiDialog',array(
'id'=>'Document-Edit',
'options'=>array(
'title'=>'Manage Documents',
'autoOpen'=>false,
'modal'=>true,
'width'=>800,
'height'=>600,
// 'close'=>'js:function(e,o){location.reload();}' ,
),
));
?>
<iframe id="cru-frame-doc" width="100%" height="100%" frameBorder="0" scrolling="no" >
<?php $this->renderPartial('ManageDocuments_Update', array('model'=>$model)); ?>
</iframe>
<?php $this->endWidget();?>
CGridView Code:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'document-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'class' => 'CButtonColumn',
'template' => '{DocumentEdit}',
'buttons' => array(
'DocumentEdit' => array(
'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',
'url'=>'$this->grid->controller->createUrl("DocumentEdit", array("id"=>$data->crm_document_id,"asDialog"=>1))',
'click'=>'function(){
$("#cru-frame-doc").attr("src",$(this).attr("href")); $("#Document-Edit").dialog("open"); return false;}',
),
),),
'crm_document_id',
'name',
'doc_type',
'delivery_method',
'content_subject',
'content_body',
'is_active',
),
)); ?>
Ajax Submit Button Code:
<?php
echo CHtml::ajaxSubmitButton( 'Save',
'js:document.location.href='.'"'.Yii::app()->createUrl("baseContact/SaveManageDocuments_Update",array("id" => $model->crm_document_id)).'"',
array(
'type'=>'POST',
"dataType" => "json",
'success' => 'function(data){
if(data.result=="success"){
window.parent.$("#Document-Edit").dialog("close");
window.parent.$("#cru-frame-doc").attr("src","");
}
}',
));
?>
Can anyone point out where im making error...
Use the below code in SaveManageDocuments_Update Controller action to close the dialog,
echo CHtml::script("window.parent.$('#Document-Edit').dialog('close');window.parent.$('#cru-frame-doc').attr('src',''); window.parent.$.fn.yiiGridView.update('document-grid');");
Yii::app()->end();

Yii - How to display display captcha in CPortlet?

I'm using portlet to display contact form - the very same as is on static page which comes generated as standard. I'm using the same ContactForm model. The form displays but captcha is not displaying and reports "CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller."
I'm new to yii so it takes awfully lot of time to figure everything out. Any quick advice what I shell do to make it working?
Best!
Yii::import('zii.widgets.CPortlet');
class ContactFormCard extends CPortlet
{
public $title='Contact';
protected function renderContent()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
$this->controller->refresh();
}
$this->render('contactFormCard',array('model'=>$model));
}
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
);
}
}
and in portlet view:
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<?php endif; ?>
In you SiteController.php add:
public function actions() {
return array(
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,
),
// [...]
);
}
In you ContactForm.php add:
public function rules() {
return array(
// [...]
array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements(), 'message' => Yii::t('formsErros', 'Código de verificação incorreto.')),
// [...]
);
}
In you view.php
<!-- [...] -->
<?php if(CCaptcha::checkRequirements()): ?>
<div class="captcha">
<?=$form->labelEx($contactFormModel, 'verifyCode')?>
<?php $this->widget('CCaptcha', array('clickableImage' => true, 'showRefreshButton' => true, 'imageOptions' => array('id' => 'captchaContactForm', 'class' => 'clickableCursor'), 'buttonLabel' => '')); ?>
<?=$form->textField($contactFormModel, 'verifyCode', array('class' => 'verticalAlignBottom'))?>
<?=$form->error($contactFormModel, 'verifyCode')?>
</div>
<?php endif; ?>
<!-- [...] -->