PHP Redux

 To determine IF the form has been submitted, I(the author) normally check IF the $submit variable is set ( which is the name of the submit input type in the form used).


  below show's the most common way of checking or to determine if a form had been submitted and as follows:


  ex.: 


  IF ( isset($_POST['submit'])) {


    # handle code here

    . . . .

    . . .

  } else {


    # display the form here

    echo '< input type="submit" ',

            'name="submit" ',

            'value="Go !"/>';

   }


  IF you want to handle a form and then display it again ( to add a record and then give an option to add another) use;


  ex. : 


  If ( !isset($_POST['submit'])) {


     # handle the form here

     . . . . .

  }

  # display the form here

  . . . .

  . . ....


  The next set of codes (below), was crafted to show, how PHP can be used to trap empty fields in an entry form.   Please take note that the said form called itself to re-check if the said values entered are correct, not empty.

 

  < ?php


  If ( isset($_POST['submit'])) {

      . . . ..

      . . ..

  } else {

  ?>


  < form action=" < ?php echo $_SERVER['PHP_SELF']; ?>" method="post">


  < fieldset>

   . . . .

   . . . .

  </fieldset>

  < div align="center">

  < input type="submit" name="submit" value="Submit Information"/>

  </div>

  </form>

  }