Modify Textfield

I have an employee table (ID, SSN, name) and an assignment table. I can assign employees to locations in the assignment table. You can only see info on employees that are already at your location. If you know the SSN of the employee it is assumed that you can have access to that employee info and make an assignment.

I want the enteree to enter a SSN, Yii looks it up to see that it is valid and in the employee table, then returns the name to the _form so that the enteree can see the name and know they entered it right. And the employee_ID is available to the model. I added employee_ssn as a variable to the model.

It doesn’t seem to be calling the controller as I get no var_dump. (First problem)

Would this be the right way to display the name?

So I have my assignment form


   

<?php

    echo $form->labelEx($model, 'employee_ssn');

    echo $form->textField($model, 'employee_ssn', array(

       'ajax' => array(

          'type'=>'POST', //request type

          'url' => CController::createUrl('getName'), //url to call.

          'success'=>'js:function(data) { $("#assignment_employee_ssn").val(data); }',

       )

    ));

    echo $form->error($model, 'employee_ssn');

Controller


public function actionGetName() {

        echo " Got Name <pre> "; var_dump($_POST); die;

        if (!empty($_POST['ssn'])) {

            $sql = 'SELECT employee_ID, CONCAT(first_name," ",last_name) as name FROM employee WHERE ssn ='.$_POST['ssn'] ;

I guess that You entered wrong html option "ajax".

If You could check Yii docs (yiiframework.com/doc/api/1.1/CHtml#activeTextField-detail), it states that you have to enter "clientChange" attribute, which itself is array, where you can specify ajax.

You could try this:


echo $form->textField($model, 'employee_ssn', array(

       'clientChange'=>array(

          'ajax'=> array(

            'type'=>'POST', //request type

            'url' => CController::createUrl('getName'), //url to call.

            'success'=>'js:function(data) { $("#assignment_employee_ssn").val(data); }',

            )

          )

    ));

This is for your first problem, i hope the second problem will be solved at the same time. : )