我有_form.php這個形式插件分配一個值,以形成插件
echo $form['catcher_id']->renderLabel(); //the label
echo $form['catcher_id']->renderError(); //the validator
symfony中創建的基類:
<?php
/**
* LpmService form base class.
*/
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(),
[color=#FF4000] 'catcher_id' => new sfWidgetFormPropelChoice(array('model' => 'LpmCatcher', 'add_empty' => false)),[/color]
'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('choices' => 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';
}
}
和我重新創建的下拉列表中手動所以我可以結合了「的onchange」事件:
<select name="services" onchange="refreshPage(this.form.services)" id="droplist">
<?php
$catcher_names = LpmCatcherPeer::getByAllNames();
foreach($catcher_names as $row)
{
?>
<option value="<?php echo $row->getName()."/".$row->getId(); ?>" <?php
if($row->getName() == $catcher_name) echo 'selected="selected"'?>><?php echo $row->getName();?></option>
<?php
}
?>
</select>
我怎麼能值賦給echo $form['catcher_id']
因爲現在當我選擇從下拉列表中的值,然後點擊提交驗證器說catcher_id是必需的(因爲我手動創建下拉菜單),所以我怎麼能手動設置值?
我有:
$form['catcher_id']->getWidget()->setAttribute('value', '11');
但它不工作。
不怕,我仍然得到驗證者說catcher_id是必需的 – 2011-02-17 09:58:32