Jump to content
Larry Ullman's Book Forums

Missing Asterisk And Tabular Ajax Validation


Recommended Posts

Hi,

I have implemented a tabular input form by using two models - model(Booking) and item(BookingForm- multiple models are kept in an Items array). I pass model and Items to the booking form and loop through the items. Is this the correct way to implement this kindof form? BookingForm is an intermediary table.

 

All the functionality is working on the page, but there is a missing asterisk from next to the first form field. The other fields have their asterisks and I have set the required rules appropriately.

 

I also wondered if anyone could tell me about... CActiveForm::validateTabular(). I have implemented ajax validation for a single model, but the way I have implemented it for tabular data doesn't seem to work - adding Items as an arguement in performAjaxValidation($model, $items) then appending output onto the existing echo.

 

I am new to frameworks and Yii so I may not be doing the right thing.

 

 

Thanks,

 

James

Link to post
Share on other sites

Hi Larry, thanks for the reply. I've had a look at the asterisk problem and solved it - it was fairly simple I just entered the wrong variable for LabelEx attribute - it should have been 'roomId' not 'Room No'. Sorry about that.

 

I have completely changed my app now and what am I stuck with is getting validation to work for forms built with formbuilder. I have followed the section in your book, but validation messages won't display. Here is my code if you would be willing to look at it:

 

The form displays, but the validation error messages  won't display. -- Fixed this problem now. The button for submit was called 'Login' when it should have been submit.

 

 

'login'=>array(
'type'=>'submit',
'label'=>'Submit',
),

 

'submit'=>array(
'type'=>'submit',
'label'=>'Submit',
),

 

 

List action from Room controller

	public function actionList()
	{
            $model = new ListForm;
            $form = new CForm('application.views.site.listForm', $model);
            
            var_dump($model->arrive);
            if ($form->submitted() && $form->validate()) {
                                
                  $this->redirect(array('site/index'));

            } else{
            
            $this->render('list', array('model' => $model, 'form' => $form));
            }
	}

Array in listForm

<?php
return array(
    'title'=>'Please provide your login credential',
 
    'elements'=>array(
        'arrive'=>array(
            'type'=>'date',
            'required'=>true
            
        ),
        'email'=>array(
            'type'=>'date',
            'required'=>true
        ),
        'subject'=>array(
            'type'=>'checkbox',
            'required'=>true
        )
    ),
    
    
    
    'buttons'=>array(
        'login'=>array(
            'type'=>'submit',
            'label'=>'Submit',
        ),
    ),
);
        

	


public function rules()
	{
		return array(
			// name, email, subject and body are required
			array('arrive, email, subject', 'required')
			// email has to be a valid email address
			//array('email', 'email'),
			// verifyCode needs to be entered correctly
			//array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
		);
	}

Rules from the ListForm model ^ and the list form

<div class="form">
    
<?php echo $form; ?>
   
</div>
Link to post
Share on other sites
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...