Solved

Default value for PEAR::QuickForm::Textarea

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

738 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