function salesforce_form_shortcode($atts) { extract(shortcode_atts(array('form' => '1', 'sidebar' => false), $atts)); $emailerror = ''; $captchaerror = ''; $content = ''; $form = (int) $form; $sidebar = (bool) $sidebar; $options = get_option("salesforce2"); if (!is_array($options)) { $options = salesforce_default_settings(); } //don't submit unless we're in the right shortcode if (isset($_POST['form_id'])) { $form_id = intval($_POST['form_id']); if ($form_id != $form) { $content = salesforce_form($options, $sidebar, null, $form); return '<div class="salesforce_w2l_lead">' . $content . '</div>'; } } //this is the right form, continue if (isset($_POST['w2lsubmit'])) { $error = false; $post = array(); $has_error = false; // field validation foreach ($options['forms'][$form]['inputs'] as $id => $input) { if (isset($_POST[$id])) { $val = $_POST[$id]; if (is_array($val)) { $val = array_map('trim', $val); } else { $val = trim($val); } } else { $val = ''; } $error = array('valid' => false, 'message' => $options['errormsg']); if ($input['show'] && $input['required'] && strlen(salesforce_maybe_implode(';', $val)) == 0) { $error['valid'] = false; } else { $error['valid'] = true; } if (($id == 'email' && $input['required'] || $input['type'] == 'email' && $val) && !is_email($val)) { $error['valid'] = false; if (isset($options['emailerrormsg']) && $options['emailerrormsg']) { $error['message'] = $options['emailerrormsg']; } else { // backwards compatibility $error['message'] = __('The email address you entered is not valid.', 'salesforce'); } } $error = apply_filters('sfwp2l_validate_field', $error, $id, $val, $options['forms'][$form]['inputs'][$id]); //$error = apply_filters('sfwp2l_'.$id, $error, $id, $options['forms'][$form]['inputs'][$id] ); $errors[$id] = $error; if ($input['required'] && strlen(salesforce_maybe_implode(';', $val)) == 0) { //$options['forms'][$form]['inputs'][$id]['error'] = true; // $error = true; //} else if ($id == 'email' && $input['required'] && !is_email($_POST[$id]) ) { // $error = true; // $emailerror = true; } else { if (isset($_POST[$id])) { if (is_array($_POST[$id])) { $post[$id] = array_map('salesforce_clean_field', $_POST[$id]); } else { $post[$id] = salesforce_clean_field($_POST[$id]); } } } } //pass daddy analytics fields if (isset($options['da_token']) && isset($options['da_url'])) { $da_token = $options['da_token']; $da_url = $options['da_url']; if (isset($_POST[$da_token])) { $post[$da_token] = $_POST[$da_token]; } if (isset($_POST[$da_url])) { $post[$da_url] = $_POST[$da_url]; } } //check captcha if enabled if (salesforce_get_option('captchaform', $form_id, $options) == 'enabled' || salesforce_get_option('captchaform', $form_id, $options) == '' && $options['captcha']) { if ($_POST['captcha_hash'] != sha1($_POST['captcha_text'] . NONCE_SALT)) { $has_error = true; $errors['captcha']['valid'] = false; if (isset($options['captchaerrormsg']) && $options['captchaerrormsg']) { $errors['captcha']['message'] = $options['captchaerrormsg']; } else { //backwards compatibility $errors['captcha']['message'] = __('The text you entered did not match the image.', 'salesforce'); } } } foreach ($errors as $error) { if (!$error['valid']) { $has_error = true; } } /* $org_id = salesforce_get_option('org_id', $form_id, $options); echo '$org_id='.$org_id; */ if (!$has_error) { $result = submit_salesforce_form($post, $options, $form); //echo 'RESULT='.$result; //if($result) echo 'true'; //if(!$result) echo 'false'; if (!$result) { $content = '<strong class="error_message">' . esc_html(stripslashes($options['sferrormsg'])) . '</strong>'; } else { // Return / Success URL $returl = apply_filters('salesforce_w2l_returl', $options['forms'][$form]['returl'], $form); $returl = apply_filters('salesforce_w2l_returl_' . absint($form_id), $returl, $form); $returl = esc_url_raw($returl); if ($returl) { ?> <script type="text/javascript"> <!-- window.location= <?php echo "'" . $returl . "'"; ?> ; //--> </script> <?php } // Success message $success_message = apply_filters('salesforce_w2l_success_message', salesforce_get_option('successmsg', $form, $options), $form); $success_message = apply_filters('salesforce_w2l_success_message_' . absint($form_id), $success_message, $form); if ($success_message) { $content = '<strong class="success_message">' . esc_html(stripslashes($success_message)) . '</strong>'; } } $sf_form_id = get_salesforce_form_id($form_id, $sidebar); $content = '<div id="' . $sf_form_id . '">' . $content . '</div>'; } else { $errormsg = esc_html(stripslashes($options['errormsg'])); $content .= salesforce_form($options, $sidebar, $errors, $form); } } else { $content = salesforce_form($options, $sidebar, null, $form); } return '<div class="salesforce_w2l_lead">' . $content . '</div>'; }
function salesforce_form_shortcode($is_sidebar = false) { $options = get_option("salesforce"); if (!is_array($options)) { salesforce_default_settings(); } if (isset($_POST['w2lsubmit'])) { $error = false; $post = array(); foreach ($options['inputs'] as $id => $input) { if ($input['required'] && empty($_POST[$id])) { $options['inputs'][$id]['error'] = true; $error = true; } else { if ($id == 'email' && $input['required'] && !is_email($_POST[$id])) { $error = true; $emailerror = true; } else { $post[$id] = trim(strip_tags(stripslashes($_POST[$id]))); } } } if (!$error) { $result = submit_salesforce_form($post, $options); if (!$result) { $content = '<strong>' . esc_html(stripslashes($options['sferrormsg'])) . '</strong>'; } else { $content = '<strong>' . esc_html(stripslashes($options['successmsg'])) . '</strong>'; } } else { $errormsg = esc_html(stripslashes($options['errormsg'])); if ($emailerror) { $errormsg .= '<br/>The email address you entered is not a valid email address.'; } $content = salesforce_form($options, $is_sidebar, $errormsg); } } else { $content = salesforce_form($options, $is_sidebar); } return $content; }