I have form add contestant where i have inputs name, surname, age, sex, weight and dropdownlist club
i try add html link with jquery
<?php echo CHtml::link('add club if doesn't exist on list','#',array('class'=>'add_club')); ?>
when i click on the link will show the name of the club field from model Club. When i fill all fields with club name, script do 1st query to club model add club name to tbl_club(id,name) then get id added club and do another query INSERT name,surname,age,sex and id added club.
<?php
/* @var $this ContestantController */
/* @var $model Contestant */
/* @var $form CActiveForm */
Yii::app()->clientScript->registerScript('search', "
$('.add_club').click(function(){
$('.add_club').toggle();
return false;
});
");
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'zawodnik-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,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>75)); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'surname'); ?>
<?php echo $form->textField($model,'surname',array('size'=>60,'maxlength'=>75)); ?>
<?php echo $form->error($model,'surname'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'club'); ?>
<?php $list = CHtml::listData(Klub::model()->findAll(), 'id', 'name'); ?>
<?php echo $form->dropDownList($model, 'club_id', $list); ?>
<?php echo CHtml::link('Add Club','#',array('class'=>'add_club')); ?>
<div class="add_club" style="display:none">
<!-- I WANT DISPLAY HERE LABEL CLUB NAME AND INPUT CLUB NAME FROM MODEL CLUB -->
</div>
<?php echo $form->error($model,'club'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget();?>
</div><!-- form -->
2nd problem is, how can i add result to table tbl_club value form field Club_Name
if(isset($_POST['club_name']){
insert to tbl_club
select id from tbl_club WHERE $_POST[club_name] = name
insert name, surname, club_id Value($_POST[name], $_POST[surname], result from select(club_id),)
} else {
instert all values from form to zawodnik (this query works)
}
ActionCreate
public function actionCreate()
{
$model=new Zawodnik;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Contestant']))
{
$model->attributes=$_POST['Contestant'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}