I have form build with yii framework.
The first 2 inputs is “first_name” and “last_name” and I have many more inputs in the same form.
I’m checking validation with “ajaxSubmitButton” and I want to check first only “first_name” and “last_name” pass the validation and If they do next time when user will submit its would check all form.
Model -> rules
array('first_name, last_name', 'length', 'min'=>2 , 'on' => 'setup'),
array('first_name, last_name , email, subject , message', 'length', 'min'=>2 , 'on' => 'submit'),
Ajax Button on View ->
<?php echo CHtml::ajaxSubmitButton( 'Submit',
CHtml::normalizeUrl(array('SubmitForm')),
array(
'error'=>'js:function(){
alert(\'error\');
}',
'beforeSend'=>'js:function(){
alert(\'beforeSend\');
}',
'success'=>'js:function(data){
alert(data);
}',
'complete'=>'js:function(){
// alert(\'complete\');
}',
'update'=>'#updatebox',
) ,array('id'=>'submit')
);
?>
Controller >
public function actionMessageForm()
{
$model = new Message;
if(isset($_POST['Message']))
{
$model->attributes=$_POST['Message'];
$valid = $model->validate('setup');
if($valid)
{
echo "pass";
$model->save();
}
else
{
echo "failed";
}
}
}
How can I check partly inputs?
What I’m doing Wrong?
You have a bug in your controller. This:
should be this:
or this:
Does that help?