Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jamie Wright

    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($cont ents))
    {
    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_arr ay($result))
    {
    $contents=$r["text"];
    }
    }
    }
    $output = "
    <html>
    <head>
    <title>
    Edit Text
    </title>
    </head>
    <body>
    <form method=\"POST\" action=\"editte xt.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;
    ?>


  • Justin Koivisto

    #2
    Re: Forms

    Jamie Wright wrote:
    [color=blue]
    > 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?[/color]

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

    $contents=htmle ntities(stripsl ashes($_POST['contents']));

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

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

    Comment

    • Jamie Wright

      #3
      Re: Forms

      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" <spam@koivi.com > wrote in message
      news:D7HMa.484$ iA3.28926@news7 .onvoy.net...[color=blue]
      > Jamie Wright wrote:
      >[color=green]
      > > I have a problem with an HTML form. I have a form which I want to be[/color][/color]
      able to[color=blue][color=green]
      > > type basic HTML code into it. When the submit button is selected the[/color][/color]
      data is[color=blue][color=green]
      > > then previewed and added back into the text box again. Unfortunately all[/color][/color]
      of[color=blue][color=green]
      > > 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[/color][/color]
      understand[color=blue][color=green]
      > > why that is happening. Any ideas?[/color]
      >
      > Sounds like magic_quotes_gp c is enabled on your system. To get rid of
      > them, before you create your output string, do this:
      >
      > $contents=htmle ntities(stripsl ashes($_POST['contents']));
      >
      > stripslashes gets rid of the escape characters addslashes would add them
      > if you need them for a query or something
      >
      > --
      > Justin Koivisto - spam@koivi.com
      > PHP POSTERS: Please use comp.lang.php for PHP related questions,
      > alt.php* groups are not recommended.
      >[/color]


      Comment

      • Justin Koivisto

        #4
        Re: Forms

        Jamie Wright wrote:[color=blue]
        >
        > "Justin Koivisto" <spam@koivi.com > wrote in message
        > news:D7HMa.484$ iA3.28926@news7 .onvoy.net...
        >[color=green]
        >>Jamie Wright wrote:
        >>
        >>[color=darkred]
        >>>I have a problem with an HTML form. I have a form which I want to be[/color][/color]
        >
        > able to
        >[color=green][color=darkred]
        >>>type basic HTML code into it. When the submit button is selected the[/color][/color]
        >
        > data is
        >[color=green][color=darkred]
        >>>then previewed and added back into the text box again. Unfortunately all[/color][/color]
        >
        > of
        >[color=green][color=darkred]
        >>>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[/color][/color]
        >
        > understand
        >[color=green][color=darkred]
        >>>why that is happening. Any ideas?[/color]
        >>
        >>Sounds like magic_quotes_gp c is enabled on your system. To get rid of
        >>them, before you create your output string, do this:
        >>
        >>$contents=htm lentities(strip slashes($_POST['contents']));
        >>
        >>stripslashe s gets rid of the escape characters addslashes would add them
        >>if you need them for a query or something
        >>[/color]
        > 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.[/color]

        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(st ripslashes($_PO ST['contents']));
        $contents=strip slashes($_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 - spam@koivi.com
        PHP POSTERS: Please use comp.lang.php for PHP related questions,
        alt.php* groups are not recommended.

        Comment

        • Jamie Wright

          #5
          Re: Forms

          > Try this to see what I mean:[color=blue]
          >
          > <?PHP
          > if(isset($_POST['contents'])){
          > $form_contents= htmlentities(st ripslashes($_PO ST['contents']));
          > $contents=strip slashes($_POST['contents']);[/color]
          <SNIP>

          brilliant. I understand now. Thanks for your help.

          Jamie


          Comment

          • Shawn Wilson

            #6
            Re: Forms



            Jamie Wright wrote:
            [color=blue]
            > 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.[/color]

            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
            [color=blue]
            >
            >
            > "Justin Koivisto" <spam@koivi.com > wrote in message
            > news:D7HMa.484$ iA3.28926@news7 .onvoy.net...[color=green]
            > > Jamie Wright wrote:
            > >[color=darkred]
            > > > I have a problem with an HTML form. I have a form which I want to be[/color][/color]
            > able to[color=green][color=darkred]
            > > > type basic HTML code into it. When the submit button is selected the[/color][/color]
            > data is[color=green][color=darkred]
            > > > then previewed and added back into the text box again. Unfortunately all[/color][/color]
            > of[color=green][color=darkred]
            > > > 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[/color][/color]
            > understand[color=green][color=darkred]
            > > > why that is happening. Any ideas?[/color]
            > >
            > > Sounds like magic_quotes_gp c is enabled on your system. To get rid of
            > > them, before you create your output string, do this:
            > >
            > > $contents=htmle ntities(stripsl ashes($_POST['contents']));
            > >
            > > stripslashes gets rid of the escape characters addslashes would add them
            > > if you need them for a query or something[/color]
            >[/color]

            --
            Shawn Wilson
            shawn@glassgian t.com



            Comment

            Working...