Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function form($fields, $types, $action, $title, $submit, $align = "left", $border = "0", $method = "POST"){
- if(isset($fields) && isset($action) && isset($method) && isset($title) && isset($submit) && $submit != "" && $title != "" && isset($align) && isset($border) && $action != "" && $fields != null){
- echo "<table>";
- //Convert to 4 arrays
- $typestitle = array();
- $typestype = array();
- $fieldstitle = array();
- $fieldsfield = array();
- foreach($types as &$type){
- $typestitle[] = array_search($type, $types);
- $typestype[] = $type;
- }
- foreach($fields as &$field){
- $fieldstitle[] = array_search($field, $fields);
- $fieldsfield[] = $field;
- }
- //Arrays are now
- // $fieldstitle
- // $fieldsfield
- // $typestitle
- // $typestype
- //Build the form
- echo "<table align='".$align."' border='".$border."'>";
- echo "<form action='".$action."' method='".$method."'>";
- echo "<tr><td style='border:0;'><b><h3>".$title."</h3></b></td></tr>";
- foreach($fieldstitle as &$num){
- echo "<tr>";
- echo "<td style='border:0;'>";
- echo $fieldsfield[array_search($num, $fieldstitle)];
- echo "</td>";
- echo "<td style='border:0;'>";
- echo "<input type='".$typestype[array_search($num, $fieldstitle)]."' name='".$num."'>";
- echo "</td>";
- echo "</tr>";
- }
- //Add the submit button
- echo "<tr>";
- echo "<td style='border:0;'></td><td align='right' style='border:0;'>";
- echo "<input type='submit' value='".$submit."'>";
- echo "</td>";
- echo "</tr>";
- echo "</form>";
- echo "</table>";
- }else{
- return(0);
- }
- }
- //Example Use
- $types = array("username" => "textbox", "email" => "email", "vemail" => "email", "password1" => "password", "password2" => "password");
- $fields = array("username" => "Username:", "email" => "Email:", "vemail" => "Verify:", "password" => "Password:", "password2" => "Re-Type:");
- form($fields, $types,"test.php","Register A New User","Register!","left","2","POST");
- ?>
Add Comment
Please, Sign In to add comment