Guest User

Untitled

a guest
Jul 3rd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2. function form($fields, $types, $action, $title, $submit, $align = "left", $border = "0", $method = "POST"){
  3.     if(isset($fields) && isset($action) && isset($method) && isset($title) && isset($submit) && $submit != "" && $title != "" && isset($align) && isset($border) && $action != "" && $fields != null){
  4.     echo "<table>";
  5.    
  6.     //Convert to 4 arrays
  7.     $typestitle = array();
  8.     $typestype = array();
  9.     $fieldstitle = array();
  10.     $fieldsfield = array();
  11.     foreach($types as &$type){
  12.         $typestitle[] = array_search($type, $types);
  13.         $typestype[] = $type;
  14.     }
  15.     foreach($fields as &$field){
  16.         $fieldstitle[] = array_search($field, $fields);
  17.         $fieldsfield[] = $field;
  18.     }
  19.    
  20.     //Arrays are now
  21.     // $fieldstitle
  22.     // $fieldsfield
  23.     // $typestitle
  24.     // $typestype
  25.    
  26.     //Build the form
  27.    
  28.     echo "<table align='".$align."' border='".$border."'>";
  29.     echo "<form action='".$action."' method='".$method."'>";
  30.     echo "<tr><td style='border:0;'><b><h3>".$title."</h3></b></td></tr>";
  31.     foreach($fieldstitle as &$num){
  32.         echo "<tr>";
  33.             echo "<td style='border:0;'>";
  34.                 echo $fieldsfield[array_search($num, $fieldstitle)];
  35.             echo "</td>";
  36.             echo "<td style='border:0;'>";
  37.                 echo "<input type='".$typestype[array_search($num, $fieldstitle)]."' name='".$num."'>";
  38.             echo "</td>";
  39.            
  40.         echo "</tr>";
  41.      
  42.     }
  43.     //Add the submit button
  44.     echo "<tr>";
  45.     echo "<td style='border:0;'></td><td align='right' style='border:0;'>";
  46.     echo "<input type='submit' value='".$submit."'>";
  47.     echo "</td>";
  48.     echo "</tr>";
  49.     echo "</form>";
  50.     echo "</table>";
  51.    }else{
  52.    return(0);
  53.    }
  54.    
  55.    
  56. }
  57.  
  58.  
  59.  
  60.  
  61. //Example Use
  62.  
  63. $types = array("username" => "textbox", "email" => "email", "vemail" => "email", "password1" => "password", "password2" => "password");
  64. $fields = array("username" => "Username:", "email" => "Email:", "vemail" => "Verify:", "password" => "Password:", "password2" => "Re-Type:");
  65.  
  66. form($fields, $types,"test.php","Register A New User","Register!","left","2","POST");
  67.  
  68. ?>
Add Comment
Please, Sign In to add comment