Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP vars being used in hidden form fields!

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
GB
Right, I've thought of jsut about everything, and everything I think of seems flawed. The problem is this - if you have a text area in a form to save to a file, you can stripslashes() and str_replace &quot;\r&quot; with &quot;<br />&quot; and then the browser will display it properly just by reading the text file. However, to display it again in a textarea, for editing etc, I have to replace &quot;<br />&quot; with &quot;\r&quot;. But that's ok, I can write a MuliLine(textorhtml) function to turn it either to text or to html friendly versions.

The problem is, how do I include it in a form hidden input field!!! The problem lies in that any variable you've taken from a form could contain a &quot;, and even if it is escaped, if you try putting it in a input type=&quot;hidden&quot; value=&quot;$whatever&quot; then you'll find it still goes wrong and ends the value at the escaped &quot; in the variable if there is one. Anyone got any bright ideas? *mutters he wouldn't have this problem if he had access to mysql for free* =/ _________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
PHP provides a function nl2br() ( for converting newlines in text to &quot;<br />&quot; tags. Actually, it leaves the newlines there, and adds &quot;<br />&quot; after each one.

Take a look at htmlspecialchars() ( for dealing with the quote problem. Want the best answers? Ask the best questions: TANSTAAFL!
 
Thanks for the replies, for some reason I just couldn't work on it anymore without motivation of someone replying!

I've already looked through the php docs on htmlentities and htmlspecialchars n stuff many times and not found them useful at all =/

But now finally I do. Basically, I pass EVERYTHING I am given through this included funtion :

Code:
function StripStuff($thetext) {
	$thetext = htmlspecialchars(stripslashes($thetext));
	$thetext = str_replace(&quot;£&quot;,&quot;&#163;&quot;,$thetext);
	return $thetext;
}

The reason for escaping the GBPound sign is they aren't allowed in XML files without being escaped! Grrr.

Then, whenever I have passed a value on to another page via a forms hidden input field, as is the title of this post, I have to run it through StripStuff() again.

Then, whenvner I want to display content taken from a text area, ie, multiple lines, I just say:

Code:
$nameshow = nl2br($name);

Then I show the $nameshow whilst still keeping the $name for further passing around or writing to xml or whatever.

I find it far better to not striptags or anything like that, as I'd rather see if a user has tried putting in font tags or anything more malicious and have it proudly sitting there in escaped equivilants doing no harm =)

Now ... just gotta write the code so that when someoen presses a 'cancel' button to go back and change their form inputs, it selects the checkboxes from the array that are already checked, and selects the right pulldown menu options (done that before) from dynamicaly generated (second dependant on first) pulldowns. Doh =/ Any prewritten code for that would save hours but don't worry otherwise ;) _________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top