PHP Class MC4WP_Form

Exibir arquivo Open project: dannyvankooten/mailchimp-for-wordpress Class Usage Examples

Public Properties

Property Type Description
$ID The form ID, matches the underlying post its ID
$config array
$content The form HTML content
$errors Array of error codes
$instances Array of instantiated form objects.
$is_submitted Was this form submitted?
$messages Array of message codes that will show when this form renders
$name The form name
$post The internal post object that represents this form.
$raw_data Array of the raw form data that was submitted.
$settings Array of settings

Protected Properties

Property Type Description
$post_meta Raw array or post_meta values.

Public Methods

Method Description
__construct ( integer $id )
__get ( string $name ) : mixed
__toString ( ) : string Output this form
add_error ( string $error_code ) Add an error to this form
add_message ( $key )
get_action ( ) : string Get the form action
get_data ( ) : array
get_element ( string $element_id = 'mc4wp-form', array $config = [] ) : MC4WP_Form_element
get_email_type ( ) : string Get "email_type" setting for new MailChimp subscribers added by this form.
get_field_types ( ) : array Get an array of field types which are present in this form.
get_html ( string $element_id = 'mc4wp-form', array $config = [] ) : string Get HTML string for this form.
get_instance ( integer | WP_Post $form_id ) : MC4WP_Form Get a shared form instance.
get_lists ( ) : array Get MailChimp lists this form subscribes to
get_message ( string $key ) : MC4WP_Form_Message Get message object
get_message_html ( string $key ) : string Get HTML string for a message, including wrapper element.
get_redirect_url ( ) : string Get "redirect to url after success" setting for this form
get_required_fields ( ) : array Get array of name attributes for the required fields in this form.
get_response_html ( ) : string Gets the form response string
get_stylesheet ( ) : string Gets the filename of the stylesheet to load for this form.
handle_request ( MC4WP_Request $request ) : void Handle an incoming request. Should be called before calling validate() method.
has_errors ( ) : boolean Does this form have errors?
has_field_type ( $type ) : boolean Does this form has a field of the given type?
set_config ( array $config ) : array Update configuration for this form
validate ( ) : boolean Is this form valid?

Protected Methods

Method Description
load_messages ( ) : array
load_settings ( ) : array
parse_request_data ( MC4WP_Request $request ) : array Parse a request for data which should be binded to $data property.

Method Details

__construct() public method

public __construct ( integer $id )
$id integer The post ID

__get() public method

public __get ( string $name ) : mixed
$name string
return mixed

__toString() public method

Output this form
public __toString ( ) : string
return string

add_error() public method

Add an error to this form
public add_error ( string $error_code )
$error_code string

add_message() public method

public add_message ( $key )
$key

get_action() public method

Valid return values are "subscribe" and "unsubscribe"
public get_action ( ) : string
return string

get_data() public method

public get_data ( ) : array
return array

get_element() public method

public get_element ( string $element_id = 'mc4wp-form', array $config = [] ) : MC4WP_Form_element
$element_id string
$config array
return MC4WP_Form_element

get_email_type() public method

Get "email_type" setting for new MailChimp subscribers added by this form.
public get_email_type ( ) : string
return string

get_field_types() public method

Get an array of field types which are present in this form.
public get_field_types ( ) : array
return array

get_html() public method

If you want to output a form, use mc4wp_show_form instead as it.
public get_html ( string $element_id = 'mc4wp-form', array $config = [] ) : string
$element_id string
$config array
return string

get_instance() public static method

Get a shared form instance.
public static get_instance ( integer | WP_Post $form_id ) : MC4WP_Form
$form_id integer | WP_Post
return MC4WP_Form

get_lists() public method

Get MailChimp lists this form subscribes to
public get_lists ( ) : array
return array

get_message() public method

Get message object
public get_message ( string $key ) : MC4WP_Form_Message
$key string
return MC4WP_Form_Message

get_message_html() public method

Get HTML string for a message, including wrapper element.
Deprecation: 3.1
public get_message_html ( string $key ) : string
$key string
return string

get_redirect_url() public method

Get "redirect to url after success" setting for this form
public get_redirect_url ( ) : string
return string

get_required_fields() public method

Get array of name attributes for the required fields in this form.
public get_required_fields ( ) : array
return array

get_response_html() public method

This does not take the submitted form element into account.
See also: MC4WP_Form_Element::get_response_html()
public get_response_html ( ) : string
return string

get_stylesheet() public method

Gets the filename of the stylesheet to load for this form.
public get_stylesheet ( ) : string
return string

handle_request() public method

Handle an incoming request. Should be called before calling validate() method.
See also: MC4WP_Form::validate
public handle_request ( MC4WP_Request $request ) : void
$request MC4WP_Request
return void

has_errors() public method

Should always evaluate to false when form has not been submitted.
public has_errors ( ) : boolean
return boolean

has_field_type() public method

Does this form has a field of the given type?
public has_field_type ( $type ) : boolean
$type
return boolean

load_messages() protected method

protected load_messages ( ) : array
return array

load_settings() protected method

protected load_settings ( ) : array
return array

parse_request_data() protected method

This does the following on all post data. - Removes fields starting with an underscore. - Remove fields which are set to be ignored. - Uppercase all field names
protected parse_request_data ( MC4WP_Request $request ) : array
$request MC4WP_Request
return array

set_config() public method

Update configuration for this form
public set_config ( array $config ) : array
$config array
return array

validate() public method

Will always return true if the form is not yet submitted. Otherwise, it will run validation and store any errors. This method should be called before get_errors()
public validate ( ) : boolean
return boolean

Property Details

$ID public_oe property

The form ID, matches the underlying post its ID
public $ID

$config public_oe property

public array $config
return array

$content public_oe property

The form HTML content
public $content

$errors public_oe property

Array of error codes
public $errors

$instances public_oe static_oe property

Array of instantiated form objects.
public static $instances

$is_submitted public_oe property

Was this form submitted?
public $is_submitted

$messages public_oe property

Array of message codes that will show when this form renders
public $messages

$name public_oe property

The form name
public $name

$post public_oe property

The internal post object that represents this form.
public $post

$post_meta protected_oe property

Raw array or post_meta values.
protected $post_meta

$raw_data public_oe property

Array of the raw form data that was submitted.
public $raw_data

$settings public_oe property

Array of settings
public $settings