473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forms

I have a problem with an HTML form. I have a form which I want to be able to
type basic HTML code into it. When the submit button is selected the data is
then previewed and added back into the text box again. Unfortunately all of
the " charachters are escaped (I think that is the correct term) ie they
have a leading \ added. This is causing me huge problems. I don't understand
why that is happening. Any ideas?

------------------CODE--------------
<?PHP
if(!isset($contents))
{
include "config.php";
mysql_connect($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpasswd']);
$query = "SELECT `text` FROM `golf_contents` WHERE 1 AND `section`
LIKE '$section'";
$result = mysql_db_query($cfg['dbname'], $query);
if ($result)
{
while ($r = mysql_fetch_array($result))
{
$contents=$r["text"];
}
}
}
$output = "
<html>
<head>
<title>
Edit Text
</title>
</head>
<body>
<form method=\"POST\" action=\"edittext.php?section=$section\">
<textarea rows=\"10\" name=\"contents\" cols=\"35\">
$contents
</textarea>
<input type=\"submit\" value=\"Preview\" name=\"B1\">
<input type=\"reset\" value=\"Reset\" name=\"B2\">
</form>
<BR>Preview...<BR>
$contents
</body>
</html>
";
echo $output;
?>
Jul 16 '05 #1
5 3616
Jamie Wright wrote:
I have a problem with an HTML form. I have a form which I want to be able to
type basic HTML code into it. When the submit button is selected the data is
then previewed and added back into the text box again. Unfortunately all of
the " charachters are escaped (I think that is the correct term) ie they
have a leading \ added. This is causing me huge problems. I don't understand
why that is happening. Any ideas?


Sounds like magic_quotes_gpc is enabled on your system. To get rid of
them, before you create your output string, do this:

$contents=htmlentities(stripslashes($_POST['contents']));

stripslashes gets rid of the escape characters addslashes would add them
if you need them for a query or something

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 16 '05 #2
Cheers for that Justin. It seems to have solved one problem, but cleverly
created another. Now the

echo $output;

gives the HTML as plain text (tags and all). I'm not sure why this is
because in the text box it is as standard HTML. I'm very confused.

"Justin Koivisto" <sp**@koivi.com> wrote in message
news:D7*****************@news7.onvoy.net...
Jamie Wright wrote:
I have a problem with an HTML form. I have a form which I want to be able to type basic HTML code into it. When the submit button is selected the data is then previewed and added back into the text box again. Unfortunately all of the " charachters are escaped (I think that is the correct term) ie they
have a leading \ added. This is causing me huge problems. I don't understand why that is happening. Any ideas?


Sounds like magic_quotes_gpc is enabled on your system. To get rid of
them, before you create your output string, do this:

$contents=htmlentities(stripslashes($_POST['contents']));

stripslashes gets rid of the escape characters addslashes would add them
if you need them for a query or something

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 16 '05 #3
Jamie Wright wrote:

"Justin Koivisto" <sp**@koivi.com> wrote in message
news:D7*****************@news7.onvoy.net...
Jamie Wright wrote:

I have a problem with an HTML form. I have a form which I want to be
able to
type basic HTML code into it. When the submit button is selected the
data is
then previewed and added back into the text box again. Unfortunately all
of
the " charachters are escaped (I think that is the correct term) ie they
have a leading \ added. This is causing me huge problems. I don't
understand
why that is happening. Any ideas?


Sounds like magic_quotes_gpc is enabled on your system. To get rid of
them, before you create your output string, do this:

$contents=htmlentities(stripslashes($_POST['contents']));

stripslashes gets rid of the escape characters addslashes would add them
if you need them for a query or something

Cheers for that Justin. It seems to have solved one problem, but cleverly
created another. Now the

echo $output;

gives the HTML as plain text (tags and all). I'm not sure why this is
because in the text box it is as standard HTML. I'm very confused.


htmlentities transforms all characters to it's HTML equivalent.
Therefore, if you type in:

afdsg asdf "with </textarea> stuff"

in the textbox, that's how it should appear again, but the code will
look like:

afdsg asdf &quot;with &lt;html&gt; stuff&quot;

You need to do that because you want to preserve any quotes that are in
the content... Otherwise it could break the textarea if a "</textarea>"
was in the content.

Try this to see what I mean:

<?PHP
if(isset($_POST['contents'])){
$form_contents=htmlentities(stripslashes($_POST['contents']));
$contents=stripslashes($_POST['contents']);
}else{
$form_contents='';
$contents='';
}
?>
<html>
<head>
<title>Edit Text</title>
</head>

<body>
<form method="POST" action="">
<textarea rows="10" name="contents" cols="35"><?php echo
$form_contents ?></textarea>
<input type="submit" value="Preview" name="B1">
<input type="reset" value="Reset" name="B2">
</form>
<?php echo $contents ?>
</body>
</html>

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 16 '05 #4
> Try this to see what I mean:

<?PHP
if(isset($_POST['contents'])){
$form_contents=htmlentities(stripslashes($_POST['contents']));
$contents=stripslashes($_POST['contents']);

<SNIP>

brilliant. I understand now. Thanks for your help.

Jamie
Jul 16 '05 #5


Jamie Wright wrote:
Cheers for that Justin. It seems to have solved one problem, but cleverly
created another. Now the

echo $output;

gives the HTML as plain text (tags and all). I'm not sure why this is
because in the text box it is as standard HTML. I'm very confused.
This is happening because you're using htmlentities(). It's converting the <
and > (as well as other characters) into the html code, ie. &lt; and &gt;. Get
rid of it, keeping stripslashes() and your html tags will work.

Shawn


"Justin Koivisto" <sp**@koivi.com> wrote in message
news:D7*****************@news7.onvoy.net...
Jamie Wright wrote:
I have a problem with an HTML form. I have a form which I want to be able to type basic HTML code into it. When the submit button is selected the data is then previewed and added back into the text box again. Unfortunately all of the " charachters are escaped (I think that is the correct term) ie they
have a leading \ added. This is causing me huge problems. I don't understand why that is happening. Any ideas?


Sounds like magic_quotes_gpc is enabled on your system. To get rid of
them, before you create your output string, do this:

$contents=htmlentities(stripslashes($_POST['contents']));

stripslashes gets rid of the escape characters addslashes would add them
if you need them for a query or something


--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
4066
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
2268
by: Joshua Russell | last post by:
Hi, Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of...
7
2454
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
13
5548
by: MD | last post by:
I have been converting a program from VB6 to VB.Net and enhancing it as well. All has been progressing OK although its been hard work. Now, all of a sudden, when I try to execute a ShowDialog()...
15
2029
by: Joshua Kendall | last post by:
I have a script in which it keeps opening the same form instead of only one instance. I also need help with a form that has a password. Where do I put the actual password? can I use a database for...
3
1628
by: Lloyd Sheen | last post by:
I have the following situation: Need a user resizable user control. After much trying with user control I came across the idea of hosting the controls in a form marked as not TopLevel = false. ...
8
2703
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
3
2357
by: Geraldine Hobley | last post by:
Hello, In my project I am inheriting several forms. However when I inherit from a form and add additional subroutines and methods to my inherited form I get all sorts of problems. e.g. I sometimes...
6
2554
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
21
3289
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
7547
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7114
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5693
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.