Php – How to handle multiple actions using a single html form

php

I hope I can be clear enough in what I need here. What I have is a function that contains some html for an email client app I'm developing. This part of the app uses a common forward, reply and "reply to all" form. Since they are all basically the same, I figured I'd go the lean route and just use a single function to handle this. The only real differences I can see between the 3 actions I mentioned above are that in a reply to all, there will be multiple email addys in the CC part of the form. For a forward, no (cc) and the (to) box should be blank. I need to represent all of this functionality and I'm kind of confused on what the best way to do this is. Can anyone please offer any help? Thanks.

I can certainly post the html is need be, I just wanted to start light.

EDIT:
I almost forgot, there will be POST values when the user submits the form in the event that the form validation fails.


function compose($type,$contents=null)
{
    echo'
        <tr>
          <td>
            <tr>
              <td valign="top">
                <form method="post" action="">
                  <table width="100%" cellpadding="0" cellspacing="0" border="0" id="reply">
                    <tr>
                      <td><h2>'.$type.'</h2></td>
                    </tr>
                    <tr>
                      <td width="1%" valign="top" nowrap><b>To:</b><br><input name="to" id="focus" title="Enter a single system user here" value="" type="text" size="64"></td>
                    </tr>
                    <tr>
                      <td nowrap><b>Cc:</b><br><input name="cc"" value="" type="text" size="64"></td>
                    </tr>
                    <tr>
                      <td nowrap><b>Subject:</b><br><input name="subject" title="Enter your subject here" value="" type="text" size="64" maxlength="30"></td>
                    </tr>
                    <tr>
                      <td valign="top"><b>Message:</b><br><textarea name="message" title="Enter your message here" rows="5" cols="50" wrap="virtual"></textarea></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td><input type="hidden" name="id" value=""><input type="submit" name="send" value="Send"></td>
                    </tr>
                  </table>
                </form>
              </td>
            </tr>
          </td>
        </tr>';
}

Best Solution

EDIT: Example modification of posted code (I haven't added all the different cases or even changed the output really, just showing the concept - all that's here is a check for a type of Reply and a check for the 'to' POST value.)

function compose($type,$contents=null)
{
    $toValue = '';
    if(isset($_POST['to']))
    {
        // Might want to actually validate this to prevent XSS, but this is just a basic example
        $toValue = $_POST['to'];
    }

    echo'
        <tr>
          <td>
            <tr>
              <td valign="top">
                <form method="post" action="">
                  <table width="100%" cellpadding="0" cellspacing="0" border="0" id="reply">
                    <tr>
                      <td><h2>'.$type.'</h2></td>
                    </tr>';

    if($type == "Reply") {
        echo'
                    <tr>
                      <td width="1%" valign="top" nowrap><b>To:</b><br><input name="to" id="focus" title="Enter a single system user here" value="' . $toValue . '" type="text" size="64"></td>
                    </tr>
                    <tr>
                      <td nowrap><b>Cc:</b><br><input name="cc"" value="" type="text" size="64"></td>
                    </tr>';
    }

    echo'
                    <tr>
                      <td nowrap><b>Subject:</b><br><input name="subject" title="Enter your subject here" value="" type="text" size="64" maxlength="30"></td>
                    </tr>
                    <tr>
                      <td valign="top"><b>Message:</b><br><textarea name="message" title="Enter your message here" rows="5" cols="50" wrap="virtual"></textarea></td>
                    </tr>
                    <tr>
                      <td> </td>
                    </tr>
                    <tr>
                      <td><input type="hidden" name="id" value=""><input type="submit" name="send" value="Send"></td>
                    </tr>
                  </table>
                </form>
              </td>
            </tr>
          </td>
        </tr>';
}

(Original inquiry) Is this function processing the results of the form, or is it displaying the form in the first place? Your question is a bit unclear about which point in the process you're talking about.

Related Question