Re: php form action breaks script

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

 





On 6/14/2012 7:28 PM, Tim Dunphy wrote:
Hello list,

  I was just wondering if I could get some opinions on a snippet of
code which breaks a php web page.

  First the working code which is basically an html form being echoed by php:

if ($output_form) {

   echo '<br /><br /><form action="sendemail.php>" method="post">
   <label for="subject">Subject of email:</label><br />
   <input id="subject" name="subject" type="text" size="30" /><br />
   <label for="elvismail">Body of email:</label><br />
    <textarea id="elvismail" name="elvismail" rows="8"
cols="40"></textarea><br />
    <input type="submit" name="Submit" value="Submit" />
   </form>';


   }

However if I change the form action to this, it breaks the page
resulting in a white screen of death:


   if ($output_form) {

   echo '<br /><br /><form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post">
   <label for="subject">Subject of email:</label><br />
   <input id="subject" name="subject" type="text" size="30" /><br />
   <label for="elvismail">Body of email:</label><br />
    <textarea id="elvismail" name="elvismail" rows="8"
cols="40"></textarea><br />
    <input type="submit" name="Submit" value="Submit" />
   </form>';


   }

Reverting the one line to this:

echo '<br /><br /><form action="sendemail.php" method="post">

gets it working again. Now I don't know if it's an unbalanced quote
mark or what's going on. But I'd appreciate any advice you may have.


Best,
tim

heredoc is best for this

if ($output_form){
  $report = <<<sty
<br /><br />
<form action="sendemail.php>" method="post"  >
<label for="subject">Subject of email:</label>
<br />
<input id="subject" name="subject" type="text" size="30" />
<br />
<label for="elvismail">Body of email:</label>
<br />
<textarea id="elvismail" name="elvismail" rows="8"cols="40"></textarea>
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
sty;
}





--
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