As batmegakapa has already explained, doing logic / generating and viewing content are two different tasks. The complexity of modern web applications often requires such an approach in order to preserve readable and understandable code, and possibly also to be reused.
This is (approximately) the reason why the MVC model (model / view / controller) and template systems today are components of most frameworks.
Of course, it is impossible to give one solution, because it depends on personal preferences and requirements that make this issue controversial, too localized and do not customize Q & A-style.
However, following the rule, so as not to mix logic and content, you will most likely do it like this (basic aproach):
no_internet_form.php :
<?php if(isset($_POST['submit']) && $_POST['no_internet']) { //echo "<h2>Response</h2><br />"; $Version = $_POST["isVersion"]; $no_internet = $_POST["no_internet"]; $script_result = execute_the_incredibly long_script($Version, $no_internet); } // more business logic ... include 'views/no_internet_form.html.php'; ?>
views/no_internet_form.html.php :
<?php if(isset($script_result)): ?> <div class="ResponseBox" style="background-position: 0 0;"> <div class="ResponseText"> <?php echo $script_result; ?> </div> </div> <?php endif;
One more thing, by the way: I had doubts about what part of the code you provided really belongs to the if block, because it was not obvious to me. The HTML code for your example somehow doesn't make much sense.
This may be just for demonstration, but it took a few seconds to really understand the meaning of your example in my head. This should be more readable - especially in large projects.
Lukas source share