Solved

Default value for PEAR::QuickForm::Textarea

Posted on 2004-09-15
5
383 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now