create 3 arrays. first array last names, second name first name and third array has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a web-based messageboard type app, I have a script that grabs messages from a MySQL db and then spit them out in a table with a reply button at the bottom of the message. however, certain messages don't show the reply button, its there in the html code, just not being displayed. I am currently blaming CRs generated by the textarea (by the way i'm not using CGI.pm at this time) anyway right now what I think I need to do is remove any blank lines at the end of the string, I've already got code for changing line breaks to
and and then back for the reply button, but its still not showing the reply button once in a while ok enough rambling, here's some code:
foreach( $msg_num = $msg_count -1; $msg_num >= 0; $msg_num--){ foreach( $i = 0; $i < @messages; $i++){ $sth = $dbh->prepare("select $messages[$i] from messages limit $ +msg_num, 1"); $sth->execute; $messageval[$i] = $sth->fetchrow_array; $sth->finish; }; $from = $messageval[0]; $date = $messageval[1]; $subject = $messageval[2]; $message = $messageval[3]; $msg_id = $messageval[4]; $message =~s/(\r\n|\n\r|\r)/<BR>\n/g; $message =~s/\n{3,}/\n\n/g; print "<TR><TD>\n"; print "Date: $date<BR>\nFrom: $from<BR>\nSubject: $subject<BR>\nMes +sage:<BR>\n$message<BR>\n"; print "<FORM METHOD='POST' ACTION='mb_post.pl'>\n"; print "<INPUT TYPE='HIDDEN' NAME='MSG_ID' VALUE='$msg_id'>\n"; print "<INPUT TYPE='HIDDEN' NAME='FROM' VALUE='$from'>\n"; print "<INPUT TYPE='HIDDEN' NAME='DATE' VALUE='$date'>\n"; print "<INPUT TYPE='HIDDEN' NAME='SUBJECT' VALUE='$subject'>\n"; $message = $messageval[3]; $message =~s/(\r\n|\n\r|\r)/\n/g; print "<INPUT TYPE='HIDDEN' NAME='MESSAGE' VALUE='$message'>\n"; print "<INPUT TYPE='SUBMIT' NAME='REPLY' VALUE='Reply'>\n</FORM>"; print "</TD></TR>\n"; };
also if you have suggestions as to how I can clean or speed this up it will be appreciated :)

Replies are listed 'Best First'.
Re: textareas, form scripts, line breaks etc
by arturo (Vicar) on Mar 02, 2001 at 21:26 UTC

    Since you're using HTML tables, you should be aware that Netscape 4.x will not display anything within a table in the browser window if you don't close all the table tags. I don't see enough code here to see where you start or where you end your HTML tables. But that would by my first stab at what's going wrong. Also, if the user puts in HTML tags, this could break various things. You are doing sanity checks on your input, I hope! Since browsers are supposed to ignore more than one whitespace character in a row (including \r, \n, \t, and spaces), I doubt it's the \r's coming in from your textarea.

    NOT a P.S. see use CGI or die; for why you should use CGI.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      actually, i'm already doing that, --a bit more of my code:
      print "<HTML>\n<TITLE>$mb_title</TITLE>\n<BODY BACKGROUND=$bgpic BGCOL +OR=$bgcolor>\n"; print "<CENTER><FONT SIZE =+3>$mb_title<P></FONT></CENTER>\n"; print "<B>By the way, if you didn't notice, this is under construction +<BR></B>\n"; print "<TABLE BORDERCOLOR=$bordercolor BORDER=$bordersize>\n"; foreach( $msg_num = $msg_count -1; $msg_num >= 0; $msg_num--){ foreach( $i = 0; $i < @messages; $i++){ $sth = $dbh->prepare("select $messages[$i] from messages limit $ +msg_num, 1"); $sth->execute; $messageval[$i] = $sth->fetchrow_array; $sth->finish; }; $from = $messageval[0]; $date = $messageval[1]; $subject = $messageval[2]; $message = $messageval[3]; $msg_id = $messageval[4]; $message =~s/(\r\n|\n\r|\r)/<BR>\n/g; $message =~s/\n{3,}/\n\n/g; print "<TR><TD>\n"; print "Date: $date<BR>\nFrom: $from<BR>\nSubject: $subject<BR>\nMes +sage:<BR>\n$message<BR>\n"; print "<FORM METHOD='POST' ACTION='mb_post.pl'>\n"; print "<INPUT TYPE='HIDDEN' NAME='MSG_ID' VALUE='$msg_id'>\n"; print "<INPUT TYPE='HIDDEN' NAME='FROM' VALUE='$from'>\n"; print "<INPUT TYPE='HIDDEN' NAME='DATE' VALUE='$date'>\n"; print "<INPUT TYPE='HIDDEN' NAME='SUBJECT' VALUE='$subject'>\n"; $message = $messageval[3]; $message =~s/(\r\n|\n\r|\r)/\n/g; print "<INPUT TYPE='HIDDEN' NAME='MESSAGE' VALUE='$message'>\n"; print "<INPUT TYPE='SUBMIT' NAME='REPLY' VALUE='Reply'>\n</FORM>"; print "</TD></TR>\n"; }; print "</TABLE>\n"; print "</BODY>\n</HTML>\n";
      I dont really have sanity checks just yet, I was gonna throw those in later, this is my first project, so i'm kinda just picking it up as I go along I'm hoping to throw in the option of html formatting(maybe even buttons for generating it), but may wind up tossing that idea out. The resulting html code (for the messages that don't show the reply button) looks like this:
      <TR><TD> Date: 26 Feb 2001 23:50:30 -0000<BR> From: merlin@ethernaut.net<BR> Subject: this is a test with lynx<BR> Message:<BR> I'm testing lynx<BR> <BR> <BR> <BR> oh yeah....by the way....<BR> <BR> <BR> <BR> yamama<BR> <BR> <BR> <BR> <FORM METHOD='POST' ACTION='mb_post.pl'> <INPUT TYPE='HIDDEN' NAME='MSG_ID' VALUE='<20010302152810.22993.qmail@ +ethernaut.net>'> <INPUT TYPE='HIDDEN' NAME='FROM' VALUE='merlin@ethernaut.net'> <INPUT TYPE='HIDDEN' NAME='DATE' VALUE='26 Feb 2001 23:50:30 -0000'> <INPUT TYPE='HIDDEN' NAME='SUBJECT' VALUE='this is a test with lynx'> <INPUT TYPE='HIDDEN' NAME='MESSAGE' VALUE='I'm testing lynx oh yeah....by the way.... yamama '> <INPUT TYPE='SUBMIT' NAME='REPLY' VALUE='Reply'> </FORM></TD></TR>
        This is a html problem, not a perl problem. The HTML is there, it's just invalid.

        In particular, you need double-qoutes if your form values are allowed to include single-quotes:

        VALUE='I'm testing lynx..'
        needs to become:
        VALUE="I'm testing lynx"

(tye)Re: textareas, form scripts, line breaks etc
by tye (Sage) on Mar 02, 2001 at 21:56 UTC

    Well, a subject that contained '></form> in it would certainly give you problems. I don't see how newlines, carriage returns, nor other whitespace characters could have any impact here.

            - tye (but my friends call me "Tye")
      yeah I agree, and I dont see how whitespace is causing the problem either I also in fact, i looked at the source, copied the afflicting TR, added missing html tags, etc. and then opened it as a single .html file, same result, so I removed the line breaks, and the reply button shows up, so i put the line breaks back, and its still there, so i figured lynx was using some line break char other than \n or \r, but then one of my test replies in IE5 did the same thing:
      <TABLE BORDERCOLOR=GREEN BORDER=2> <TR><TD> Date: 2 Mar 2001 15:34:12 -0000<BR> From: merlin@ethernaut.net<BR> Subject: RE: trying to get it to url-redirect<BR> Message:<BR> ok lets go back to WRAP='SOFT'<BR> <BR> ---------------------------------------------------------------------- +--------------------------------------------------------------------- +--------------------------<BR> <BR> one line?<BR> <BR> <BR> <BR> ---------------------------------------------------------------------- +----------<BR> <BR> On 26 Feb 2001 21:18:26 -0000,<BR> <BR> no@canthaveit.com wrote:<BR> <BR> Subject: trying to get it to url-redirect<BR> <BR> Message:<BR> <BR> it should print the message, then redirect to the messageboard<BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <FORM METHOD='POST' ACTION='mb_post.pl'> <INPUT TYPE='HIDDEN' NAME='MSG_ID' VALUE='<a05010400b6bd151b8737@[192. +168.2.3]>'> <INPUT TYPE='HIDDEN' NAME='FROM' VALUE='merlin@ethernaut.net'> <INPUT TYPE='HIDDEN' NAME='DATE' VALUE='2 Mar 2001 15:34:12 -0000'> <INPUT TYPE='HIDDEN' NAME='SUBJECT' VALUE='RE: trying to get it to ur +l-redirect'> <INPUT TYPE='HIDDEN' NAME='MESSAGE' VALUE='ok lets go back to WRAP='SO +FT' ---------------------------------------------------------------------- +--------------------------------------------------------------------- +-------------------------- one line? ---------------------------------------------------------------------- +---------- On 26 Feb 2001 21:18:26 -0000, no@canthaveit.com wrote: Subject: trying to get it to url-redirect Message: it should print the message, then redirect to the messageboard '> <INPUT TYPE='SUBMIT' NAME='REPLY' VALUE='Reply'> </FORM></TD></TR>
      I think I'll be switching to CGI.pm, which will probably require a virtual rewrite, but I'm still really curious about this

        I suspect the subject being "ok lets go back to WRAP='SOFT'" is the culprit (and what happened to the > on the end of that tag?).

                - tye (but my friends call me "Tye")