Cooper94 Posted January 29, 2009 Share Posted January 29, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/142904-form-in-echo/ Share on other sites More sharing options...
.josh Posted January 29, 2009 Share Posted January 29, 2009 yes, you can do that. But since you use " ... " to encapsulate your string, you need to escape all occurrences of " inside your string, like this: \" so that php knows that you aren't trying to close your string quotes. Quote Link to comment https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749192 Share on other sites More sharing options...
ratcateme Posted January 29, 2009 Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749194 Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749208 Share on other sites More sharing options...
.josh Posted January 29, 2009 Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749218 Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749220 Share on other sites More sharing options...
slpctrl Posted January 29, 2009 Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142904-form-in-echo/#findComment-749224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.