ajaxSubmitButton with database

Hi,

I am a newbie to web development. My basics are not very strong. But I am hoping to learn them as I go.

What i am trying to do is very simple.

  • I have a database set up with "email" as one of the columns(also has first and last name columns). This column has 5 test emails in it.

  • Now there is a view which has a form to create a new team. It has (two text fields for team name and member email) , (div to show added player) and (two buttons;one to add player(needs ajaxsubmission);second to submit the team, once all the players have been entered).

  • Captain enters the team name in the first text field.

  • (AJAX/JQUERY part)Captain enters an email of the player and press add player button , if the email is in the database, the first and last name of the player shows up in the div

  • (AJAX/JQUERY part) if email does not exist in the database, two text fields (first and last name), and two buttons(create player and cancel) show up. The created player will also needs to be added to database.

  • once the div has all the players, there should be an option to remove player(just from the div, not from database)

Thanks,

Vic

VIEW CODE

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(

'id'=&gt;'FormId',


'enableAjaxValidation'=&gt;TRUE,


'clientOptions'=&gt;array('validateOnSubmit'=&gt;TRUE),

)); ?>

<?php echo $form->errorSummary($model2,‘email’); ?>

<div id="data">

<?php $this->renderPartial(’_ajaxContent’, array(‘myValue’=>$myValue)); ?>

</div>

<div class="row">

    &lt;?php echo &#036;form-&gt;labelEx(&#036;model2,'team member email'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model2,'email'); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model2,'email'); ?&gt;

</div>

<?php echo CHtml::ajaxSubmitButton(’+’,CController::createUrl(‘home/UpdateAjax’),

                          array('update' =&gt; '#data')); ?&gt;

<?php $this->endWidget(); ?>

------------------------------**

Controller CODE

class HomeController extends Controller

{

public function actionIndex()


{


	


	&#036;model= new Teamname;


	


//	&#036;this-&gt;render('createteam',array('model'=&gt;&#036;model));


	


	&#036;model1= new Gametype;


	&#036;select = array(); 


	&#036;model1 = Gametype::model()-&gt;findAll();

// format models as $key=>$value with listData

  &#036;model2=new User;


    


	&#036;data = array();


   


    &#036;data[&quot;myValue&quot;] = &quot;Player status&quot;;


	


	&#036;this-&gt;render('createteam', array('model'=&gt;&#036;model,'model1'=&gt;&#036;model1,'model2'=&gt;&#036;model2,'select'=&gt;&#036;select,  'myValue'=&gt; &#036;data[&quot;myValue&quot;]));





	/*	if(isset(&#036;_POST['ajax']) )&amp;&amp; &#036;_POST['ajax']==='user-form')


	{


		echo CActiveForm::validate(&#036;model2);


		Yii::app()-&gt;end();


		


			


	}*/


	





}





public function actionUpdateAjax()





{


  &#036;data = array();


  &#036;model2=new User;


  if (isset(&#036;_POST['formId']))


  {


  &#036;model2-&gt;email=&#036;_POST['formId'];


  &#036;data[&quot;myValue&quot;]=&#036;model2;   	            &#036;this-&gt;renderPartial('_ajaxContent', &#036;data, false, true);


		


  }


  else &#036;data[&quot;myValue&quot;]='not happening';





 &#036;this-&gt;renderPartial('_ajaxContent', &#036;data, false, true);


}

}