/** * Initialize a form. This is usually done in the context of a view/controller in your application. When a form is * constructed, the fields populate their input based on the form * * @param array $options */ public function __construct(array $options = []) { // Update the meta values for this form's meta object with a user-supplied array // of key=>value pairs mapping to properties on this form's meta object if (array_key_exists('meta', $options) && is_array($options['meta'])) { $this->meta->updateValues($options['meta']); } // if CSRF is enabled on the Meta field, then generate a CSRF field // automagically and attach it to the form if ($this->meta && $this->meta->csrf) { $this->csrf = $this->meta->buildCSRF($this); list($csrf_name, $csrf_field) = $this->csrf->setupForm($this); if (!property_exists($csrf_field->csrf_impl, 'form_meta') || !$csrf_field->csrf_impl->form_meta) { $csrf_field->csrf_impl->form_meta = $this->meta; } $this->__set($csrf_name, $csrf_field); } if (array_key_exists('prefix', $options)) { $this->prefix = $options['prefix']; } // Normalize the end of the prefix to contain only one dash if ($this->prefix && !str_contains("-_;:/.", substr($this->prefix, -1))) { $this->prefix .= "-"; } }