How To Fill Text Field With Database Value

Hi guys.

I have two tables Jobs and Applicants.

Now on Job detail page there is an online apply button which moves you to the Applicant online apply form.

now on that form I want to print the job_id in a hidden text field(which is a forign key in Applicant table), because both Jobs and Applicants are in relation.

I am trying this but it gives me "Trying to get property of non-object" error.

here is my textfield code.


<?php echo $form->hiddenField($model, Applicant::model()->findByPk($model->id)->job_id, array('class' => 'span10', 'maxlength' => 256)); ?>

Would anyone please solve it.

Thanks in advance.

I have solved it using


<?php echo $form->hiddenField($model, 'job_id', array('class' => 'span10', 'maxlength' => 256,'value'=>$_GET['jobid'])); ?>

If you want you can also try to put

$model->job_id = $_GET[‘jobid’];

before your textfield.

or if you have an entire form model

$model->attributes = Yii::app()->session[‘YourForm’]->attributes;

So you’ll have default value for each filled field in your session or get/post Data depending how you pass you’r value.

You could create a new action in your job controller and ditch the application controller. You really don’t need it because you shouldn’t allow applications to be changed once submitted. If you have over 50 employees within a 75 mile radius and in the USA you should have it forward to an EEO and VET status page (must be different pages according to our HR lawyers check with yours) that collects their info for those too.

That’s what i did for my job tracking script i wrote awhile back and remove your hidden fields that anyone can change if they view the script.




public function actionApplication($id)

{

	$model=$this->loadModel($id);

	$applicant=new Applicant;

	if(isset($_POST['Applicant']))

	{

	$applicant->unsetAttributes();  // clear any default values

	$applicant->attributes=$_POST['Applicant'];

	$valid=$applicant->validate();

	if($valid)

	{ 

		$applicant->job_id = $id;

		if($applicant->save()) {

		$this->redirect(array('eeopage','id'=>$applicant->id));//you want to make sure the eeo stays with the applicant so get the next application id

		} 

	}

	}

	$this->render('application',array(

	'model'=>$model,

	'applicant'=>$applicant

	));

}



You could also add another view file and action in your job to “manage” the submitted ones. I have it so under the admin view of the job you can see applicants for that job. That’s what i did.