Banner image

This is the older method of form generation usign a PHP class

Forms can be rendered by using the tools class but we now prefer to use HTML directly written into a view file in conjunction with the new form javascript biscuits-forms.js.
Our biscuits-forms.js functions pick up data- attributes to define the validation to do for each form input or textarea.

These are still commonly used throughout the biscuits engine functions

  • The tools class is ready to go in biscuits controllers
  • Then set up the $formSpec associative array array()

    Some values you might set include the following. Just set the values that you require.

    • fields This is a sub level associative array with keys for each field (Database column) and values as an array of field properties for that form field <input> to appear on the form.
      Eg: name => array('mandatory' => true, ), ...
    • action If not set the form will update any DB itself, but you get set your own action here.
    • access_allowed You own code should set this to true according to your own rules and criteria. If anyone enters the URL to lead to a tools form this will be set to disallow access by default.
    • success_url Redirect here on success, otherwise stay in the form
    • set_values An associative array of DB columns and the value that you have set for this column. These will go into your DB update/insert along with the form values entered. Eg: timestamp = current time or update user id.
    • Others there are many other values that you can pass into the $fldSpec array to generate the form. Look in the tools class function database_form
    • selQuery to generate a <SELECTION> tag of select options We will use the first array element [0] for the value and the second array element [1] to display this value in full desciptive form
  • Finally include the line

    $this->tools->database_form($formSpec);

Examples

Modify an existing row


       $this->findClass('tools_1b');
        $this->tools = new tools();
        
        $formSpec   =   array(
            'form_id'           =>  'edit_transaction',
            'id'                =>  $transactionId,
            'table'             =>  'et_sales',
            'access_allowed'    =>  $access_allowed,
            
            'fields'    =>   array(
                'account'      =>  'Account Name',
                'transactionId'     =>  'Transaction ID',
                
                'description'       =>  'Description',
                'amount'            =>  'Amount',
                'display_date_paid' =>  'Date Paid',
                ),
            
            'fldReadOnly'      =>  array(
                'account'       =>  true,
                'transactionId' =>  true,
                'display_date_paid' => true,
                ),
            'set_values'    =>  array(
                'userid'        =>  $row['userid'],                
                'account'       =>  $account['username'],
                'transactionId' =>  $transactionId,
                
                'display_date_paid'  =>  date("D dS M Y ",$row['date_paid']),
                ),
            
            );
        
        $this->tools->database_form($formSpec);
        $this->pageFoot();
 

        

The DB pdate

Biscuits forms post the form data on submission back to the same page. The tools.php class detects that post data has been submitted and takes care of the DB update.
This is detected by the inclusion of a hidden form input in all forms.

            if (isset($_POST['tools-form'])) {
                        if ($_POST['tools-form'] == $this->form_id) {
                // Remember! the form may not validate and so can be posted again after amending the data. 
                $this->processSubmission();
                ...
                ...

               $this->doFormSQL();
            

Leon link to chat
Website by Ibiscuits