Jump to content
Larry Ullman's Book Forums

weno

Members
  • Posts

    8
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by weno

  1. 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>
  2. 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
  3. Please ignore this I am past this stage now
  4. Hi, I have run into another problem. I have begun implementing the master detail form. In the create.php form I have duplicated rows(HTML and fields) which are for user input, but this causes the highlighted fields(that have been chosen in the last form submission) on the webpage to duplicate... if I choose a value in the first row it automatically chooses the same in the second row. I use two models - both of them are passed to the form. <?php /* @var $this BookingController */ /* @var $model Booking */ $this->breadcrumbs=array( 'Bookings'=>array('index'), 'Create', ); $this->menu=array( array('label'=>'List Booking', 'url'=>array('index')), array('label'=>'Manage Booking', 'url'=>array('admin')), ); ?> <h1>Create Booking</h1> <?php //$this->renderPartial('_form', array('model'=>$model)); ?> <?php /* @var $this BookingController */ /* @var $model Booking */ /* @var $form CActiveForm */ ?> <div class="form"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'booking-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'=>false, )); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model,'Id'); ?> <?php echo $form->textField($model,'Id'); ?> <?php echo $form->error($model,'Id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'customerId'); ?> <?php echo $form->textField($model,'customerId'); ?> <?php echo $form->error($model,'customerId'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'date'); ?> <?php echo $form->textField($model,'date'); ?> <?php echo $form->error($model,'date'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'Room No'); ?> <?php echo $form->dropDownList($BookingRoom, 'roomId', CHtml::listData( Room::model()->findAll(), 'id', 'id'), array('single'=>'single', 'size'=>5) ); ?> <?php echo $form->error($BookingRoom,'roomId'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'startDate'); ?> <?php echo $form->textField($BookingRoom,'startDate'); ?> <?php echo $form->error($BookingRoom,'startDate'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'endDate'); ?> <?php echo $form->textField($BookingRoom,'endDate'); ?> <?php echo $form->error($BookingRoom,'endDate'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'adults'); ?> <?php echo $form->dropDownList($BookingRoom, 'adults', array('1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5'), array('single'=>'single', 'size'=>5) ); ?> <?php echo $form->error($BookingRoom,'adults'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'children'); ?> <?php echo $form->dropDownList($BookingRoom, 'children', array('1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5'), array('single'=>'single', 'size'=>5) ); ?> <?php echo $form->error($BookingRoom,'children'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'Room No'); ?> <?php echo $form->dropDownList($BookingRoom, 'roomId', CHtml::listData( Room::model()->findAll(), 'id', 'id'), array('single'=>'single', 'size'=>5) ); ?> <?php echo $form->error($BookingRoom,'roomId'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'startDate'); ?> <?php echo $form->textField($BookingRoom,'startDate'); ?> <?php echo $form->error($BookingRoom,'startDate'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'endDate'); ?> <?php echo $form->textField($BookingRoom,'endDate'); ?> <?php echo $form->error($BookingRoom,'endDate'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'adults'); ?> <?php echo $form->dropDownList($BookingRoom, 'adults', array('1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5'), array('single'=>'single', 'size'=>5) ); ?> <?php echo $form->error($BookingRoom,'adults'); ?> </div> <div> <?php echo $form->labelEx($BookingRoom,'children'); ?> <?php echo $form->dropDownList($BookingRoom, 'children', array('1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5'), array('single'=>'single', 'size'=>5) ); ?> <?php echo $form->error($BookingRoom,'children'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?> </div> <?php $this->endWidget(); ?> </div><!-- form -->
  5. Solved this now - empty dropdowns.
  6. I've followed Larry's example and trying to apply it to my own application . The dropdown box on my update form is displaying, but there aren't any values in the dropdown.
  7. I have already implemented the relationships in the Booking model. I'm looking to get started with the next step. Such as Handling related models in Yii forms - http://www.larryullman.com/2010/08/10/handling-related-models-in-yii-forms/ but I see that Larry has got different kindof mapped many-to-many relationship in his example.
  8. I have three tables in my database booking, bookingrooms, room and the bookingrooms is the link table resolving many to many. CRUD has created forms for booking and room, but the booking form is too simple and does not include the bookingrooms section that I want in the form. How do I put this area onto the booking form? I presume it's something to do with multiple models and custom forms.
×
×
  • Create New...