Posted by: Sourav | May 26, 2011

Another dynamic form in php


form3.php

<html>
    <head>
        <title>
            Form 3
        </title>
    </head>
        <body bgcolor=”black”>
       <table width=”600″ align=”center” border=”0″
              bordercolor=”orange” bgcolor=”black”>
        <tr>
            <td>
                <fieldset>
                        <legend>
                            <b><i><font color=”orange” size=”4″>Author’s form</font></i></b>
                               
                        </legend>
                <table align=”center”>
                  
                   
            <form name=”authorform” action=”result3.php” method=”post”>
               
          
                  
                  <center><b><font color=”orange”> <?php echo $msg;?></font></b></center>
                  
               
               
               
              
            <tr>
                <td colspan=”2″ align=”center”>
                  
                   <font color=”white”> Please enter the information below to get access to the resources</font>
                  
                  
                </td>
            </tr>
              <tr>
                <td>
                    <br />
                </td>
              </tr>
            <tr>
                <td>
                    <font color=”white”>Author’s Name:</font>
                </td>
                <td>
                    <input type=”text” name=”authorname” size=”70″ tabindex=”1″
                           value=”<?php echo $msg;?>” >
                </td>
            </tr>
           
            <tr>
              
                <td  colspan=”2″ align=”center”>
                  
                  <font color=”white”>(Format:<b><i>Firstname</i></b>[:SPACE:]<b><i>Middlename</i></b>[:SPACE:]<b><i>Lastname</i></b>)</font>
                  
                  
                </td>
               
            </tr>
           
           
            <tr>
              
                <td>
                  
                 <font color=”white”> Birthdate:</font>
                  
                  
                </td>
                <td>
                    <input type=”text” name=”birthdate” size=”30″ tabindex=”2″
                           value=”<?php echo $_POST[‘birthdate’];?>”>
                </td>
            </tr>
           
            <tr>
                <td  colspan=”2″ align=”center”>
                    <font color=”white”>(Format:<b><i>dd/mm/yyyy</i></b> or <b><i>dd.mm.yyyy</i></b> or <b><i>dd-mm-yyyy</i></b>)</font>
                </td>
            </tr>
            <tr>
              
                <td>
                  
                <font color=”white”> Qualifications:</font>
                  
                  
                </td>
                <td>
                    <input type=”text” name=”qualifications” size=”70″ tabindex=”3″
                           value=”<?php echo $_POST[‘qualifications’];?>”>
                </td>
            </tr>
       
            <tr>
                <td  colspan=”2″ align=”center”>
                   <font color=”white”> (Use commas for multiple qualification)</font>
                </td>
            </tr>
            </tr>
        <tr>
            <td><font color=”white”>Speciality</font></td>

            <td>
            <textarea cols=”50″ rows=”6″ name=”speciality” tabindex=”4″
                      value=”<?php echo $_POST[‘speciality’];?>”></textarea>
            </td>
        </tr>
        <tr>
            <td colspan=”2″ align=”center”>
               <font color=”white”> Enter data fitting in 5 lines</font>
            </td>
        </tr>
            <table align=”center”>
            <tr>
                <td >
                    <input type=”submit” value=”submit” name=”submit” onclick=”submit()”>
                        <input type=”reset” value=”clear” name=”reset” onclick=”reset()”>
                </td>
            </tr>
            </table>
            </form>
                </table>
                </fieldset>
            </td>
        </tr>
       </table>
      
           
        </body>
</html>
       
    result3.php

    

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

if(ereg(“([[:space:]]){2}”,$_POST[‘authorname’]))

{
    $msg=”Please do not use double space in author’s name”;
    include(“form3.php”);
    exit;
   
}

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

if(!ereg((“^([0-9]){2}[/.-]([0-9]){2}[/.-]([0-9]){4}$”),$_POST[‘birthdate’]))

{
    $msg=”Birthdate format is not correct”;
    include(“form3.php”);
    exit;
   
}

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

?>

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

        </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: