1
Coplan
Slashes in my form preview
  • 2003/10/27 4:43

  • Coplan

  • Just popping in

  • Posts: 51

  • Since: 2002/10/2


I'm writing a module that allows users to submit descriptions about files they are submitting. It's a song database, but that's not really important.

I'm using a form to submit the data. The user might enter a description, but when they preview the description, it contains extra spaces at the beginning. IN addition, some special characters (like ', \) are prefixed with a "\".

I realize this is more of a PHP question, but I've never noticed this behavior outside of xoops. Does anyone know why that might be happening, or how I can fix it? I'm using the Post method, and here are tidbits of code:

Quote:

// Harvest some of the data provided via POST (if applicable)
$songInfo = array('s_name' => $_POST['s_name'],
'genre_id' => $_POST['genre_id'],
'uname' => $cur_uname,
'user_id' => $cur_uid,
'user_id2' => $_POST['user_id2'],
's_url' => $_POST['s_url'],
's_url2' => $_POST['s_url2'],
's_url3' => $_POST['s_url3'],
'stype_id' => $_POST['stype_id'],
'stype_id2' => $_POST['stype_id2'],
'stype_id3' => $_POST['stype_id3'],
's_desc' => $_POST['s_desc'],
);


Quote:






Comments: $songInfo[s_desc]



In this case, if I submit:
Quote:

I'm Testing Something.


I get:
Quote:

I\'m Testing Something.

[/quote]

2
Coplan
Re: Slashes in my form preview
  • 2003/10/27 6:24

  • Coplan

  • Just popping in

  • Posts: 51

  • Since: 2002/10/2


I somehow stumbled upon my own solution.

As it turns out, on my server, the php.ini has magic_quotes_gpc enabled. I can simply turn them off, but a better solution (assuming portability) would be to create a new function such as this (taken straight from the bird book):

Quote:

function raw_param($in) {
return ini_get('magic_quotes_gpc') ? stripslashes($in)
: $in;
}



Then call the function in this way:
Quote:

$stored = raw_param($_GET['name']);
// $stored is now an exact copy of the user's input


I only have one more problem. There now seems to be spaces popping up before and after the description. Still trying to figure that one out.

3
lubdub
Re: Slashes in my form preview
  • 2003/10/27 12:28

  • lubdub

  • Just popping in

  • Posts: 64

  • Since: 2002/2/28


Well, from my own experience, I'd say there's already something like that.
Correct me if I'm wrong, but if you need to use Text input from the client, you're likely to store it somewhere. If you store it in an Object class instance, extending XoopsObject, you can use the setVar() getVar() methods to have this clean up made for you, somehow.

Otherwise, depending on your usage, you can have a look at the TextSanitizer class.

Login

Who's Online

119 user(s) are online (77 user(s) are browsing Support Forums)


Members: 0


Guests: 119


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits