0

我有一个 Zend 表单和这个表单的 URL。

URL 有 3 个参数 firstname、lastname 和 email。在我的表单中,我有 3 个输入字段,其中还有名字、姓氏和电子邮件。

每当我提交表格时。它从 URL 参数而不是表单输入字段中获取值。

有没有办法在表单中获取值?

我知道来自 url 的参数与表单输入字段同名*

网址:http ://mywebsite.com/thank-you?key=e72671a8640b45c2401afe887b9b530a& first_name =First& last_name =User& email =user_3fdfsdfs@gmail.com

Zend 动作控制器的形式:

$signupForm = new Application_Form_UserSignUp();
if ($signupForm->isValid($this->getRequest()->getParams()))
        {

            $user = $this->_helper->model('Users')->createRow($signupForm->getValues());   
            if ($user->save())
            {
                Zend_Session::rememberMe(186400 * 14);
                Zend_Auth::getInstance()->getStorage()->write($user);
                $user->sendSignUpEmail();
                $this->getHelper('redirector')->gotoRoute(array(), 'invite');
                return;
            }
        }
$this->view->signupForm = $signupForm;

Zend 形式:

class Application_Form_UserSignUp extends Zend_Form
{
public $first_name, $last_name, $email, $submitButton;

public function init()
{
    $this->setName('signupForm'); 

    $this->first_name = $this->createElement('text', 'first_name')->setRequired(true);
    $this->last_name = $this->createElement('text', 'last_name')->setRequired(true);

    // Check if email is duplicated in database
    $noEmailExists = new Zend_Validate_Db_NoRecordExists(
            array(
                'table' => 'users',
                'field' => 'email'
            )
        );
    $noEmailExists->setMessage('%value% is already used by another person, please try again with different email address', Zend_Validate_Db_Abstract::ERROR_RECORD_FOUND);

    $this->email = $this->createElement('text', 'email')
                     ->setLabel('Email')
                     ->addValidator($noEmailExists)
                     ->addValidator('EmailAddress')
                     ->setRequired(true);

    $this->submitButton = $this->createElement('button', 'save')
                            ->setLabel('Sign Up')
                            ->setAttrib('type', 'submit');

    $this->addElements(array($this->first_name, $this->last_name, $this->email, $this->submitButton));

    $elementDecorators = array(
        'ViewHelper'
    );
    $this->setElementDecorators($elementDecorators);

}

}
4

1 回答 1

1

在您的控制器 Action 中,您可以将值传递给 Zend_Form 对象:

$form->populate($data);

或 $form->setDefaults($data);

populate() 接受一个数组,其中键是表单字段的名称,数组值是字段值。

http://framework.zend.com/manual/1.12/en/zend.form.forms.html#zend.form.forms.elements.values

于 2013-01-11T15:55:44.010 回答