How to return form value using Ajax

// Though I may think this is a kind of FAQ, I am asking here because I was not able to find a proper answer here.

I am making AJAX code like following example, and works fine unless passing a value via ajax.


Then, I would like to pass a value of the form to PHP using ajaxlink, and would like to know how.

Following is a ‘views/ldap/index.php’.

<div class="row">

    	<?php echo $form->labelEx($model,'en'); ?>

    	<?php echo $form->textField($model,'en'); ?>

    	<?php echo $form->error($model,'en'); ?>


<?php echo CHtml::ajaxLink('Get info', array('getLdap'), array('update' => '#ldap')





    	public function actionGetLdap()


          		$model=new Ldap;

          		$en = <img src='' class='bbc_emoticon' alt='???' /> // en is a enployee number, but don't know get how?

          		$info = $this->getCachedLdap($en);

          		$model = $this->processModel($info, $model);

          		$this->renderPartial('_ldap', array('model'=>$model));



The flow is as follows. As the code above, a user enters ‘enployee number’ (en) in the form and click ajaxlink. Then the javascript returns this en as Ldap[en] and call ‘actionGetLdap()’. I don’t know the way to get the value from the javascript. It may be JSON encoded but I am not sure.

Does anyone out there could kindly provide a suggestion to me? Thank you in advance.

use ajaxSubmitButton();

It should serialize the form data and send it in a post request.

<input type="text" name="myField" />

The forms data will be name value paired in the $_POST


Thanks alex-w :lol:, I should have added some informations though.

Suppose that the user enters en (employee number) as a user ID. Then the client system inquires the other informations such as user name, telephone number and so on to the LDAP server. Assume that the password is not stored in the server, the user has to enter it in the form.

In this situation, the user will enter en and click ajaxLink (or ajaxButton), and enter password. Everything has been entered, the user should click submit.

This is why I need the solution using AJAX without clicking the submit button.


I am a bit getting closer to the answer. According to the JQuery manual, there is a parameter of ‘data’ for ajax() as follows.

It seems that I can send the data using data parameter of JQuery ajax() method to PHP and get it from $_GET variables.

Setting the type as “POST” seems to be better than default “GET”, though I have not been succeeded to get the value of the form so far :(