How do i go about doing a form which sends itself, basically what i want to do is for the 1 php file to display a form, when the submit button is pressed the form is emailed, now i know how to do the email bit, i just wasn't sure about how to have both form & mail code in 1 file, ie what is the form action, how do i reference the form's testboxes etc.?

cheers

jamie

    what you need to do is

    <? if ( $been == "Y" ) { ?>

    //email code goes here

    <? } else { ?>

    // form goes here.

    <FORM action="<? echo $PHP_SELF; ?>" method="post">
    <INPUT type="hidden" name="been" value="Y">

    //rest of form

    </FORM>
    <? } ?>

    The been variable tells the script if the user has submited the for to this script if there havent then the form is displayed.
    To reference the variables that are used in the form just use the name so if you create a textbox with the name of emailadd then you can just use the variable emailadd.

    Mark.

      Thanks for this thats great, just to clarify tho,i would for example do print "$emailadd"

        don't bother answering i tested and found that i was assuming the correct thing amd its working, Cheers Mark!

          1. The form should POST data back to itself (using $PHP_SELF).

          2. The script should start with some logic like this:

          if ($REQUEST_METHOD == 'POST')
          &nbsp;&nbsp;{
          &nbsp;&nbsp;// you're getting the form data, do something with it
          &nbsp;&nbsp;}
          else
          &nbsp;&nbsp;{
          &nbsp;&nbsp;// generate the form
          &nbsp;&nbsp;}

          A slightly better variant of this, if you have to do a lot of form validation, is:

          function generate_form( ... parameters here...)
          {
          global $PHP_SELF, ....;
          }

          if ($REQUEST_METHOD == 'POST')
          &nbsp;&nbsp;{
          &nbsp;&nbsp;if ( validate_fields(...) )
          &nbsp;&nbsp;&nbsp;&nbsp;{
          &nbsp;&nbsp;&nbsp;&nbsp;// do something with the data...
          &nbsp;&nbsp;&nbsp;&nbsp;}
          &nbsp;&nbsp;else
          &nbsp;&nbsp;{ // one or more fields not correct, redisplay the form
          &nbsp;&nbsp;generate_form(...);
          &nbsp;&nbsp;}
          else
          &nbsp;&nbsp;{ // must be a GET, display an empty form:
          &nbsp;&nbsp;generate_form(...);
          &nbsp;&nbsp;}

          if ($REQUEST_METHOD == 'POST')
          &nbsp;&nbsp;

            Write a Reply...