Solved

Default value for PEAR::QuickForm::Textarea

Posted on 2004-09-15
5
425 Views
Last Modified: 2012-08-13
Is there a way to set the defasutl value for a textbox created with PEAR's Quickform? The inherited method setValue doesn't work since the textarea-tag doesn't respond to the value-attribute...

Thanks in advance,
//madwax
0
Comment
Question by:madwax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12072167
Setting the value via setValue should work as the PHP-Code which outputs the textarea is the following:
 preg_replace("/(\r\n|\n|\r)/", '
', htmlspecialchars($this->_value))

and the settings is done vi
    function setValue($value)
    {
        $this->_value = $value;
    } //end func setValue

version I looked in HTML_QuickForm-3.2.3

So it should work.
0
 
LVL 7

Author Comment

by:madwax
ID: 12073342
hmm... maybe I am doing something wrong then.... I have upgraded pear with the upgrade-all command and on the page I have the following code (excerpt):

$form->addElement('textarea', 'long_description','Beskrivning:', array('cols' => 50, 'rows' => 15, 'value' => "test1"));
$ld = $form->getElement("long_description");
$ld->setValue("test");

it doesn't display any value in the textarea and when I print_r($ld) i get:

html_quickform_textarea Object ( [_attributes] => Array ( [cols] => 50 [rows] => 15 [value] => test1 [name] => long_description ) [_tabOffset] => 0 [_tab] => [_lineEnd] => [_comment] => [_label] => Beskrivning: [_type] => textarea [_flagFrozen] => [_persistantFreeze] => 1 [_value] => test )

this clearly shows that the _value variable is set both once And twice but isn't showed any of the times... (it doesn't work without the $ld) either...

//madwax
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 12089285
So I got the error. THe problem ist that you modify a copy of your text-area-object, but not the object in the QuickForm. Change the line:
$ld = $form->getElement("long_description");
to
$ld = &$form->getElement("long_description");

and it works.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question