Posted by: Sourav | May 23, 2011

More dynamic form using PHP


form2.php

<html>
    <head>
        <title>
            Form number 2
        </title>
        </head>
        <body>
           
           <table align=”center” border=”0″ bordercolor=”black” bgcolor=”white”
                  width==”600″>
           
            <tr>
                <td>
        
                <fieldset>
                    <legend>
                        <b> <i>Author Details:</i></b>
                    </legend>
                    <table>
                    <form action=”result2.php” method=”post” name=”authorform”>
                       <tr>
                        <td>
                           <b><i> <font color=”blue”><?php echo $msg;?></font></i><b>
                        </td>
                       </tr>
                       <table align=”center”>
                       <tr>
                        <td align=”center” >
                            Please enter the information to get access the resources available
                        </td>
                       </tr>
                       </table>
                       <br />
                       <table>
                       <tr>
                       <td>
                        Author Name:&nbsp;
                       </td>
                       <td>
                        <input type=”text” size=”70″ tabindex=”1″ name=”authorname”
                               value=”<?php echo $_POST[‘authorname’];?>”>
                       </td>
            </tr>
           
            <tr>
                <td align=”center” colspan=”2″>
                    (Format: <b>Firstname</b>[:SPACE:]<b>Middlename</b>[:SPACE:]<b>Lastname</b>)
           
                </td>
               
            </tr>
                      
                      
            <tr>
               
                <td>
                    Birthdate:
                </td>
                <td>
                    <input type=”text” name=”birthdate” size=”20″ tabindex=”2″
                           value=”<?php echo $_POST[‘birthdate’];?>”>
                </td>
            </tr>
            <tr>
                <td align=”center” colspan=”2″>
                    (Format: <b>dd/mm/yyyy</b> or <b>dd.mm.yyyy</b> or <b> dd-mm-yyyy </b>)
           
                </td>
               
            </tr>
            <tr>
               
                <td>
                   Qualifications:
                </td>
                <td>
                    <input type=”text” name=”qualifications” size=”70″ tabindex=”3″
                           value=”<?php echo $_POST[‘qualifications’];?>”>
                </td>
            </tr>
                    <tr>
                <td align=”center” colspan=”2″>
                    (Use commas for multiple qualification)
           
                </td>
               
            </tr>
                    <tr>
               
                <td>
                   Speciality:
                </td>
                <td>
                    <textarea cols=”50″ rows=”6″ name=”speciality” tabindex=”4″
                       value=”<?php echo $_POST[‘speciality’];?>”></textarea>
                </td>
            </tr>
                   <tr>
                <td align=”center” colspan=”2″>
                    (Enter data in 5 lines)
           
                </td>
               
            </tr>
                       </table>
                   <table align=”center”>
                    <tr>
               
               
                <td align=”center”>
                    <input type=”submit” name=”submit” value=”submit” tabindex=”5″>
                        <input type=”reset” name=”reset” value=”clear” tabindex=”5″>    
                </td>
            </tr>
                   </table>
                       </table>
           
                    </form>
                    </table>
                </fieldset>
                </td>
            </tr>
           </table>
          
           
           
        </body>
       
</html>
       
    result2.php

<?php

if(empty($_POST[‘authorname’]))
{
    $msg=”Please enter the author’s name”;
    include(“form2.php”);
    exit;
}

if(ereg(“([[:space:]]){2}”,$_POST[‘authorname’]))
{
    $msg=”Please do not use double space in author’s name”;
    include(“form2.php”);
    exit;
}

if(empty($_POST[‘birthdate’]))
{
    $msg=”Please enter the author’s birthdate”;
    include(“form2.php”);
    exit;
}
if(!ereg(“^([0-9]){2}[/.-]([0-9]){2}[/.-]([0-9]){4}$”,$_POST[‘birthdate’]))

{
    $msg=”Author’s birthdate format is not correct”;
    include(“form2.php”);
    exit;
}

if(empty($_POST[‘qualifications’]))
{
    $msg=”Please enter the author’s qualification”;
    include(“form2.php”);
    exit;
}
if(empty($_POST[‘speciality’]))
{
    $msg=”Please enter the author’s speciality”;
    include(“form2.php”);
    exit;
}

?>
<html>
    <head>
        <title>
            Result Page
        </title>
    </head>
    <body>
      <table width=”600″ border=”1″ cellpadding=”1″ cellspacing=”1″
             align=”center”>
        <?php list($firstname,$middlename,$lastname)=split(” “,$_POST[‘authorname’],3);?>
        <?php if($lastname==””)
        {?>
        <tr>
            <td align=”center”><?php echo $firstname;?></td>
         <td align=”center”><?php echo $middlename;?></td>
        </tr>
        <tr>
            <td align=”center”>Firstname</td>
            <td align=”center”>Lastname</td>
        </tr>
        <?php }
        else
        { ?>
          <tr>
            <td align=”center”><?php echo $firstname;?></td>
         <td align=”center”><?php echo $middlename;?></td>
         <td align=”center”><?php echo $lastname;?></td>
        </tr> 
       <tr>
            <td align=”center”>Firstname</td>
            <td align=”center”>Lastname</td>
        </tr>
      <?php } ?>
      </table>
         <br />
         <br />
        <?php $_POST[‘birthdate’]=ereg_replace(‘[/.-]’,’ ‘,$_POST[‘birthdate’]);?>
       
        <table width=”600″ border=”1″ cellpadding=”1″ cellspacing=”1″
             align=”center”>
       
        <tr>
            <td>
                <?php echo $_POST[‘birthdate’];?>
            </td>
            <td>
                <b><i>Birthdate</i></b>
            </td>
       
        </tr>
        </table>
        <br />
        <br />
         <table width=”600″ border=”1″ cellpadding=”1″ cellspacing=”1″
             align=”center”>
            <?php
            $a=1;
            $qual=split(“,”,$_POST[‘qualifications’]);
           
               
        foreach($qual as $fld)
        {
           
       ?>
       <tr>
        <td align=”center”>
            <?php echo $fld;?>
        </td>
        <td>
            <?php echo “Qualification number $a”;
             $a=$a+1;?>
        </td>
        </tr>
       <?php } ?>
     
 
   
         </table>
        <br />
        <br />
        <table width=”600″ border=”1″ cellpadding=”1″ cellspacing=”1″
             align=”center”>
            <?php
            $a=1;
            $spe=split(“,”,$_POST[‘speciality’]);
           
               
        foreach($qual as $fld)
        {
           
       ?>
       <tr>
        <td align=”center”>
            <?php echo $fld;?>
        </td>
        <td>
            <?php echo “Speciality number $a”;
             $a=$a+1;?>
        </td>
        </tr>
       <?php } ?>
     
 
   
         </table>
       
       
       
       
    </body>
</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: