Ejemplo n.º 1
0
 protected function validate_posted_data($data, &$errors = array())
 {
     if (empty($data['awpcp_sender_name'])) {
         $errors['awpcp_sender_name'] = __('Please enter your name.', 'AWPCP');
     }
     if (empty($data['awpcp_sender_email'])) {
         $errors['awpcp_sender_email'] = __('Please enter your email.', 'AWPCP');
     } else {
         if (!isValidEmailAddress($data['awpcp_sender_email'])) {
             $errors['ad_contact_email'] = __("The email address you entered was not a valid email address. Please check for errors and try again.", "AWPCP");
         }
     }
     if (empty($data['awpcp_contact_message'])) {
         $errors['awpcp_contact_message'] = __('There was no text in your message. Please enter a message.', 'AWPCP');
     }
     if (get_awpcp_option('useakismet')) {
         $spam_filter = awpcp_listing_reply_spam_filter();
         if ($spam_filter->is_spam($data)) {
             $errors['awpcp_contact_message'] = __('Your message was flagged as spam. Please contact the administrator of this site.', 'AWPCP');
         }
     }
     if (get_awpcp_option('captcha-enabled')) {
         $captcha = awpcp_create_captcha(get_awpcp_option('captcha-provider'));
         $error = '';
         if (!$captcha->validate($error)) {
             $errors['captcha'] = $error;
         }
     }
     return empty($errors);
 }
    ?>
</label>
            <?php 
    echo awpcp_form_error('terms-of-service', $errors);
    ?>
        </p>
        <?php 
}
?>

        <?php 
if ($ui['captcha']) {
    ?>
        <div class='awpcp-form-spacer'>
            <?php 
    $captcha = awpcp_create_captcha(get_awpcp_option('captcha-provider'));
    ?>
            <?php 
    echo $captcha->render();
    ?>
            <?php 
    echo awpcp_form_error('captcha', $errors);
    ?>
        </div>
        <?php 
}
?>

        <?php 
if ($preview) {
    ?>
Ejemplo n.º 3
0
 /**
  * @param  array  $data     Normalized array with Ad details. All fields are expected
  *                          to be present: isset($data['param']) === true
  * @param  array  $errors
  * @return boolean          true if data validates, false otherwise
  */
 protected function validate_details($data = array(), $edit = false, $payment_term = null, &$errors = array())
 {
     global $hasextrafieldsmodule;
     // $edit = !empty($data['ad_id']);
     $is_moderator = awpcp_current_user_is_moderator();
     $user_id = awpcp_array_data('user_id', 0, $data);
     $user_payment_term = awpcp_array_data('user_payment_term', '', $data);
     if (get_awpcp_option('freepay') == 1 && $user_id > 0 && empty($user_payment_term) && !$edit) {
         $errors['user_payment_term'] = __('You did not select a Payment Term. Please select a Payment Term for this Ad.', 'AWPCP');
     }
     $start_date = strtotime($data['start_date']);
     if ($edit && $is_moderator && empty($data['start_date'])) {
         $errors['start_date'] = __('Please enter a start date for the Ad.', 'AWPCP');
     }
     $end_date = strtotime($data['end_date']);
     if ($edit && $is_moderator && empty($data['end_date'])) {
         $errors['end_date'] = __('Please enter an end date for the Ad.', 'AWPCP');
     }
     if ($edit && $is_moderator && $start_date > $end_date) {
         $errors['start_date'] = __('The start date must occur before the end date.', 'AWPCP');
     }
     // Check for ad title
     if (empty($data['ad_title'])) {
         $errors['ad_title'] = __("You did not enter a title for your Ad", "AWPCP");
     }
     // Check for ad details
     if (empty($data['ad_details'])) {
         $errors['ad_details'] = __("You did not enter any text for your Ad. Please enter some text for your Ad.", "AWPCP");
     }
     // Check for ad category
     if (empty($data['ad_category']) && $edit) {
         $errors['ad_category'] = __("You did not select a category for your Ad. Please select a category for your Ad.", "AWPCP");
     }
     // If website field is checked and required make sure website value was entered
     if (get_awpcp_option('displaywebsitefield') == 1 && get_awpcp_option('displaywebsitefieldreqop') == 1) {
         if (empty($data['websiteurl'])) {
             $errors['websiteurl'] = __("You did not enter your website address. Your website address is required.", "AWPCP");
         }
     }
     //If they have submitted a website address make sure it is correctly formatted
     if (!empty($data['websiteurl']) && !isValidURL($data['websiteurl'])) {
         $errors['websiteurl'] = __("Your website address is not properly formatted. Please make sure you have included the http:// part of your website address", "AWPCP");
     }
     // Check for ad poster's name
     if (empty($data['ad_contact_name'])) {
         $errors['ad_contact_name'] = __("You did not enter your name. Your name is required.", "AWPCP");
     }
     // Check for ad poster's email address
     if (empty($data['ad_contact_email'])) {
         $errors['ad_contact_email'] = __("You did not enter your email. Your email is required.", "AWPCP");
     }
     // Check if email address entered is in a valid email address format
     if (!awpcp_is_valid_email_address($data['ad_contact_email'])) {
         $errors['ad_contact_email'] = __("The email address you entered was not a valid email address. Please check for errors and try again.", "AWPCP");
     } else {
         if (!awpcp_is_email_address_allowed($data['ad_contact_email'])) {
             $message = __('The email address you entered is not allowed in this website. Please use an email address from one of the following domains: %s.', 'AWPCP');
             $domains_whitelist = explode("\n", get_awpcp_option('ad-poster-email-address-whitelist'));
             $domains_list = '<strong>' . implode('</strong>, <strong>', $domains_whitelist) . '</strong>';
             $errors['ad_contact_email'] = sprintf($message, $domains_list);
         }
     }
     // If phone field is checked and required make sure phone value was entered
     if (get_awpcp_option('displayphonefield') == 1 && get_awpcp_option('displayphonefieldreqop') == 1) {
         if (empty($data['ad_contact_phone'])) {
             $errors['ad_contact_phone'] = __("You did not enter your phone number. Your phone number is required.", "AWPCP");
         }
     }
     $region_fields = array();
     foreach ($data['regions'] as $region) {
         foreach ($region as $type => $value) {
             if (!empty($value)) {
                 $region_fields[$type] = true;
             }
         }
     }
     // If country field is checked and required make sure country value was entered
     if ($payment_term->regions > 0 && get_awpcp_option('displaycountryfield') == 1 && get_awpcp_option('displaycountryfieldreqop') == 1) {
         if (!awpcp_array_data('country', false, $region_fields)) {
             $errors['regions'] = __("You did not enter your country. Your country is required.", "AWPCP");
         }
     }
     // If state field is checked and required make sure state value was entered
     if ($payment_term->regions > 0 && get_awpcp_option('displaystatefield') == 1 && get_awpcp_option('displaystatefieldreqop') == 1) {
         if (!awpcp_array_data('state', false, $region_fields)) {
             $errors['regions'] = __("You did not enter your state. Your state is required.", "AWPCP");
         }
     }
     // If city field is checked and required make sure city value was entered
     if ($payment_term->regions > 0 && get_awpcp_option('displaycityfield') == 1 && get_awpcp_option('displaycityfieldreqop') == 1) {
         if (!awpcp_array_data('city', false, $region_fields)) {
             $errors['regions'] = __("You did not enter your city. Your city is required.", "AWPCP");
         }
     }
     // If county/village field is checked and required make sure county/village value was entered
     if ($payment_term->regions > 0 && get_awpcp_option('displaycountyvillagefield') == 1 && get_awpcp_option('displaycountyvillagefieldreqop') == 1) {
         if (!awpcp_array_data('county', false, $region_fields)) {
             $errors['regions'] = __("You did not enter your county/village. Your county/village is required.", "AWPCP");
         }
     }
     // If price field is checked and required make sure a price has been entered
     if (get_awpcp_option('displaypricefield') == 1 && get_awpcp_option('displaypricefieldreqop') == 1) {
         if (strlen($data['ad_item_price']) === 0 || $data['ad_item_price'] === false) {
             $errors['ad_item_price'] = __("You did not enter the price of your item. The item price is required.", "AWPCP");
         }
     }
     // Make sure the item price is a numerical value
     if (get_awpcp_option('displaypricefield') == 1 && strlen($data['ad_item_price']) > 0) {
         if (!is_numeric($data['ad_item_price'])) {
             $errors['ad_item_price'] = __("You have entered an invalid item price. Make sure your price contains numbers only. Please do not include currency symbols.", "AWPCP");
         }
     }
     if ($hasextrafieldsmodule == 1) {
         // backward compatibility with old extra fields
         if (function_exists('validate_extra_fields_form')) {
             $_errors = validate_extra_fields_form($data['ad_category']);
         } else {
             if (function_exists('validate_x_form')) {
                 $_errors = validate_x_form();
             }
         }
         if (isset($_errors) && !empty($_errors)) {
             $errors = array_merge($errors, (array) $_errors);
         }
     }
     // Terms of service required and accepted?
     if (!$edit && !$is_moderator && get_awpcp_option('requiredtos') && empty($data['terms-of-service'])) {
         $errors['terms-of-service'] = __("You did not accept the terms of service", "AWPCP");
     }
     if (!$edit && !is_admin() && get_awpcp_option('captcha-enabled')) {
         $captcha = awpcp_create_captcha(get_awpcp_option('captcha-provider'));
         $error = '';
         if (!$captcha->validate($error)) {
             $errors['captcha'] = $error;
         }
     }
     if (get_awpcp_option('useakismet')) {
         $spam_filter = awpcp_listing_spam_filter();
         if ($spam_filter->is_spam($data)) {
             $errors[] = __("Your Ad was flagged as spam. Please contact the administrator of this site.", "AWPCP");
         }
     }
     return count(array_filter($errors)) === 0;
 }