NYCPHP Meetup

NYPHP.org

[nycphp-talk] Can code be executed in a heredoc?

keith at keithjr.net keith at keithjr.net
Tue Feb 17 08:34:58 EST 2004


One way that I would do it is break out of the print statement, and then
execute the if statement, print the appropriate menu, and then go back
into the heredoc.

Or you could execute a switch statement before hand, that handles the
$_POST variables, and then have a varaible of say $selectstatement set to
the appropriate select code that prints out in the heredoc.. so it would
be like

     I am submitting ...
     $selectstatement
     <br />

instead of that whole if statement.


> Hello,
> I wanted to use a heredoc, because it was easy to send out formatted text.
>  So, I was using this function I created to print out an HTML form and
> reuse it on postback.  I know that in a heredoc, simple variables can be
> resolved.  But I ran into a situation where I need to display a different
> dropdown depending on the value of this dropdown on postback (or if the
> $_POST doesn't exist).
>
> The example below is what I was trying to do.  Instead, PHP displayed the
> if statement as text.
>
> Does anybody have suggestions?  I could try to check the dropdown value
> outside this function and fill a variable with an HTML string and then
> insert in the heredoc.
>
> Thanks,
> Stephen
>
> ----------------------------
>
> function printForm()
> 	{
> 		global $errorMessage;
>
> 		echo <<< UPLOADFORM
> 		<p>* denotes a required field.</p>
>
> 		<form action="$_SERVER[PHP_SELF]" method="post"
> enctype="multipart/form-data">
>
> 		<table cellpadding="5" cellspacing="5" class="submissionstable">
> 		<tr>
> 		<td class="submissionfieldname">Name *:</td>
> 		<td class="submissionerrorfield"><input type="text" name="username"
> size="30" value="$_POST[username]" /> $errorMessage[username]</td>
> 		</tr>
> 		<tr>
> 		<td class="submissionfieldname"> </td>
> 		<td style="color: #ffffff; font-family: arial, helvetica, sans-serif,
> verdana; font-size: 10pt; text-align: left;"><br />
> 		I am submitting ...
> 		if isset($_POST[lyricstype])
> 		{
> 			<select name="lyricstype">
> 			if ($_POST[lyricstype] == "none")
> 			{
> 				<option value="none" selected="selected">neither a romanization or
> translation</option>
> 			}
> 			else
> 			{
> 				<option value="none">neither a romanization or translation</option>
> 			}
>
> 			if ($_POST[lyricstype] == "romanization")
> 			{
> 				<option value="romanization" selected="selected">a
> romanization</option>
> 			}
> 			else
> 			{
> 				<option value="romanization">a romanization</option>
> 			}
>
> 			if ($_POST[lyricstype] == "translation")
> 			{
> 				<option value="translation" selected="selected">a translation</option>
> 			}
> 			else
> 			{
> 				<option value="translation">a translation</option>
> 			}
> 			</select>
> 		}
> 		else
> 		{
> 			<select name="lyricstype">
> 				<option value="none" selected="selected">neither a romanization or
> translation</option>
> 				<option value="romanization">a romanization</option>
> 				<option value="translation">a translation</option>
> 			</select>
> 		}
> 		<br />
> 		<br /></td>
> 		</tr>
> 		</table>
> 		</form>
> UPLOADFORM;
> 	}	// End function printForm()
> --
> ___________________________________________________________
> Sign-up for Ads Free at Mail.com
> http://promo.mail.com/adsfreejump.htm
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>


>From hans not junk at nyphp.com  Tue Feb 17 08:38:16 2004
Return-Path: <hans not junk at nyphp.com>
Received: from ehost011-1.exch011.intermedia.net (unknown [64.78.21.3])
	by virtu.nyphp.org (Postfix) with ESMTP id 27A4AA85E9
	for <talk at lists.nyphp.org>; Tue, 17 Feb 2004 08:38:16 -0500 (EST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: RE: [nycphp-talk] Can code be executed in a heredoc?
Date: Tue, 17 Feb 2004 05:38:13 -0800
Message-ID: <41EE526EC2D3C74286415780D3BA9F87937411 at ehost011-1.exch011.intermedia.net>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [nycphp-talk] Can code be executed in a heredoc?
Thread-Index: AcP1FIcAkzkDaI+OQx6RQYP3dK2x8QARmFIQ
From: "Hans Zaunere" <hans not junk at nyphp.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
X-BeenThere: talk at lists.nyphp.org
X-Mailman-Version: 2.1.2
Precedence: list
Reply-To: NYPHP Talk <talk at lists.nyphp.org>
List-Id: NYPHP Talk  <talk.lists.nyphp.org>
List-Unsubscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
	<mailto:talk-request at lists.nyphp.org?subject=unsubscribe>
List-Archive: <http://lists.nyphp.org/pipermail/talk>
List-Post: <mailto:talk at lists.nyphp.org>
List-Help: <mailto:talk-request at lists.nyphp.org?subject=help>
List-Subscribe: <http://lists.nyphp.org/mailman/listinfo/talk>,
	<mailto:talk-request at lists.nyphp.org?subject=subscribe>
X-List-Received-Date: Tue, 17 Feb 2004 13:38:16 -0000


> function printForm()
> 	{
> 		global $errorMessage;
> =09
> 		echo <<< UPLOADFORM
> 		<p>* denotes a required field.</p>
> 	=09
> 		<form action=3D"$_SERVER[PHP_SELF]" method=3D"post"=20
> enctype=3D"multipart/form-data">

Personally, I wouldn't use a heredoc for this purpose.  Instead, break =
out of PHP mode, like so...


function printForm()
{

global $errorMessage;

?>

<p>*denotes a required field.</p>

<form action=3D"<?=3D$_SERVER['PHP_SELF']?>" method=3D"post" =
enctype=3D"multipart/form-data">

....

<php

}



I always use this method outputting large amounts of text and it's =
worked very well, and with quite clean code.

H




More information about the talk mailing list