Good Programming Practices With PHP With Concatenating HTML -
i'm trying concatenate php html , wondering best practice is. far, have approached so: --edited display full script--
<?php include("header.php"); ?> <div id="main"> <table id="maintable"> <tr> <td id="leftpane"> <div class="pgbody"> <div class="subblock"> <form action="<?php echo htmlentities($_server['php_self']); ?>" method="post"> <table width="100%" cellpadding="10" cellspacing="0"> <tr> <td colspan="3" style="width:99%"> <label for="isversion">installshield version</label><br /> <select name="isversion" onchange="javascript:settimeout('__dopostback(\'ddlversion\',\'\')', 0)" id="isversion" class="box"> <option value="2012spring">2012 spring</option> <option value="2012">2012</option> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2009 express">2009 express</option> <option value="is2008">2008</option> <option value="is2008 express">2008 express</option> </select> <tr> <td colspan="3" style="width:99%"> <br /> <input type="checkbox" name="no_internet" value="no_internet"> no_internet </td> </tr> <tr> <td colspan="3" style="width:99%"> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </tr></table> <?php if(isset($_post['submit'])) { echo "<h2>response</h2><br />"; $isversion = $_post["isversion"]; $output_script = " <p>hello, <br /> activate installshield, please follow steps below:<br /><br /> 1. launch command prompt window , browse directory - 'c:\program files\installshield\\$isversion\system' (or 'program files (x86)' on 64 bit machine)<br /> 2. need pass parameter '/return' executable 'tsconfig' below<br /> 'c:\program files\installshield\\$isversion\system\tsconfig.exe /return'<br /> 3. providing machine has valid internet connection license deactivate , message in dialog reflect this<br /> 4. re-launch installshield.exe , presented same activation dialog before<br /> 5. proceed activation normally<br /> 6. dialog should show successful activation message , product should remain activated @ stage.<br /> </p>"; ?> <div class="responsebox" style="background-position: 0 0;"> <div class="responsetext"> <?php echo $output_script; } ?> <?php elseif(isset($_post['submit']) && $_post['no_internet']) { echo "<h2>response</h2><br />"; $isversion = $_post["isversion"]; $no_internet = $_post["no_internet"]; $output_script = " <p>hello, <br /> activate installshield, please follow steps below:<br /><br /> 1. launch command prompt window , browse directory - 'c:\program files\installshield\\$isversion\system' (or 'program files (x86)' on 64 bit machine)<br /> 2. need pass parameter '/return' executable 'tsconfig' below<br /> 'c:\program files\installshield\\$isversion\system\tsconfig.exe /return /$no_internet'<br /> 3. providing machine has valid internet connection license deactivate , message in dialog reflect this<br /> 4. re-launch installshield.exe , presented same activation dialog before<br /> 5. proceed activation normally<br /> 6. dialog should show successful activation message , product should remain activated @ stage.<br /> </p>"; ?> <div class="responsebox" style="background-position: 0 0;"> <div class="responsetext"> <?php echo $output_script; } ?> </div> </div> </div> </td> <td id="rightpane"> <div class="promobox" style="background-position: 0 0;"> <div class="promotext"> <?php echo "<h2>related kb article: </h2><br />"; echo "<h3>deactivation of - q201081</h3>"; ?> </div> </div> </td> </tr> </tr> </table> </div> as can see php , html concatenate 1 , when required. wondering, if best approach , should use php echo rather doing above?
trying write elseif block below gives me error states elseif unexpected, makes me think i'm approaching whole thing wrong.
when @ huge projects people have made, i've noticed barely within each file, , not lot of html visible. correct in assuming of goes within objects or classes? suggestions or references appreciated. in advance.
you'll different description of "best practices" different people. go psr-1 code formatting standards, includes important point:
- files should either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) should not both.
i recommend php code not print out html directly @ use templates instead. i'm big fan of templating engines, , there ton of them out there. people "php templating engine," , use if wanted. keep logic out of template (display) possible.
decide on standards ahead of time team , stick them. there may variance in opinion whether echo or ?> better, once have decided, consistent. it's important keep indentation consistent too. if that, you'll able find missing brace makes elseif incorrect.
Comments
Post a Comment