Jump to content

Symfony woes


Gainax

Recommended Posts

Hi

 

I've built a form in symfony which is fine in terms of the way it looks. The only problem is I can't submit it as I'm getting an error.

 

The form takes the persons user_id when they are logged in and a few other fields which are simply text/input boxes.

 

As the form is to post jobs, I thought it would be wise to have a job id, to make things easier and to keep jobs in a formatted way in the db.

 

The only problem is, the id column is giving me the error. The error is its passing in an invalid id.

 

My code for the BaseJobForm class which does the validation is:

 

<?php

/**
* Job form base class.
*
* @package    fitbritz
* @subpackage form
* @author     mysyfy@gmail.com
* @version    SVN: $Id: sfPropelFormGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
*/
class BaseJobForm extends BaseFormPropel
{
  public function setup()
  {
    $this->setWidgets(array(
'id'             => new sfWidgetFormInputHidden(),
      'title'           => new sfWidgetFormInput(),
      'user_id'         => new sfWidgetFormInputHidden(),
      'job_category_id' => new sfWidgetFormPropelChoice(array('model' => 'JobCategory', 'add_empty' => true)),
      'created_at'      => new sfWidgetFormDateTime(),
      'updated_at'      => new sfWidgetFormDateTime(),
      'salary'          => new sfWidgetFormInput(),
      'availability'    => new sfWidgetFormInput(),
      'country_id'      => new sfWidgetFormPropelChoice(array('model' => 'Country', 'add_empty' => true)),
      'region_id'       => new sfWidgetFormPropelChoice(array('model' => 'Region', 'add_empty' => true)),
      'district_id'     => new sfWidgetFormPropelChoice(array('model' => 'District', 'add_empty' => true)),
      'city_id'         => new sfWidgetFormPropelChoice(array('model' => 'City', 'add_empty' => true)),
      'is_active'       => new sfWidgetFormInput(),
      'description'     => new sfWidgetFormTextarea(),
      'duties'          => new sfWidgetFormTextarea(),
      'candidate_info'  => new sfWidgetFormTextarea(),
      'benefits'        => new sfWidgetFormTextarea(),
      'skills'          => new sfWidgetFormTextarea(),
      'how_apply'       => new sfWidgetFormTextarea(),
    ));

    $this->setValidators(array(
      'id'              => new sfValidatorPropelChoice(array('model' => 'Job', 'column' => 'id', 'required' => true)),
      'title'           => new sfValidatorString(array('max_length' => 255)),
      'user_id'         => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'column' => 'id', 'required' => false)),
      'job_category_id' => new sfValidatorPropelChoice(array('model' => 'JobCategory', 'column' => 'id', 'required' => false)),
      'created_at'      => new sfValidatorDateTime(array('required' => false)),
      'updated_at'      => new sfValidatorDateTime(array('required' => false)),
      'salary'          => new sfValidatorString(array('max_length' => 255)),
      'availability'    => new sfValidatorString(array('max_length' => 255)),
      'country_id'      => new sfValidatorPropelChoice(array('model' => 'Country', 'column' => 'id', 'required' => false)),
      'region_id'       => new sfValidatorPropelChoice(array('model' => 'Region', 'column' => 'id', 'required' => false)),
      'district_id'     => new sfValidatorPropelChoice(array('model' => 'District', 'column' => 'id', 'required' => false)),
      'city_id'         => new sfValidatorPropelChoice(array('model' => 'City', 'column' => 'id', 'required' => false)),
      'is_active'       => new sfValidatorInteger(array('required' => false)),
      'description'     => new sfValidatorString(),
      'duties'          => new sfValidatorString(),
      'candidate_info'  => new sfValidatorString(),
      'benefits'        => new sfValidatorString(),
      'skills'          => new sfValidatorString(),
      'how_apply'       => new sfValidatorString(),
    ));

    $this->widgetSchema->setNameFormat('job[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function getModelName()
  {
    return 'Job';
  }

}

 

Any my form is:

 

<?php use_helper('Form','I18N')?>

<div id="left-col">

<?php echo include_partial('team/left_col_box') ?>

<?php echo include_partial('career/left_col_box')?>

<?php echo include_partial('advice/left_col_box') ?>

<?php echo include_partial('opportunity/left_col_box') ?>

</div>

<style type="text/css">

</style>

<div class="page">
<?php echo include_partial('members/main_menu'); ?>

<h3 class="sub"><?php echo link_to('Return to list','members_job') ?> <?php echo $form->getObject()->getTitle() ?></h3>

<?php if($sf_user->hasFlash('notice')): ?>
	<div class="message-success">
		<p><?php echo $sf_user->getFlash('notice'); ?></p>
	</div>
<?php endif; ?>

<?php if ($sf_user->hasFlash('error')): ?>
	<div class="message-fail">
		<p><?php echo __($sf_user->getFlash('error'), array(), 'sf_admin') ?></p>
	</div>
<?php endif; ?>

<?php if($form->hasErrors()): ?>

	<?php foreach($form->getErrorSchema()->getErrors() as $name=>$error): ?>
		<div class="message-fail">
			<p><?php echo $name . '=='.$error; ?></p>
		</div>
	<?php endforeach; ?>

<?php endif; ?>

<div>

	<?php echo form_tag_for($form, '@members_job',array('class'=>'ryform')) ?>

		<?php echo $form->renderHiddenFields(); ?>

		<fieldset>
          	<legend><strong>Main Job Details</strong></legend>
			<ul>
		    	<?php echo $form['title']->renderRow() ?>
			<?php echo $form['salary']->renderRow() ?>
			<?php echo $form['availability']->renderRow() ?>
			<?php echo $form['job_category_id']->renderRow() ?>
		    	<?php echo $form['country_id']->renderRow() ?>
		    	<?php echo $form['region_id']->renderRow() ?>
		    	<?php echo $form['district_id']->renderRow() ?>
		    	<?php echo $form['city_id']->renderRow() ?>

			</ul>
		</fieldset>


		<fieldset>
			<legend><strong>Texts</strong></legend>

			<ul>
				<?php echo $form['description']->renderRow(array('class'=>'tinyMCE')) ?>
				<?php echo $form['duties']->renderRow(array('class'=>'tinyMCE')) ?>
				<?php echo $form['candidate_info']->renderRow(array('class'=>'tinyMCE')) ?>
				<?php echo $form['skills']->renderRow(array('class'=>'tinyMCE')) ?>
				<?php echo $form['benefits']->renderRow(array('class'=>'tinyMCE')) ?>
				<?php echo $form['how_apply']->renderRow(array('class'=>'tinyMCE')) ?>


			</ul>
		</fieldset>

		<input type="submit" value="save" />

	</form>

</div>

</div>

<?php echo include_partial('sidebars/ads') ?>

 

In the schema.xml file, the id column for job table is:

 

 <column name="id" type="INTEGER" size="11" primaryKey="true" autoIncrement="true" required="true" />

 

Looking at the form in FF web dev tools, the job id is 3 and the user_id is 3 (3 = my user id in the user_profile table), but it's saying that 3 is invalid.

 

Can anyone suggest reasons why it's doing this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.