LLMS_Form_Validator::validate_required_fields( array $posted_data, array[] $fields )
Ensure that all of the forms required fields are present in the submitted data.
Parameters Parameters
- $posted_data
-
(array) (Required) User data (likely from $_POST).
- $fields
-
(array[]) (Required) Array of LifterLMS form fields.
Return Return
(WP_Error|true)
Source Source
File: includes/forms/class-llms-form-validator.php
public function validate_required_fields( $posted_data, $fields ) { // Ensure all required fields have been submitted. $err = new WP_Error(); $err_data = array(); foreach ( $this->get_required_fields( $fields ) as $field ) { if ( empty( $posted_data[ $field['name'] ] ) ) { // Translators: %s = field label or name. $err->add( 'llms-form-missing-required', sprintf( __( '%s is a required field.', 'lifterlms' ), isset( $field['label'] ) ? $field['label'] : $field['name'] ) ); $err_data[ $field['name'] ] = $field; } } if ( $err->errors ) { $err->add_data( $err_data, 'llms-form-missing-required' ); return $err; } return true; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |