Skip to content
Snippets Groups Projects
Select Git revision
  • 573bfb703ee914e0fad2178799fcb0f0834392a2
  • master default protected
  • devel
  • feature/add-escaping-to-templates
  • feature/add-priority-sorting
  • 3.3.0
  • 3.2.1
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.4.12
  • 2.4.11
  • 2.4.10
  • 2.4.9
  • 2.4.8
  • 2.4.7
  • 2.4.6
  • 2.4.5
  • 2.4.4
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3.2
  • 2.3.1
  • 2.3
25 results

Form.php

Blame
  • Form.php 1.63 KiB
    <?php
    
    namespace WPDesk\Forms;
    
    use WPDesk\View\Renderer\Renderer;
    
    /**
     * Abstraction layer for forms.
     *
     * @package WPDesk\Forms
     */
    interface Form {
    	/**
    	 * For some reason you may want to disable a form. Returns false when disabled.
    	 */
    	public function is_active(): bool;
    
    	/**
    	 * Whether form handle_request method was successfully executed.
    	 */
    	public function is_submitted(): bool;
    
    	/**
    	 * After handle_request or set_data the data in form can be invalid according to field validators.
    	 * Returns false when one of them says the data is invalid.
    	 */
    	public function is_valid(): bool;
    
    	/**
    	 * Add array to update data.
    	 *
    	 * @param array $request New data to update.
    	 *
    	 * @return void
    	 */
    	public function handle_request( array $request = [] );
    
    	/**
    	 * Data could be saved in some place. Use this method to transmit them to form.
    	 *
    	 * @param array $data Data for form.
    	 *
    	 * @return void
    	 */
    	public function set_data( array $data );
    
    	/**
    	 * Use to render the form to string.
    	 *
    	 * @param Renderer $renderer Renderer to render form fields and form-templates.
    	 */
    	public function render_form( Renderer $renderer ): string;
    
    	/**
    	 * Get data from form. Use after handle_request or set_data.
    	 *
    	 * @return array<int,string>
    	 */
    	public function get_data(): array;
    
    	/**
    	 * Get data from form. Use after handle_request or set_data.
    	 * The difference get_data is that here you will not get any objects and complex data types besides arrays.
    	 *
    	 * @return array
    	 */
    	public function get_normalized_data(): array;
    
    	/**
    	 * Form if you ever need to have more than one form at once.
    	 */
    	public function get_form_id(): int;
    }