Hello. How set in true validateOnSubmit?
<?php $form = $this->beginWidget('CActiveForm', array('id'=>'form','enableAjaxValidation'=>true,'clientOptions'=>array('validateOnSubmit'=>true))) ?>
dont work.
Hello. How set in true validateOnSubmit?
<?php $form = $this->beginWidget('CActiveForm', array('id'=>'form','enableAjaxValidation'=>true,'clientOptions'=>array('validateOnSubmit'=>true))) ?>
dont work.
It should be validateOnSubmit, not validateonsubmit (note letter cases)
Thanks
Bug: CActiveForm messes up CCaptcha
Every ajax form validation request generates a captcha validation so the displayed captcha code is no longer valid when the form is gonna be submitted.
this should somehow be avoided, maybe with some sort of rule option for captchas.
maybe with something that prevents captcha validation from being executed during an ajax request or during a foreign call via CActiveForm::validate($model)
i go with scenarios for now
–
and look promising so far
BUG: form is not submitted (send data to server directly without ajax) if
'validateOnSubmit' => true, // (letter-case specified correctly)
Qiang, please, change default value for $buttonName in
$CForm->submitted($buttonName='submit')
if element with name “submit” is presented in form, form isn’t submitted (using $(‘form’).submit())!
patch for jquery.yiiactiveform.js:
// in initialization
$form.find(':submit').bind('mouseup keyup',function(){
$form.get(0).activeElement=this;
});
// for correct submit
($form.get(0).activeElement||$form.find(':submit:first')).click();
This is expected as described in the API documentation.
Using scenario to skip the validation of captcha is one way to go. The other way is to list the attributes to be validated when calling CActiveForm::validate()
Do you still have problem with "validateOnSubmit"?
There’s a successCssClass option. You can use this CSS to toggle the visibility of success message.
I will take a look. But where did you get $form->submited() method? There’s no such method in CForm.
Qiang, try to check your code of CForm.php:
Hi (and sorry form my english),
I’m using CActiveForm and it seems that ‘inputContainer’ option passed in array to the CActiveForm->error() doesn’t work.
$form->error($model,'cityId', array('inputContainer'=>'#postalcode'));
When I open file ‘framework/web/js/source/jquery.yiiactiveform.js’ the getInputContainer function looks like this:
...
$.each(settings.attributes, function(i,attribute){
settings.attributes[i] = $.extend({
...
hideErrorMessage : settings.hideErrorMessage,
inputContainer : settings.inputContainer,
errorCssClass : settings.errorCssClass,
...
}, attribute);
...
var getInputContainer = function(attribute) {
if(attribute.container == undefined)
return $('#'+attribute.inputID).closest('div');
else
return $(attribute.container]).filter(':has("#'+attribute.inputID+'")');
};
Shouldn’t attribute.container looks like attribute.inputContainer?
When I change this code, ‘inputContainer’ works.
We are talking about CActiveForm in this thread. It’s not CForm.
Hi,
tried the CActiveForm Widget.
But the AJAX didnt worked.
there is no javaScript loaded when i used this Widget
<?php $form = $this->beginWidget('CActiveForm'?>
i used Yii 1.1.0 (January 10, 2010) and copy the CActiveForm class to my
framework/web/widgets Folder but i get an error that
include(CActiveForm.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory
when i copy that class to my models folder than i got no error but the widget doesnt worked
javascript not loaded.
regards james
View
<div class="row">
<?php $form = $this->beginWidget('CActiveForm', array('id'=>'person-form')); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo CHtml::activeLabelEx($model,'Vorname:'); ?>
<?php echo CHtml::activeTextField($model,'vname'); ?>
</div>
<div class="row">
<?php echo CHtml::activeLabelEx($model,'Nachname:'); ?>
<?php echo CHtml::activeTextField($model,'nname'); ?>
</div>
<div class="row">
<?php echo CHtml::activeLabelEx($model,'Email:'); ?>
<?php echo CHtml::activeTextField($model,'email'); ?>
</div>
<div class="row submit">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
controller
public function actionIndex()
{
$model=new PersonForm;
$this->performAjaxValidation($model);
if(isset($_POST['PersonForm']))
{
$model->attributes=$_POST['PersonForm'];
// validate user input and redirect to the previous page if valid
if($model->validate())
echo "validate";
}
$this->render('index',array('model'=>$model));
}
Qiang, CForm and CActiveForm linked together (if we use ajax and “submit”-validation both), if CForm has button with “submit” name, CActiveForm ($form.submit()) isn’t submitted in general!
try to test this piece of code (in FF etc.):
<form id="test" method="POST">
<input type="submit" name="submit" value="CLICK!" />
</form>
<script type="text/javascript">
/*<![CDATA[*/
jQuery(function(){
$('#test').submit();
});
/*]]>*/
</script>
You shouldn’t mix files from different framework versions. It’s better to use a separate svn checkout.
You also need this setting for ajax validation to work:
<?php $form=$this->beginWidget('CActiveForm', array(
'enableAjaxValidation'=>true,
)); ?>
I see what you mean. It has nothing to do with the naming of the button. It’s actually a problem with how to know which button is pressed to trigger form submission using javascript. Unfortunately, according to my study, there is no reliable way to detect this in form submit event. When enabling validationOnSubmit, the form will be submitted using javascript, which will cause the missing of the clicked button value in submitted data.
As a workaround, if you have several very similar forms (e.g. all related with the same type of model), you may add a hidden field in each form to differentiate them.
Qiang, check my post #26 - I proposed solution ("patch for jquery.yiiactiveform.js" section).
That’s not a reliable solution. activeElement is not supported by all browsers.