Separating PHP and HTML - Please Help


I got this tutorial for a drop down box. But i would like to separate the code.

The form should be in its own html file, it should not contain any php code. Example: form.html
The php code should be in a separate php file. Example: codeform.php

My question.
How can i access my code without them being in the same page.
What do i need to write in the form.html to access the php file.

Here is the code:
if(!isset($_POST[‘submit’])) # If this form has not been submitted
$chosen = array(3, 6, 2, 7); # Use the default
else # Otherwise
$chosen = $_POST[‘colors’]; # Use what has been submitted

function showOptionsDrop($array, $active, $echo=true){
    $string = '';

    foreach($array as $k =&gt; $v){
            $s = (in_array($k, $active))? ' selected="selected"' : '';
            $s = ($active == $k)? ' selected="selected"' : '';
        $string .= '&lt;option value="'.$k.'"'.$s.'&gt;'.$v.'&lt;/option&gt;'."\


    if($echo)   echo $string;
    else        return $string;

$colors = array('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'pink', 'black', 'white', 'silver', 'gold');


///needs to be in separate html file
<form name=“colorform” action=“” method=“post”>
<select name=“colors” multiple=“multiple” size=“15”>

    &lt;?php echo showOptionsDrop($colors, $chosen, true); ?&gt;

&lt;/select&gt;&lt;br /&gt;
&lt;input type="submit" name="submit" value="submit" /&gt;



You cannot. Not without relying on things like javascript and ajax.

You can separate the model and the view, but that seems to be similar to what is happening to the form already.

The problem you will have, is that you will only replace PHP with a templating language. The aim is to separate code which isn’t relevant to presentation from the template, not remove code altogether.

I don’t think you can do that.

You’d write

<?php include 'myfile.php' ?>

To use it but I’m not 100% as I still think your HTML file would itself have to be a PHP file to use that code. I might be wrong though, never tried it.

And you could include the HTML in a PHP file instead, echo it if it has not been POSTed.

You were all right it was not possible. I started using smarty and that did the trick