| |
| <?php
|
| add_filter( 'ninja_forms_submit_data', 'leadcapsule_final_post' );
|
|
|
| function leadcapsule_final_post( $form_data ) {
|
| $form_id = $form_data['id'];
|
| $payload = array();
|
| $is_leadcapsule_form = false;
|
|
|
|
|
|
|
|
|
| $field_map = array(
|
| 'txt_campaign_id' => 'CampaignId',
|
| 'txt_first_name' => 'FirstName',
|
| 'txt_last_name' => 'LastName',
|
| 'txt_address1' => 'Address1',
|
| 'txt_city' => 'City',
|
| 'txt_zip' => 'Zip',
|
| 'txt_state' => 'State',
|
| 'txt_phone' => 'Phone',
|
| 'txt_work_phone' => 'WorkPhone',
|
| 'txt_email' => 'Email',
|
| 'txt_ownhome' => 'OwnHome',
|
| 'txt_residence_date' => 'ResidenceDate',
|
| 'txt_military' => 'Military',
|
| 'txt_date_of_birth' => 'DateOfBirth',
|
| 'txt_ssn' => 'Social',
|
| 'txt_drivers_license_state' => 'DriversLicenseState',
|
| 'txt_drivers_license_number' => 'DriversLicenseNumber',
|
| 'txt_incometype1' => 'IncomeType',
|
| 'txt_employer' => 'Employer',
|
| 'txt_hiredate' => 'HireDate',
|
| 'txt_pay_frequency' => 'PayFrequency',
|
| 'txt_directdeposit' => 'DirectDeposit',
|
| 'txt_gross_monthly_income' => 'GrossMonthlyIncome',
|
| 'txt_next_pay_date' => 'NextPayDate',
|
| 'txt_second_pay_date' => 'SecondPayDate',
|
| 'txt_bank_account_type' => 'BankAccountType',
|
| 'txt_bank_account_name' => 'BankAccountName',
|
| 'txt_account_open_date' => 'BankAccountOpenDate',
|
| 'txt_bank_account_number' => 'BankAccountNumber',
|
| 'txt_bank_routing_number' => 'BankRoutingNumber',
|
| 'txt-loan_amount' => 'LoanAmount',
|
| 'txt_source' => 'Source',
|
| 'user-analytics-ip' => 'IPAddress',
|
| 'user-analytics-browser' => 'UserAgent',
|
|
|
|
|
| 'txt_subid1' => 'SubId',
|
| 'txt_optin' => 'OptIn',
|
| 'txt_istest' => 'IsTest'
|
| );
|
|
|
|
|
| foreach ( $form_data['fields'] as $field ) {
|
| $field_id = isset( $field['id'] ) ? $field['id'] : $field;
|
| $value = isset( $field['value'] ) ? $field['value'] : '';
|
|
|
| $field_model = Ninja_Forms()->form( $form_id )->get_field( $field_id );
|
|
|
| if ( $field_model ) {
|
| $nf_key = $field_model->get_setting( 'key' );
|
|
|
| if ( array_key_exists( $nf_key, $field_map ) ) {
|
| $lc_key = $field_map[ $nf_key ];
|
| $payload[ $lc_key ] = $value;
|
|
|
|
|
| if ( $lc_key === 'CampaignId' && !empty($value) ) {
|
| $is_leadcapsule_form = true;
|
| }
|
| }
|
| }
|
| }
|
|
|
| if ( !$is_leadcapsule_form ) {
|
| return $form_data;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| if ( empty($payload['SubId']) ) {
|
| $payload['SubId'] = 'CL';
|
| }
|
|
|
|
|
| if ( empty($payload['IsTest']) ) {
|
| $payload['IsTest'] = 'False';
|
| }
|
|
|
|
|
| if ( empty($payload['UserAgent']) ) {
|
| $payload['UserAgent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "Mozilla/5.0 (Windows NT 10.0; Win64; x64)";
|
| }
|
|
|
|
|
|
|
|
|
| $endpoint = "https://leads.clearnexus.com/Leads/LeadPost.aspx";
|
| $curl = curl_init();
|
|
|
| curl_setopt_array($curl, array(
|
| CURLOPT_URL => $endpoint,
|
| CURLOPT_RETURNTRANSFER => true,
|
| CURLOPT_SSL_VERIFYPEER => false,
|
| CURLOPT_MAXREDIRS => 10,
|
| CURLOPT_TIMEOUT => 30,
|
| CURLOPT_FOLLOWLOCATION => true,
|
| CURLOPT_POST => true,
|
| CURLOPT_POSTFIELDS => http_build_query($payload),
|
| ));
|
|
|
| $response = curl_exec($curl);
|
| $err = curl_error($curl);
|
| curl_close($curl);
|
|
|
|
|
|
|
|
|
| $redirect_url = "https://galtcredit.com/";
|
|
|
| if ( !$err && !empty($response) ) {
|
|
|
| $response_clean = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
|
| $xml = @simplexml_load_string($response_clean, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);
|
|
|
| if ( $xml !== false && isset($xml->Redirect) && !empty((string) $xml->Redirect) ) {
|
| $redirect_url = trim((string) $xml->Redirect);
|
| }
|
| }
|
|
|
|
|
| $form_data['extra']['lc_redirect_url'] = $redirect_url;
|
|
|
|
|
| $form_data['extra']['lc_raw_response'] = base64_encode($response);
|
|
|
| return $form_data;
|
| }
|
|
|
| |
| |
Comments