For beginner form generate code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    For beginner form generate code

    connect.php
    PHP Code:
    <?php

        
    class connect
        
    {
            
    //$x = array("text-2","password-2","file-1","submit-1","lable-2");

            
    function createform($method,$action,$enctype,$x)

            {

    echo 
    $str "<form method='".$method."' action='".$action."' enctype='".$enctype."'>";
            
            
    foreach(
    $x as $k=>$v)
    {
        
    $vdata explode("-",$v);
        
        if(
    $vdata[0]=="text")
        {
            
    $i=1;
            while(
    $i<=$vdata[1])
            {
                
    $this->createtext("","","20",$vdata[0],1,"");$i++;
                echo 
    "<br />";
                echo 
    "<br />";
            }
        }

        else if(
    $vdata[0]=="password")
        {    
            
            
    $i=1;
            while(
    $i<=$vdata[1])
            {
                
    $this->createtext("","","",$vdata[0],6,"");$i++;
                echo 
    "<br />";
                echo 
    "<br />";
            }
        }

        else if(
    $vdata[0]=="submit")
        {
            
    $i=1;
            while(
    $i<=$vdata[1])
            {
                
    $this->createtext("","Enter","",$vdata[0],1,"");$i++;
                echo 
    "<br />";
                echo 
    "<br />";
            }
        }
        else if(
    $vdata[0]=="file")
        {
            
    $i=1;
            while(
    $i<=$vdata[1])
            {
                
    $this->createtext("","","",$vdata[0],4,"");$i++;
                echo 
    "<br />";
                echo 
    "<br />";
            }
        }

        else
        {}




    }



    echo 
    $str="</form>";

    //echo $str;

            
    }


            function 
    createtext($name,$value,$maxlength,$type,$fortype,$option)
            {
                if(
    $fortype==1)
                {
                    
                    
    $str "<input type='".$type."' maxlength='".$maxlength."' value='".$value."' name='".$name."' id='".$name."'  class='".$name."' />";
                    
                }
                else if(
    $fortype==2)
                {
                    
                    
    $str "<textarea maxlength='".$maxlength."' name='".$name."' id='".$name."'  class='".$name."'> ".$value."</textarea>";
                    
                }
                else if(
    $fortype==3)
                {
                    
                    
    $str "<select name=".$name.">";
                    if(
    count($option)>0)
                    {
                        foreach(
    $option as $k=>$v)
                        {
                            
    $vdata explode("-",$v);
                            
    $str.="<option value=".$vdata[0].">".$vdata[1]."</option>";
                        }
                        
                    }
                    
    $str.= "</select>";
                }

                else if(
    $fortype==4)
                {
                    
    $str "<input type='".$type."' value='".$value."' name='".$name."' id='".$name."'  class='".$name."' />";
                }
                else
                {
                    
    $str "<input type='".$type."'  value='".$value."' name='".$name."' id='".$name."'  class='".$name."' />";
                
                }
                
                echo 
    $str;    
            }
            
            
                    
            
            
            }
            
    $obj=new connect;


    ?>
    test.php
    PHP Code:
    <?php
        
    // include_once("connect.php");
        
        
        
        
    $x = array("text-2","password-2","file-1","submit-1","lable-2");
    $obj->createform("post","action.php",5,$x);
    ?>

    php masters make this code better
    Last edited by andrew3008; 05.08.11, 06:44.

    #2
    You want it cleaner or load faster then it will not do ?
    Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
    Visit: WapMasterz Coming Back Soon!
    _______
    SCRIPTS FOR SALE BY SUBZERO
    Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
    FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
    _______
    Info & Tips
    php.net
    w3schools.com

    Comment


      #3
      Usually its best to use plain text/html, form generators are tricky business. If ure using a framework that has been component unit tested fine, else dont be lazy.

      Comment


        #4
        For a beginner this would probably be to confusing lol

        Comment


          #5
          i start learning php 1 week bfore jus i tried this so better thought share and get feedback and make it better

          Comment


            #6
            i like adding to the page other then adding to MySql.

            Think of noobs i know have 159 database to control one site and they asking me why there site loads is so high lmao !
            Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
            Visit: WapMasterz Coming Back Soon!
            _______
            SCRIPTS FOR SALE BY SUBZERO
            Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
            FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
            _______
            Info & Tips
            php.net
            w3schools.com

            Comment


              #7
              I guess, class makes difficult for beginners.
              Did I help you?
              You can help me too
              Your donations will help me finance my studies.

              Comment

              Working...
              X