简体   繁体   English

如何设置使用PEAR QuickForm提交后显示的值?

[英]How to set values displayed after submit using PEAR QuickForm?

Let's say I've got form like this: 假设我有这样的形式:

$form = new HTML_QuickForm('Novinky');  
$defaults = array('text' => '');
$form->setDefaults($defaults);
$elements['text'] = $form->addElement('textarea', 'text', 'Text', array('cols'=>55, 'rows'=>10, 'id'=>'text'));
$form->addElement('submit','save','Save');
if (isset($_POST[save])) {
    if ($form->validate()) {            
        $form->process(array($this,'writeDB'));
    }
}

After submit I want the default value to be shown instead of the value entered by user. 提交后,我希望显示默认值,而不是用户输入的值。 Does Quickform have some functionality to achieve that or do I have to use something clumsy like: Quickform是否具有某些功能可以实现这一目标,或者我必须使用一些笨拙的东西,例如:

$elements['text']->setValue( $defaults['text']);

.. in which case the setDefaults method seems bit useless to me... ..在这种情况下,setDefaults方法对我来说似乎毫无用处...

你可以用

$form->exportValue('text');

setDefaults method is thought to "pre-fill" the content of the form. setDefaults方法被认为是“预填充”表单的内容。

After a submit the values set into the forms are the ones coming from the method $form->getSubmitValues. 提交后,将值设置为表单中的值,这些值来自方法$ form-> getSubmitValues。

If you want / need to change that behaviour then you have no other option than setting the value manually: 如果您想要/需要更改该行为,那么除了手动设置值之外,您别无其他选择:

code (to be used after you define your element "text" of course): 代码(当然,在定义元素“文本”之后使用):

$text=$form->getElement('text');                    
$text->setValue('your value');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM