Re: [SMARTY] newbie: Escaped variables in form textareas??

From: Date: Mon, 01 Jul 2002 18:22:10 +0000
Subject: Re: [SMARTY] newbie: Escaped variables in form textareas??
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5131@lists.php.net to get a copy of this message
Even better since it will work for all special characters! Thanks, Brian! :) Avern
From: Brian E. Lozier <brian@massassi.net> To: travis@dawnstar.org, "Avern Williams" <avern@hotmail.com> CC: ben@hypothetical.co.uk, smarty-general@lists.php.net Subject: Re: [SMARTY] newbie: Escaped variables in form textareas?? Date: Mon, 01 Jul 2002 11:17:30 -0700 Now your quotes are tripping up the HTML by adding extra quotes in a text tag. Like this: <input type="text" name="mytextbox" value="Hello "mom""> it reads the value as 'Hello ' (see where the first quote ends the tag?). You can use htmlentities() from php to replace all the special characters with their HTML equivilients (&quot; in this case). Brian 7/1/02 10:55:40 AM, "Avern Williams" <avern@hotmail.com> wrote: Ah, that explains it! So it's not smarty at all, but rather my php configuration. Sorry, Monte. :) I see what you mean, too, becuase when I tried to change the smarty template to read: ---------------------------- You entered: <input type="text" name="yourtext" value="{$yourtext|stripslashes}"> ---------------------------- then any single quotes the user entered came through nicely, but any doublequotes they entered still tripped up the display. :/ I'm not really adept enough to handle all the escaping code myself, so I'll try to see if there is an escaping class somewhere. thanks for all the tips, everyone! Avern
From: <travis@dawnstar.org> Reply-To: <travis@dawnstar.org> To: Avern Williams <avern@hotmail.com> CC: <ben@hypothetical.co.uk>, <smarty-general@lists.php.net> Subject: Re: [SMARTY] newbie: Escaped variables in form textareas?? Date: Mon, 1 Jul 2002 14:34:10 -0400 (EDT) Your PHP installation probably has "magic_quotes_gpc" set to true,
meaning
all GET/POST/COOKIE data is escaped automatically. The escape character (the backslash) is typically dropped when the data is inserted into the database, which is why you'll only notice the backslashes in data that
you
redisplay from the request. So, for any page that will redisplay submitted data, you'll have to do what Ben says (use stripslashes()). Alternatively, you can funnel all request information into a PHP class that handles the
escaping/unescaping
for you (e.g. $myclass->getUnescapedData("param_name")). Or you can
turn
off magic_quotes_gpc locally and just escape all the data yourself. cheers, Travis On Mon, 1 Jul 2002, Avern Williams wrote:
Thanks, I was going to say that it seemed like smarty was putting in
the
slashes by default. To test it I tried creating a php page with the following content: --------------------------------- <?php if ($action == "submit") { require("Smarty.class.php"); $smarty = new Smarty; $smarty->assign("yourtext",$yourtext); $smarty->display("formtest.tpl"); } else { print "<form action=\"/smarty/formtest.php\" method=\"post\"><input type=\"hidden\" name=\"action\" value=\"submit\">Enter your text:
<input
type=\"text\" name=\"yourtext\"><br><input type=\"submit\"></form>"; } ?> --------------------------------- Then I created formtest.tpl to look like: --------------------------------- You entered: <input type="text" name="yourtext" value="{$yourtext}"> --------------------------------- And when I tried it, if I entered text with a quote, it didn't show
up
after
submission. Is smarty intended to behave this way by default? Thanks for the info on stripslashes. I'll give that a try. thanks again! Avern
From: Ben Godfrey <ben@hypothetical.co.uk> To: "Avern Williams" <avern@hotmail.com> CC: smarty-general@lists.php.net Subject: Re: [SMARTY] newbie: Escaped variables in form textareas?? Date: Mon, 1 Jul 2002 18:09:00 +0100 You need to run PHP's stripslashes function on the form data. Either do it in the application or, if this isn't possible, write a Smarty modifier to wrap stripslashes. Ben On Monday, July 1, 2002, at 05:51 , Avern Williams wrote:
Hi, I have a textarea field for comments in a web form. If there is no problem with the form, then the comment gets entered into a
database
and
is immediately display in an html page (this part works fine).
However,
if there is a problem with the form, I've asked a smarty template
to
redisplay the form, showing the visitor's original comment as the
default
value in the comment field. The problem is that if their comment has a quote character, then
the
backslashes show up when the form is redisplayed. I know the
backslashes
normally help the quotes to be displayed properly, but is there a
way
to
have smarty show the comments variable without the backslashes? thanks, Avern _________________________________________________________________ Join the worldís largest e-mail service with MSN Hotmail. http://www.hotmail.com -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
_________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com
_________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
_________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx

« previous php.smarty.general (#5131) next »