i have the following code:
abstract class BaseLpmServiceForm extends BaseFormPropel
{
public function setup()
{
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'name' => new sfWidgetFormInputText(),
'wap_home' => new sfWidgetFormInputText(),
'call_center_number' => new sfWidgetFormInputText(),
'catcher_id' => new
sfWidgetFormPropelChoice(array('model' => 'LpmCatcher', 'add_empty' =>
false)),
'price_description' => new sfWidgetFormInputText(),
'logo' => new sfWidgetFormInputText(),
'invalid_msisdn_text' => new sfWidgetFormInputText(),
'terms_and_conditions' => new sfWidgetFormInputText(),
'service_code' => new sfWidgetFormInputText(),
));
$this->setValidators(array(
'id' => new sfValidatorChoice(array('cho开发者_如何学Cices'
=> array($this->getObject()->getId()), 'empty_value' => $this-
>getObject()->getId(), 'required' => false)),
'name' => new
sfValidatorString(array('max_length' => 64, 'required' => false)),
'wap_home' => new
sfValidatorString(array('max_length' => 256, 'required' => false)),
'call_center_number' => new
sfValidatorString(array('max_length' => 13, 'required' => false)),
'catcher_id' => new
sfValidatorPropelChoice(array('model' => 'LpmCatcher', 'column' =>
'id')),
'price_description' => new
sfValidatorString(array('max_length' => 128, 'required' => false)),
'logo' => new
sfValidatorString(array('max_length' => 255, 'required' => false)),
'invalid_msisdn_text' => new
sfValidatorString(array('max_length' => 255, 'required' => false)),
'terms_and_conditions' => new
sfValidatorString(array('max_length' => 750, 'required' => false)),
'service_code' => new
sfValidatorString(array('max_length' => 3, 'required' => false)),
));
$this->widgetSchema->setNameFormat('lpm_service[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this-
>validatorSchema);
parent::setup();
}
public function getModelName()
{
return 'LpmService';
}
}
then i have in _form.php the following snippet:
<th><?php echo $form['catcher_id']->renderLabel();
$catcher_id = $form->getObject()->getCatcherId();
$catcher = LpmCatcherPeer::getByCatcherId($catcher_id);
$catcher_name = $catcher->getName();
?></th>
<td>
<?php echo $form['catcher_id']->renderError();
?>
<!-- <input type="hidden" name="$value" id="$value"/> -->
<select name="services"
onchange="refreshPage(this.form.services)" id="droplist">
<?php
//echo $form['catcher_id'];
//echo var_dump($_GET($form['catcher_id']));
//echo var_dump($_POST($form['catcher_id']));
//$catcher_names = explode(" ",$form['catcher_id']);
$catcher_names = LpmCatcherPeer::getByAllNames();
foreach($catcher_names as $row)
{
?>
<option value="<?php echo $row->getName();?>" <?
php
if($row->getName() == $catcher_name) echo
'selected="selected"';?>><?php echo $row->getName();?></option>
<?php
}
?>
</select>
<?php
//$catcher_names = explode(" ",$form['catcher_id']);
//$user = "";
//$message = '<script type="text/
javascript">refreshPage("'.$user.'")</script>';
//echo $message;
$form['service_code']->getWidget()-
>setAttribute('disabled', 'true');
echo $form['service_code']->renderLabel();
echo $form['service_code']->renderError();
echo $form['service_code'];
$service_code = $form['service_code']->getValue();
if ($service_code != null)
{
$catcher = LpmServicePeer::getByName($form['name']-
>getValue());
$catcher->setCatcherId(11);
$catcher->setServiceCode($service_code);
$form['catcher_id']->getWidget()-
>setAttribute('value','"11"');
$form->save();
}
?>
my problem lies with the line: $form['catcher_id']->getWidget()->setAttribute('value','"11"'); it is not working i get an error.. if a service code was entered i want to set catcher id to the value of 11 error is:
500 | Internal Server Error | sfValidatorErrorSchema
catcher_id [Required.]
and also:
$errorSchema = new sfValidatorErrorSchema($this);
// check that post_max_size has not been reached
if (isset($_SERVER['CONTENT_LENGTH']) && (int)
$_SERVER['CONTENT_LENGTH'] > $this-
>getBytes(ini_get('post_max_size')))
can ANYBODY PLEASE help me i am desperate please many thanks
You need to use setDefault
in your controller instead of setValue
$this->form = new BaseLpmServiceForm();
$this->form->setDefaults(array('service_code' => 11));
I know in symfony 1.4 with doctrine you can pass in the defaults to the constructor.
$this->form = new BaseLpmServiceForm(array('service_code' => 11));
精彩评论