Re: Quickform & Foreign Text

From: Date: Sun, 21 Nov 2004 02:57:19 +0000
Subject: Re: Quickform & Foreign Text
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15730@lists.php.net to get a copy of this message
Alexey & Justin, Thanks for all your help and patience! I really appreciate that. As I am sure you are aware, I am just a beginner in the PEAR world therefore I am grateful for any help I can get. So I took your advice and figured out how to use unicode and it finally works!!! Could you take a look at this and tell me if there is a way I can improve my script? Here is my upload script which has been saved as a Unicode document: ######################################################## // The textarea field $form->addElement('textarea','textareaExample','Text', $attrs); // Add a submit button $form->addElement('submit','submit','Submit'); // Validate text field if ($display = $form->validate()) { $insert = "INSERT INTO textarea VALUES ('" . utf8_encode(htmlspecialchars($form -> getSubmitValue('textareaExample'), ENT_QUOTES)) . "')"; $result = mysql_query($insert); if ($result) { $display = "INSERT Successful"; } else { $display = "<font color=red>INSERT failed</font>"; } } else { // If not submitted, display the form $display = $form->toHtml(); } ######################################################## Here is the EDIT script that inserts data from the database into the <textarea> to be edited, also saved as a unicode document. ######################################################## // Function found at http://kr.php.net/manual/en/function.htmlspecialchars.php function unhtmlspecialchars( $string ) { $string = str_replace ( '&amp;', '&', $string ); $string = str_replace ( '&#039;', "'", $string ); $string = str_replace ( '&quot;', '"', $string ); $string = str_replace ( '&lt;', '<', $string ); $string = str_replace ( '&gt;', '>', $string ); return $string; } // Instantiate the QuickForm class $form = new HTML_QuickForm('example', 'POST'); // textarea attributes $attrs = array("rows"=>"10", "cols"=>"30"); // decode unicode $DESC = utf8_decode($text); $DESC = unhtmlspecialchars($DESC); // Set defaults for the form elements $form->setDefaults(array('textareaExample' => $DESC)); // The textarea field $form->addElement('textarea','textareaExample','Text', $attrs); ######################################################## Does that look like I am on the right track? Would you make any major changes to either of these 2 scripts? Thanks again! Eric

« previous php.pear.general (#15730) next »