Solved

Default value for PEAR::QuickForm::Textarea

Posted on 2004-09-15
5
412 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

830 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