GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-May-2004, 12:57
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough

storing html from a form


OK so I have a lil problem storing html code in a textfile.
This is the form used to get the $page and $newtext variables.

<form action="edtext.php" method="get">
<b>Page:</b><input type="text" name="page"><br>
<b>Text:</b><textarea name="newtext">Add content here</textarea><br>
<input type="submit" value="send">
</form>

Now within the edtext.php file, the $page is for the textfile you want to add the $newtext to.

This is all good it works quite fine, but a problem exists when a lot of code is entered. IE the $page and $newtext data is transferred as so:
edtext.php?page=home;newtext=%3C%21--+Nav+Table+--%3E%0D%0A%3Ctable+border%3D%5C%5C%5C%220%5C%5C%5C% 22+cellPadd etc etc etc.

So not all text within the $newtext textarea in the form is sent to the php script.
And the text that is sent is further edited IE it would convert this text:
<table border="0"> to this text:
<table border=\"0\"> etc

So how can I send large amounts of (unedited) text to a php script from a form in a html doc?
Pls help thanx
  #2  
Old 20-May-2004, 05:13
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Use POST (instead of GET) method in your form?
  #3  
Old 24-May-2004, 04:48
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough
Quote:
Originally Posted by JdS
Use POST (instead of GET) method in your form?
ok I tried the 'post' method and the data is sent neater. But there are still two problems that are battling me:

Firstly the text that is sent throught the form is limited. Is there a way I can assign the amount of characters sent, maybe in the <textarea> field of the form? I donno.
Secondly the html text that is sent is being edited to work with php and I have no idea why. Surely the data should be sent as is I donno why this is happening. IE: <table border="0"> (entered in the textarea) would be edited to <table border=\"0\"> why is this?
peace
  #4  
Old 24-May-2004, 08:08
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
This has to do with your php.ini setting for magic_quotes_gpc. If it's set to TRUE/ON/1, then all ' (single-quote), " (double quote), \ (backslash) and NUL's (in user-inputted data off GET/POST/COOKIE) are escaped with a backslash automatically.

If you need to display these 'values' on a web page, then simply pass the data through stripslashes e.g.

PHP Code:

<?php
echo htmlentities( stripslashes($_POST['newtext']), ENT_QUOTES );
?>


About limiting the characters submitted via a textarea, I don't know how to do this but I think it's impossible. However, you can do this client-side (i.e. with JavaScript) or server-side with e.g. PHP's substr() function.
  #5  
Old 24-May-2004, 11:16
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough
I see. So can I save the html retrieved from the form as follows?

PHP Code:

$normaltext = htmlentities( stripslashes($_POST['$newtext']), ENT_QUOTES );
$newFilePointer = fopen("$textFile","w+");
fputs($newFilePointer, $normaltext, 1024);
fclose($newFilePointer); 



Will that work now?
Peace
  #6  
Old 25-May-2004, 04:42
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Yes, that should work (considering your 'write' script works well).... I am sure you've tested it already.

You have a choice whether to pass the data via htmlentities before you store the data in a textfile or just before you display the data - you know that, right?
  #7  
Old 25-May-2004, 05:11
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough
Quote:
You have a choice whether to pass the data via htmlentities before you store the data in a textfile or just before you display the data - you know that, right?

Hmmm...isn't this what I have done in my previous post? The html text is stored in a string variable called $newtext, from a textarea. Then in the script, if $newtext is defined, then strip it back down using htmlentities and then store it in the textfile.

I am still having problems with limited characters being sent from the textarea. Pls tell me more about PHP's substr() function and how i can use it?
  #8  
Old 25-May-2004, 05:22
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
An example string off $_POST['newtext'] could be;
<b>This is in "bold"</b>.
right?

With htmlentities( stripslashes($_POST['newtext']), ENT_QUOTES ), that string is converted to:
&lt;b&gt;This is in &quot;bold&quot;&lt;/b&gt;.

About substr(), let's assume you only want to allow a user to submit up to 255 characters via $_POST['newtext'], your form-processing script can then ensure that it so simply by adding this line inside the script, before doing anything else:

PHP Code:

<?php
// ensure that $_POST['nextext'] is only 255 chars long
$_POST['newtext'] = substr( stripslashes($_POST['newtext']), 0, 255 );

//...
?>

 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with form orbitel MySQL / PHP Forum 11 21-Jan-2004 15:29
Why doesnt my form work correctly? rhino1616 Web Design Forum 2 06-Nov-2003 17:21
simple form from generated page zuzupus Web Design Forum 0 17-Sep-2003 09:27
validate form skyloon MySQL / PHP Forum 3 15-Jul-2003 09:04
[class] Generate Forms Without Using HTML! Elmseeker PHP Code Library 6 11-Mar-2003 12:05

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:26.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.