2

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:

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

.. in which case the setDefaults method seems bit useless to me...

Jakub Stejskal
  • 571
  • 2
  • 9
  • 25

2 Answers2

0

you could use

$form->exportValue('text');
streetparade
  • 32,000
  • 37
  • 101
  • 123
  • Documentation says: This method first tries to find a cleaned-up submitted value, it will return a value set by setValue()/setDefaults()/setConstants() if submitted value does not exist for the given element.... So I guess that doesn't solve my problem :/ – Jakub Stejskal Dec 12 '09 at 23:11
0

setDefaults method is thought to "pre-fill" the content of the form.

After a submit the values set into the forms are the ones coming from the method $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');
damko
  • 301
  • 1
  • 12