Jump to content

Recommended Posts

How would I get a form in an echo statment, is it even possible?

if ( $_GET['content'] == "pirep" ) { 
echo "<form name="form3" action="pirep_process.php" method="post">
<table cellpadding="8" align="center" cellspacing="0" width="80%" style="font-size: 10pt">
   <tr> 
      <td align="left" valign="top"> </td>
      <td ><input name="username" type="hidden" id="username" value="RPA001"></td>
   </tr>  
<tr> 
      <td align="left" valign="top">Booked Flights</td>
      <td >
<select name="Manual" size="1" onchange="window.open(this.options[this.selectedIndex].value,'_top')"> 
<option>Booked Flights</option>
<option value="book.php?id=" id=""></option>
</td>
   </tr>  
   <tr>
     <td align="left" valign="top">Date of Flight</td>
     <td><input name="date" type="text" id="date" value="2009-01-29"></td>
   </tr>
   <tr>
     <td align="left" valign="top">Departure Airport</td>
     <td><input name="icao_orig" type="text" id="icao_orig" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Destination Airport</td>
     <td><input name="icao_dest" type="text" id="icao_dest" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Type Aircraft</td>
     <td><select name="aircraft" type="text" id="aircraft"> 
         <option value="ERJ-170">ERJ-170/175</option>
</td>
   </tr>
   <tr>
     <td align="left" valign="top">Flight Number</td>
     <td><input name="routenum" type="text" id="routenum" value=""></td>
   </tr>

   <tr>
     <td align="left" valign="top">Flight Time</td>
     <td><input name="flthrs2" type="text" id="flthrs2" value=""></td>
   </tr>
   <tr>
     <td><input name="hub" type="hidden" id="hub" value="KPHL"></td>
   </tr>
   <tr> 
      <td align="left" valign="top">Comments:</td>
     <td><input name="comments" type="text" id="comments" value=""></td>
    </tr>
   <tr>
     <td align="left" valign="top">Online:</td>
     <td><select name="online" type="text" id="online"> 
         <option value="Yes">Yes</option>
         <option value="No">No</option>
</td>
</tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" name="Submit" value="File Pirep!"></td>
    </tr>
</table>
</form>";
} 

I am basicly trying to reduce the amount of files on my server and I dont know if this is possible, is it?

Link to comment
https://forums.phpfreaks.com/topic/142904-form-in-echo/
Share on other sites

for large amounts of HTML like that i find it is easier to close the php tags like this

<?php
if ( $_GET['content'] == "pirep" ) { 
?><form name="form3" action="pirep_process.php" method="post">
<table cellpadding="8" align="center" cellspacing="0" width="80%" style="font-size: 10pt">
   <tr> 
      <td align="left" valign="top"> </td>
      <td ><input name="username" type="hidden" id="username" value="RPA001"></td>
   </tr>  
<tr> 
      <td align="left" valign="top">Booked Flights</td>
      <td >
<select name="Manual" size="1" onchange="window.open(this.options[this.selectedIndex].value,'_top')"> 
<option>Booked Flights</option>
<option value="book.php?id=" id=""></option>
</td>
   </tr>  
   <tr>
     <td align="left" valign="top">Date of Flight</td>
     <td><input name="date" type="text" id="date" value="2009-01-29"></td>
   </tr>
   <tr>
     <td align="left" valign="top">Departure Airport</td>
     <td><input name="icao_orig" type="text" id="icao_orig" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Destination Airport</td>
     <td><input name="icao_dest" type="text" id="icao_dest" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Type Aircraft</td>
     <td><select name="aircraft" type="text" id="aircraft"> 
         <option value="ERJ-170">ERJ-170/175</option>
</td>
   </tr>
   <tr>
     <td align="left" valign="top">Flight Number</td>
     <td><input name="routenum" type="text" id="routenum" value=""></td>
   </tr>

   <tr>
     <td align="left" valign="top">Flight Time</td>
     <td><input name="flthrs2" type="text" id="flthrs2" value=""></td>
   </tr>
   <tr>
     <td><input name="hub" type="hidden" id="hub" value="KPHL"></td>
   </tr>
   <tr> 
      <td align="left" valign="top">Comments:</td>
     <td><input name="comments" type="text" id="comments" value=""></td>
    </tr>
   <tr>
     <td align="left" valign="top">Online:</td>
     <td><select name="online" type="text" id="online"> 
         <option value="Yes">Yes</option>
         <option value="No">No</option>
</td>
</tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" name="Submit" value="File Pirep!"></td>
    </tr>
</table>
</form>
<?php
} 
?>

your html will still only be outputted if the if statement returned true

 

Scott.

Link to comment
https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749194
Share on other sites

I prefer to use heredoc so that way you can include variables with {$variablename} instead of having to use <?php echo $variablename; ?> 

 

But that is just my preference :)

 

<?php
if ( $_GET['content'] == "pirep" ) { 
    echo <<<OUTPUT 
          <form name="form3" action="pirep_process.php" method="post">
<table cellpadding="8" align="center" cellspacing="0" width="80%" style="font-size: 10pt">
   <tr>
      <td align="left" valign="top"> </td>
      <td ><input name="username" type="hidden" id="username" value="RPA001"></td>
   </tr> 
<tr>
      <td align="left" valign="top">Booked Flights</td>
      <td >
<select name="Manual" size="1" onchange="window.open(this.options[this.selectedIndex].value,'_top')">
<option>Booked Flights</option>
<option value="book.php?id=" id=""></option>
</td>
   </tr> 
   <tr>
     <td align="left" valign="top">Date of Flight</td>
     <td><input name="date" type="text" id="date" value="2009-01-29"></td>
   </tr>
   <tr>
     <td align="left" valign="top">Departure Airport</td>
     <td><input name="icao_orig" type="text" id="icao_orig" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Destination Airport</td>
     <td><input name="icao_dest" type="text" id="icao_dest" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Type Aircraft</td>
     <td><select name="aircraft" type="text" id="aircraft">
         <option value="ERJ-170">ERJ-170/175</option>
</td>
   </tr>
   <tr>
     <td align="left" valign="top">Flight Number</td>
     <td><input name="routenum" type="text" id="routenum" value=""></td>
   </tr>

   <tr>
     <td align="left" valign="top">Flight Time</td>
     <td><input name="flthrs2" type="text" id="flthrs2" value=""></td>
   </tr>
   <tr>
     <td><input name="hub" type="hidden" id="hub" value="KPHL"></td>
   </tr>
   <tr>
      <td align="left" valign="top">Comments:</td>
     <td><input name="comments" type="text" id="comments" value=""></td>
    </tr>
   <tr>
     <td align="left" valign="top">Online:</td>
     <td><select name="online" type="text" id="online">
         <option value="Yes">Yes</option>
         <option value="No">No</option>
</td>
</tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" name="Submit" value="File Pirep!"></td>
    </tr>
</table>
</form>
OUTPUT;
} 
?>

Link to comment
https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749208
Share on other sites

Depending on the situation, I'll either use heredoc or escape out of the php tags and just do individual php tags when necessary.  He just asked if it was possible so I addressed that specifically.

 

:) I just got bored and saw rat's post and decided to reply with my 2cents, no offense to you in any way.

Link to comment
https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749220
Share on other sites

You can also do something like this:

 

<?php
echo <<<HERE
<b><h3><center>Chislam's Chat Box</center></h3></b>
<iframe src="chat.txt" width="700" height="250"></iframe>
<form method="post" name="form">Nickname: <input type="text' name="nickname" value="$nickname"><br>
Message:   <input type="text" name="message"><input type="submit" value="Submit">
</form>
<a href="chat.php">Refresh</a>
HERE;
?>

 

Notice the echo <<<HERE and the HERE; at the bottom; inbetween that, you can print pure HTML, and you don't need to escape any quotes or anything. That's what I use to echo quotes.

Link to comment
https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749224
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.