[], 'first_name' => [ 'type' => 'text', 'label' => 'First Name', 'attribs' => [ 'required' => true ] ], 'last_name' => [ 'type' => 'text', 'label' => 'Last Name', 'attribs' => [ 'required' => true ] ], 'street' => [ 'type' => 'text', 'label' => 'Street', 'attribs' => [ 'required' => true ] ], 'zip' => [ 'type' => 'text', 'label' => 'Zip', 'attribs' => [ 'required' => true ] ], 'city' => [ 'type' => 'text', 'label' => 'City', 'attribs' => [ 'required' => true ] ], 'email' => [ 'type' => 'email', 'label' => 'Email', 'attribs' => [ 'required' => true ] ], 'phone' => [ 'type' => 'phone', 'label' => 'Phone', 'attribs' => [ 'required' => true ] ], ]; public static function get_fields() { if ( empty( static::$fields['prefix'] ) ) { $prefix = [ 'type' => 'radio', 'multi_options' => ( 'en' == FQP\FQP::get_curr_lang() ) ? [ 'Mr' => 'Mr', 'Ms' => 'Ms', 'Mrs' => 'Mrs' ] : [ 'Herr' => 'Herr', 'Frau' => 'Frau' ], 'attribs' => [ 'required' => true ], ]; static::$fields['prefix'] = $prefix; if ( FQP\FQP::is_short_forms() ) { static::$fields['email_subscription'] = [ 'type' => 'checkbox', 'label' => 'EN Ja, ich möchte über Tipps und News rund um die Firmengründung und das Unternehmertum informiert werden. (Keine Angst, wir werden Sie nicht mit Unmengen an E-Mails belästigen und Sie können die Informationen jederzeit wieder abbestellen.)', 'attribs' => [] ]; $lang = FQP\FQP::get_curr_lang(); $url = get_site_url(); if ( 'de' == $lang ) { $url = "{$url}/{$lang}/agb/"; } else { $url = "{$url}/{$lang}/agb/"; // англійська має мити власний урл } static::$fields['agree'] = [ 'type' => 'checkbox', 'label' => sprintf( fqp__( 'EN Ja, ich akzeptiere die AGB\'s' ), $url ), 'escape_label' => false, 'attribs' => [ 'required' => true, ] ]; } } return static::$fields; } public static function sanitize_data( &$data ) { if ( !is_array( $data ) ) { $data = []; } $errors = []; $fields = [ 'prefix' => fqp__('Prefix'), 'first_name' => fqp__('First Name'), 'last_name' => fqp__('Last Name'), 'street' => fqp__('Street'), 'zip' => fqp__('Zip'), 'city' => fqp__('City'), 'email' => fqp__('Email'), 'phone' => fqp__('Phone'), ]; $field_messages = [ 'required' => fqp__('%s is required'), 'wrong_format' => fqp__('%s is in wrong format'), ]; $email_regex = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD'; foreach ( $fields as $name => $title ) { if ( !array_key_exists( $name, $data ) || empty( $data[$name] ) ) { $errors[] = esc_html( sprintf( $field_messages['required'], $title ) ); } else if ( in_array( $name, [ 'email' ] ) ) { if ( !preg_match( $email_regex, $data[$name] ) ) { $errors[] = esc_html( sprintf( $field_messages['wrong_format'], $title ) ); } } } if ( $data['phone'] ) { $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); try { $number = $phoneUtil->parse( $data['phone'], 'LI' ); if ( !$phoneUtil->isValidNumber( $number ) ) { $errors[] = esc_html( sprintf( $field_messages['wrong_format'], $fields['phone'] ) ); } } catch ( \libphonenumber\NumberParseException $e ) { $errors[] = esc_html( sprintf( $field_messages['wrong_format'], $fields['phone'] ) ); } } return ( empty( $errors ) ) ? true : $errors; } }