HighDots Forums  

Need help with magic quotes

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Need help with magic quotes in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike-H
 
Posts: n/a

Default Need help with magic quotes - 04-02-2009 , 11:32 AM






I have a simple email form, similar to David Powers' example in chapter 11 of
The Essential Guide to DW-CS3. It works at a very rudimentary level.

I have been asked to give the client the ability to put carriage returns in
the middle of their form entry. If they just hit the enter key to insert a
carriage return, no keystrokes are entered into the post data to represent
that. I tried putting \n\r in the form entry, and it came out \\n\\r. I tried
using David's snippet to remove the slashes, and the script removed one of the
slashes, but it still renders as just text (\n\r) when the form is processed.

Is there a way to insert an actual carriage return and/or line feed in a form
and have it come out that way? There must be, because this forum seems to do it
just fine. If possible, I'd like to not require that they type in the escape
characters, but just hit the enter key within the textarea box.

Thanks for any help you can give me.
Mike


Reply With Quote
  #2  
Old   
GarryCT
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 12:12 PM






First of all, don't use magic quotes... not only are they evil and deprecated,
they will actually be removed from PHP 6... use addslashes/stripslashes instead.

To get the carriage returns, you can search the textarea.value for '\r\n' or
"'%0d%0a' (after escaping) & replace them with a token that you can handle on
the back end. A good token candidate could be something like '<br/>'...




Reply With Quote
  #3  
Old   
GarryCT
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 01:19 PM



ok...

did the code snippet in the second reply not work for you on the client side?

Reply With Quote
  #4  
Old   
Gary White
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 01:27 PM



On Thu, 2 Apr 2009 15:32:01 +0000 (UTC), "Mike-H"
<webforumsuser (AT) macromedia (DOT) com> wrote:

Quote:
Is there a way to insert an actual carriage return and/or line feed in a form
and have it come out that way? There must be, because this forum seems to do it
just fine. If possible, I'd like to not require that they type in the escape
characters, but just hit the enter key within the textarea box.
Not seeing your code makes it impossible to say that they aren't being
stripped out somewhere, but carriage returns are indeed submitted with the
form data. The problem is that HTML compresses white space and ignores the
carriage returns when displaying it. To get around that, use the PHP
nl2br() function:

echo nl2br($row['fieldname']);

Gary


Reply With Quote
  #5  
Old   
Mike-H
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 01:50 PM



I did get an alert box, it said this:
line1%0D%0A<br/>line2%0D%0A<br/>line3%0D%0A

But the text on the back end apparently never got the <br /> in the input
stream because my email still has everything on one line.

This also requires a user to manually enter "%0D" or "%0A" or "\n" or "\r" in
the text when they want a new line. Or they can just type "<br />". I am trying
to avoid requiring an end-user to type any extra characters.


Reply With Quote
  #6  
Old   
GarryCT
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 02:03 PM



They shouldn't have to type any extra characters. I get:

Line 1<br/>Line 2</br>Line 3 when I type 3 lines using carriage returns. You
may want to try (the other) Gary's suggesting to convert newlines to breaks
(nl2br) on the server side


Reply With Quote
  #7  
Old   
GarryCT
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 02:14 PM



Just to be clear... You wouldn't actually type the %0D & %0A... They are the
hexadecimal representation of carriage return/line feed. The user would just
have to hit the return key after each line as one normally would.


Reply With Quote
  #8  
Old   
Mike-H
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 02:33 PM



Gary White: nl2br() did the trick. Thank you. I figured there had to be a nice
php function to do this.

Garry, thanks for your help. I can see how this can help in some cases. I'm
not very good at javascript, so I'm choosing the other solution, since not
understanding this will make it much harder to maintain it.

Mike


Reply With Quote
  #9  
Old   
Gary White
 
Posts: n/a

Default Re: Need help with magic quotes - 04-02-2009 , 04:38 PM



On Thu, 2 Apr 2009 18:33:24 +0000 (UTC), "Mike-H"
<webforumsuser (AT) macromedia (DOT) com> wrote:

Quote:
Gary White: nl2br() did the trick. Thank you. I figured there had to be a nice
php function to do this.
You're welcome. It's a fairly common misunderstanding.

Gary


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.