Skip to content

Commit

Permalink
🔥 REMOVE: table and utis class
Browse files Browse the repository at this point in the history
  • Loading branch information
mahafuz committed May 2, 2022
1 parent 4e9fedc commit 636eaab
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 637 deletions.
4 changes: 2 additions & 2 deletions includes/Classes/class-form-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function submitQuotation() {

$fullname = sanitize_user( $_POST['pqfw_customer_name'] );
$email = sanitize_email( $_POST['pqfw_customer_email'] );
$phone = pqfw()->utils->sanitize_phone_number( $_POST['pqfw_customer_phone'] );
$phone = pqfw()->helpers->sanitizePhoneNumber( $_POST['pqfw_customer_phone'] );
$subject = sanitize_text_field( $_POST['pqfw_customer_subject'] );
$comments = sanitize_text_field( $_POST['pqfw_customer_comments'] );
$mapedDataToSave = [
Expand All @@ -52,7 +52,7 @@ public function submitQuotation() {
'comments' => $comments
];

$validate = pqfw()->utils->validate( $mapedDataToSave );
$validate = pqfw()->helpers->validate( $mapedDataToSave );

if ( $validate->has_errors() ) {
wp_send_json_error( $validate->errors );
Expand Down
53 changes: 53 additions & 0 deletions includes/Classes/class-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,57 @@ class Helpers {
public function generatePrivacyPolicy( $text ) {
return function_exists( 'wc_replace_policy_page_link_placeholders' ) ? wc_replace_policy_page_link_placeholders( $text ) : $text;
}

/**
* Sanitize phone number.
* Allows only numbers and "+" (plus sign).
*
* @param string $phone Phone number.
*
* @return string
* @since 1.0.0
*/
public function sanitizePhoneNumber( $phone ) {
return preg_replace( '/[^\d+]/', '', $phone );
}

/**
* Validate user data.
*
* @since 2.0.0
* @param array $fields The input fields value to validate.
* return mixed
*/
public function validate( $fields ) {
$errors = new \WP_Error();

$requiredFields = [
'fullname',
'email'
];

foreach ( $requiredFields as $required ) {
if ( empty( $fields[ $required ] ) ) {
$errors->add( 'field', sprintf( '%s %s', $required, __( 'is required.', 'pqfw' ) ) );
}
}

if ( $errors->has_errors() ) {
return $errors;
}

if ( strlen( $fields['fullname'] ) < 4 ) {
$errors->add( 'username_length', __( 'Username too short. At least 4 characters is required', 'pqfw' ) );
}

if ( ! validate_username( $fields['fullname'] ) ) {
$errors->add( 'username_invalid', __( 'Sorry, the username you entered is not valid', 'pqfw' ) );
}

if ( ! is_email( $fields['email'] ) ) {
$errors->add( 'email_invalid', __( 'Email is not valid', 'pqfw' ) );
}

return $errors;
}
}
310 changes: 0 additions & 310 deletions includes/Classes/class-table.php

This file was deleted.

Loading

0 comments on commit 636eaab

Please sign in to comment.