Re: newbie problem - extraneous newlines inserted in PHP-generated HTML form source

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, November 21, 2006 10:31 am, Mark White wrote:
> I am VERY new to this, so please be gentle.
>
> I am trying to use PHP to generate an HTML form for editing an
> uncomplicated XML document. I can parse the xml information
> successfully. However, when it comes to building the form, where I
> have
> a pair of double quotes (one escaped) to open the insertion of an
> array
> variable for a form value there is also a newline character inserted
> in
> the generated HTML form source code. Firefox and Safari ignore the
> 'breaks' in the code lines but it causes Explorer 5.2 (Mac) to fail to
> display the values.
>
> I have tried replacing the escaped double quote with a single quote -
> no
> change, the HTML source still includes the extra newline. I've tried
> removing and inserting spaces either side of the '.' without luck.
> I've
> also checked the xml document in Textwrangler and it is 'clean' of
> unwanted hidden characters.
>
> There are two oddities about this. Firstly, the array[0] postion
> record
> set form doesn't produce this 'broken' generated HTML, yet subsequent
> records each show breaks in the HTML source in exactly the same place.
> The other strangeness is that if I tab the original xml document for
> clarity I get tabs inserted in the HTML along with the extra return
> ....
> but again, only from record 2 (array[1]) onwards.
>
> Here is part of the xml -
>
> <?xml version="1.0"?>
>
> <teachingstaff>
> <person>
> <name>name 1</name>
> <status>headteacher</status>
> <class>1</class>
> <history>words here</history>
> <picture>1.jpg</picture>
> </person>
> <person>
> <name>name 2</name>
> <status>teacher</status>
> <class>2</class>
> <history>words here</history>
> <picture>2.jpg</picture>
> </person>
> <person>
> <name>name 3</name>
>
> and so on ... and here is some of the php to generate the HTML editing
> form -
>
> <?
> loadteachingstaff();
> echo "<div id=\"container\">";

It is much clearer to break in/out of PHP "mode" than to have all
these echo statements.

?>
<div id="container">
  <div class="head"><h2>Edit staff listing</h2></div>
  <div><?php
    if ($tstaffid < count($teachingstaff)) {
    ?>
    <form action="tstaffsave.php" method="POST">
    ...
    </form>
    <?php
    }
  ?>
  </div>
</div>

This may or may not help with the newlines in your data...

> echo "<div class=\"head\"><h2>Edit staff listing</h2></div><div>\n";
> if($tstaffid < count($teachingstaff)) {
> echo "<form action=\"tstaffsave.php\" method=\"POST\">";
> echo "<input type=\"hidden\" name=\"tstaffid\" value=\"$tstaffid\">";
> echo "<table>\n<tr><td class=\"labelr\">Name: </td><td><input
> type=\"text\" name=\"newname\" size=\"50\"
> value=\"".$teachingstaff[$tstaffid]['name']."\"></td></tr><br />\n";
> echo "<tr><td class=\"labelr\">Role: </td><td><input type=\"text\"
> name=\"newstatus\" size=\"50\"
> value=\"".$teachingstaff[$tstaffid]['status']."\"></td></tr><br />\n";
> echo "<tr><td class=\"labelr\">Class(es): </td><td><input
> type=\"text\"
> name=\"newclass\" size=\"50\"
> value=\"".$teachingstaff[$tstaffid]['class']."\"></td></tr><br />\n";
> echo "<tr><td class=\"labelr\" valign=\"top\">Experience:
> </td><td><textarea name=\"newhistory\" rows=\"5\" cols=\"50\"
> align=\"left\">" . $teachingstaff[$tstaffid]['history'] .
> "</textarea></td><br /></tr>\n";
>
> and so on ...
>
> The (**NEWLINE**) 'break' in the generated HTML source appears at the
> following point in each of the echoed lines -
> ...
> name=\"newstatus\" size=\"50\"
> value=\""**NEWLINE**.$teachingstaff[$tstaffid]['status']."\"></td></tr><br
> />\n";
> ...
>
> ... but NOT if $tstaffid is 0 ...
>
> Sorry to be so long-winded. I've checked the FAQ archives and can't
> find
> anything which helps.

You need to first be 100% sure that you don't have newlines in the
data itself.

If status should have no whitespace before/after it, you could also
just http://php.net/trim it for now, and figure out where the newline
is coming from later.  But you'll want to track it down, as this will
likely not go away until you understand where it comes from.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux