<?php

include_once "../lib/buildform.class.php";
/**
 * How to use the from class: implement it like this 
 */
try {
    $createform = new BuildForm("textform", filter_var($_SERVER["PHP_SELF"]), "post");
    echo $createform->formHtml("<p>Sign Up Form :)</p>");
    // $firstname= array("label"=>"*Firstname","type"=>"text","name"=>"firstname","value"=>"","required"=>true,"optionalattr"=>"class=\"formclass\" placeholder=\"Enter name here\"");
    // $lastname = array("label"=>"*Lastname","type"=>"text","name"=>"lastname","value"=>"","required"=>true,"optionalattr"=>"class=\"formclass\" placeholder=\"Enter name here\"");
    $email = array("label" => "*Email Address", "type" => "email", "name" => "email", "value" => "", "optionalattr" => "class=\"formclass\" placeholder=\"Enter your email here\"");
    //$password= array("label"=>"*Password","type"=>"password","name"=>"pass","value"=>"","required"=>true,"optionalattr"=>"class=\"formclass\"");
    $submit = array("type" => "submit", "name" => "submit", "value" => "Register Me", "optionalattr" => "class=\"formclass\"");
    $hidden = array("type" => "hidden", "name" => "submit", "value" => "Register Me", "optionalattr" => "class=\"formclass\"");
    $createform->createInputField(array("label" => "*Enter Firstname", "type" => "text", "name" => "firstname", "value" => "", "required" => true, "optionalattr" => "class=\"formclass\" placeholder=\"Enter name here\""));
    $createform->createInputField(array("label" => "*Enter Lastname", "type" => "text", "name" => "lastname", "value" => "", "required" => true, "optionalattr" => "class=\"formclass\" placeholder=\"Enter name here\""));
    $createform->createInputField($email);
    //$createform->createInputField($password);
    $createform->createTextField(array("label" => "*Type Your Message", "name" => "comments", "cols" => 40, "rows" => 10, "value" => "", "optionalattr" => "class=\"formclass\" placeholder=\"Type your message here\""));
    $gender = array("label" => "Select your Gender", "radiogroup" => array(array("radiolabel" => "male", "checked" => $createform->checkedRadioValue("gender", "male"), "name" => "gender", "value" => "male"), array("radiolabel" => "female", "checked" => $createform->checkedRadioValue("gender", "female"), "name" => "gender", "value" => "female")));
    $sex = array("label" => "Choose your sex", "name" => "sex", "options" => array("....", "male" => "Male", "female" => "Female"));
    $recipes = array("label" => "Choose your favourite foods", "checkboxes" => array(array("checklabel" => "Banku and Tilapia", "name" => "recipes[]", "value" => "Banku and Tilapia", "checked" => $createform->checkedBoxValue("recipes", 'Banku and Tilapia')), array("checklabel" => "Rice and Stew", "name" => "recipes[]", "value" => "Rice and Stew", "checked" => $createform->checkedBoxValue("recipes", 'Rice and Stew')), array("checklabel" => "Fried Rice and Chicken", "name" => "recipes[]", "value" => "Fried Rice and Chicken", "checked" => $createform->checkedBoxValue("recipes", "Fried Rice and Chicken")), array("checklabel" => "Gari Foto and Chicken", "name" => "recipes[]", "value" => "Gari Foto and Chicken", "checked" => $createform->checkedBoxValue("recipes", "Gari Foto and Chicken"))));
    $createform->createCheckBox($recipes);
    $createform->createSelectField($sex);
    $createform->createRadioButton($gender);
    $createform->createInputField($hidden);
    //$createform->createInputField($hidden);
    $createform->createInputField($submit);
    //shows entire form on screen
    echo $createform->displayForm("Top Labling");
     $process->errorinfo = array_merge($process->errorinfo, $validate->check_PasswordLength(array("password" => 6)));
     $process->errorinfo = array_merge($process->errorinfo, $validate->check_requiredFields($required));
     $process->errorinfo = array_merge($process->errorinfo, $validate->check_PasswordFields("password", "cpassword"));
     /** Insert Data into Database **/
     $process->message("You have successfully registered {$process->post("firstname")}");
     if ($process->successflag) {
         echo "<p style='background:white;text-align:center'>Hooray your form is ready to be inserted into the database :)</p>";
         //echo "Form_submitted - ".$process->post("firstname");
         //$rec::$tablefields = array('fieldname1'=>'?','fieldname2'=>'?',...);
         //array("firstname","lastname","gender","username","email","password","cpassword",); //$sql = $query->getTable("users");
         // $result = $query->tablefields = array('fieldname1'=>'?','fieldname2'=>'?');
         // return parent::setData($key,$result);
     }
 }
 $form = new BuildForm("signupform", filter_var($_SERVER["PHP_SELF"]), "post");
 $form->form_heading = $form->formHtml("<h2>User Sign Up Form </h2>");
 //First name
 $form->createInputField(array("label" => "*Firstname", "type" => "text", "name" => "firstname", "value" => "", "optionalattr" => "class=\"forminput\" placeholder=\"Enter Firstname\""), $validate->displayErrorField($process->errorinfo, "firstname"));
 //Last name
 $form->createInputField(array("label" => "*Lastname", "type" => "text", "name" => "lastname", "value" => "", "optionalattr" => "class=\"forminput\" placeholder=\"Enter Lastname\""), $validate->displayErrorField($process->errorinfo, "lastname"));
 //Gender
 $form->createSelectField(array("label" => "*Gender", "name" => "gender", "value" => "", "options" => array("--Select Your Gender--" => "--Select Your Gender--", "M" => "Male", "F" => "Female")), $validate->displayErrorField($process->errorinfo, "gender"));
 //Username
 $form->createInputField(array("label" => "*Username", "type" => "text", "name" => "username", "value" => "", "required" => true, "optionalattr" => "class=\"forminput\" placeholder=\"Enter Username \""), $validate->displayErrorField($process->errorinfo, "username"));
 //Email
 $form->createInputField(array("label" => "*Email", "type" => "email", "name" => "email", "value" => "", "optionalattr" => "class=\"forminput\" placeholder=\"Enter Email: someone@example.com\""), $validate->displayErrorField($process->errorinfo, "email"));
 //Password
 $form->createInputField(array("label" => "*Password", "type" => "password", "name" => "password", "value" => "", "optionalattr" => "class=\"forminput\" placeholder=\"Enter Password\""), $validate->displayErrorField($process->errorinfo, "password"));
 //Confirm Password
 $form->createInputField(array("label" => "*Confirm Password", "type" => "password", "name" => "cpassword", "value" => "", "optionalattr" => "class=\"forminput\" placeholder=\"Enter Your Password Again \""), $validate->displayErrorField($process->errorinfo, "cpassword"));
 //Terms and Conditions