Zebra_Form::__construct PHP Method

__construct() public method

Initializes the form. $form = new Zebra_Form('myform');
public __construct ( string $name, string $method = 'POST', string $action = '', array $attributes = '' ) : void
$name string Name of the form @param string $method (Optional) Specifies which HTTP method will be used to submit the form data set. Possible (case-insensitive) values are POST an GET Default is POST @param string $action (Optional) An URI to where to submit the form data set. If left empty, the form will submit to itself. You should *always* submit the form to itself, or server-side validation will not take place and you will have a great security risk. Submit the form to itself, let it do the server-side validation, and then redirect accordingly! @param array $attributes (Optional) An array of attributes valid for a
tag (i.e. style) Note that the following attributes are automatically set when the control is created and should not be altered manually: action, method, enctype, name @return void
$method string
$action string
$attributes array
return void
    function __construct($name, $method = 'POST', $action = '', $attributes = '')
    {
        $this->controls = $this->variables = $this->errors = $this->master_labels = array();
        // default filesysyem permissions for uploaded files
        $this->file_upload_permissions = '0755';
        // default values for the form's properties
        $this->form_properties = array('action' => $action == '' ? $_SERVER['REQUEST_URI'] : $action, 'assets_server_path' => rtrim(dirname(__FILE__), '\\/') . DIRECTORY_SEPARATOR, 'assets_url' => rtrim(str_replace('\\', '/', 'http' . (isset($_SERVER['HTTPS']) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ? 's' : '') . '://' . rtrim($_SERVER['HTTP_HOST'], '\\/') . '/' . substr(rtrim(dirname(__FILE__), '\\/'), strlen($_SERVER['DOCUMENT_ROOT']))), '\\/') . '/', 'attributes' => $attributes, 'auto_fill' => false, 'captcha_storage' => 'cookie', 'csrf_cookie_config' => array('path' => '/', 'domain' => '', 'secure' => false, 'httponly' => true), 'csrf_cookie_name' => 'zebra_csrf_token_' . $name, 'csrf_storage_method' => 'auto', 'csrf_token' => '', 'csrf_token_lifetime' => 0, 'csrf_token_name' => 'zebra_csrf_token_' . $name, 'doctype' => 'html', 'has_upload' => false, 'honeypot' => 'zebra_honeypot_' . $name, 'identifier' => 'name_' . $name, 'language' => array(), 'method' => strtoupper($method), 'name' => $name, 'other_suffix' => '_other', 'secret_key' => '', 'show_all_error_messages' => false);
        // set default client-side validation properties
        $this->clientside_validation(true);
        // get the maximum allowed file size for uploads
        $upload_max_filesize = ini_get('upload_max_filesize');
        // see what it is given in (G, M, K)
        $unit = strtolower(substr($upload_max_filesize, -1));
        // get the numeric value
        $value = substr($upload_max_filesize, 0, -1);
        // convert to bytes
        // notice that there is no break
        switch (strtolower(substr($upload_max_filesize, -1))) {
            case 'g':
                $value *= 1024;
            case 'm':
                $value *= 1024;
            case 'k':
                $value *= 1024;
        }
        // set the form's respective property
        $this->form_properties['max_file_size'] = $value;
        // include the XSS filter class - the Zebra_Form_Control class extends this class
        require_once dirname(__FILE__) . '/includes/XSSClean.php';
        // include the Control.php file which contains the Zebra_Form_Control class which is
        // extended by all of the classes
        require_once dirname(__FILE__) . '/includes/Control.php';
        // load the default language file
        $this->language('english');
        // enable protection against CSRF attacks using the default values
        // note that this has no effect if this method was already called before
        $this->csrf();
    }