Sara Fuerst
Sara Fuerst

Reputation: 6068

Setting Value on PHP Zend Form

I currently have a form that will let you create a family.

FamilyForm.php

$description = new Textarea(self::KEY_FAMILY_DESCRIPTION);
$description->setAttribute("id", self::KEY_FAMILY_DESCRIPTION);
$description->setLabel("Description");
$this->add($description);    

$status = new Hidden(self::KEY_FAMILY_STATUS);
$status->setAttribute("id", self::KEY_FAMILY_STATUS); 
$this->add($status); 

$save = new Button(self::KEY_SAVE_BTN);
$save->setAttributes(array("id", self::KEY_SAVE_BTN));
$save->setLabel("Save");
$save->setValue("Save");
$this->add($save);

Create.phtml

<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_DESCRIPTION, !($this->admin)); ?>
<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_STATUS, !($this->admin)); ?>
<div class="form-actions">
      <?php $save = $this->form->get(ProjectFamilyForm::KEY_SAVE_BTN); ?>
      <?php $save->setAttribute("class", "btn btn-primary"); ?>
      <?php echo $this->formSubmit($save); ?>

      <a class="btn" href="<?php echo $this->url('home'); ?>">Cancel</a>
</div>

This works and allows me to input the description and the status of the family upon creation. However, everytime a family is created the status should be "active". However, the setValue() method seems to not be working.

Upvotes: 2

Views: 160

Answers (1)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72289

I am not expert of ZEND but to do this some ways are there:-

  1. most preferable way:- Make you db table field set type and set the default value to active.

  2. Create a hidden field with predefined active value.

Please check this link for help:- http://forums.zend.com/viewtopic.php?t=2079

Upvotes: 1

Related Questions