|  | Posted by William Gill on 06/26/07 15:51 
David Gillen wrote:> William Gill said:
 >> OK this may seem stupid, but I use this template for my php/html forms
 >> so that processing and form are in the same document.
 >>
 >>    <?php if (array_key_exists('_submit_check',$_POST)) {
 >>
 >>       php code to process form data and html to display a message
 >>       to the user goes here.
 >>            ...
 >>            ...
 >>
 >>    <?php } else { ?>    // close if block, open else block
 >>
 >>       html and form go here.
 >>      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 >>    	  <input type="hidden" name="_submit_check" value="1"/>
 >>            ...
 >>            ...
 >>
 >>    <?php } ?>    // close else block
 >>
 >> In theory it's great, but after I get a whole lot of html in the gaps it
 >> gets really hard to follow and edit, especially if I'm editing months later.
 >>
 >> I tried indenting the html inserts, but as my php gets more involved,
 >> and properly indented (especially in the processing block) that gets
 >> pretty messy.
 >>
 > If you code is that long that you can't follow it easily you need to break it
 > down into various functions to handle what you are doing. Put these functions
 > into an include file.
 >
 
 Actually, it's the html that obscures the php.
 
 When I make a php template, I don't have any trouble reading and
 following the code, but after I add a couple dozen lines of html It's
 hard to see where a logical php block begins and ends.
 
 This is easy to follow:
 <?php
 if ($a > $b) {
 echo "a is bigger than b";
 } else {
 echo "a is NOT bigger than b";
 }
 ?>
 
 but when '<?php if ($a > $b) { ?>' and '<?php } else { ?>' are separated
 by many lines of html, it isn't so easy.
 
 >
 > <?php if (array_key_exists('_submit_check',$_POST)) {
 > 	processSubmission();
 > <?}else{?>
 > 	processNormal();
 > <?}?>
 >
 > I'd also loose the comments about closing and opening blocks, they are
 > completely unnecessary.
 >
 > D.
 [Back to original message] |