예제 #1
0
function validate_captcha($validation_result)
{
    // 2 - Get the form object from the validation result
    $form = $validation_result["form"];
    // 3 - Get the current page being validated
    $current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;
    //print_r($validation_result); exit;
    // 4 - Loop through the form fields
    foreach ($form['fields'] as &$field) {
        // 5 - If the field does not have our designated CSS class, skip it
        if (strpos($field['cssClass'], 'validate-anti-spam') === false) {
            continue;
        }
        // 6 - Get the field's page number
        $field_page = $field['pageNumber'];
        // 7 - Check if the field is hidden by GF conditional logic
        $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
        // 8 - If the field is not on the current page OR if the field is hidden, skip it
        if ($field_page != $current_page || $is_hidden) {
            continue;
        }
        // 9 - Get the submitted value from the $_POST
        $field_value = rgpost("input_{$field['id']}");
        // 10 - Make a call to your validation function to validate the value
        $is_valid = is_valid_captcha($field_value);
        // 11 - If the field is valid we don't need to do anything, skip it
        if ($is_valid) {
            continue;
        }
        // 12 - The field failed validation, so first we'll need to fail the validation for the entire form
        $validation_result['is_valid'] = false;
        // 13 - Next we'll mark the specific field that failed and add a custom validation message
        $field['failed_validation'] = true;
        $field['validation_message'] = 'Vul het antwoord op de vraag in, het antwoord is het getal nul (0).';
    }
    // 14 - Assign our modified $form object back to the validation result
    $validation_result['form'] = $form;
    // 15 - Return the validation result
    return $validation_result;
}
예제 #2
0
파일: page.php 프로젝트: nwtug/academia
 function process_contactus()
 {
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     if ($this->input->post('sendmessage')) {
         $required_fields = array('emailaddress*EMAILFORMAT', 'helptopic', 'subject', 'description', 'captcha');
         $_POST['attachmenturl'] = !empty($_FILES['attachmenturl']['name']) ? $this->sysfile->local_file_upload($_FILES['attachmenturl'], 'Upload_' . strtotime('now'), 'attachments', 'filename') : '';
         $_POST = clean_form_data($_POST);
         $validation_results = validate_form('', $_POST, $required_fields);
         #Only proceed if the validation for required fields passes
         if ($validation_results['bool'] && is_valid_captcha($this, $_POST['captcha'])) {
             #Send the contact message to the administrator and
             $send_result = $this->sysemail->email_form_data(array('fromemail' => NOREPLY_EMAIL), get_confirmation_messages($this, $_POST, 'website_feedback'));
             if ($send_result) {
                 $data['msg'] = "Your message has been sent. Thank you for your feedback.";
                 $data['successful'] = 'Y';
             } else {
                 $data['msg'] = "ERROR: Your message could not be sent. Please contact us using our phone line.";
             }
         }
         if (!$validation_results['bool']) {
             $data['msg'] = "WARNING: The highlighted fields are required.";
         }
         $data['requiredfields'] = array_merge($validation_results['requiredfields'], array('captcha'));
         $data['formdata'] = $_POST;
     }
     $data['pagedata'] = $this->Query_reader->get_row_as_array('get_page_by_section', array('section' => 'Support', 'subsection' => 'Contact Us'));
     if (count($data['pagedata']) > 0) {
         $data['pagedata']['details'] = str_replace(">", ">", str_replace("<", "<", $data['pagedata']['details']));
         $data['pagedata']['parsedtext'] = $this->wiki_manager->parse_text_to_HTML(htmlspecialchars_decode($data['pagedata']['details'], ENT_QUOTES));
         $result = $this->db->query($this->Query_reader->get_query_by_code('get_subsections_by_section', array('section' => $data['pagedata']['section'])));
         $data['subsections'] = $result->result_array();
     }
     $data = add_msg_if_any($this, $data);
     $this->load->view('page/contactus_view', $data);
 }