Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 504799

salesforce_w2l_before_submit

$
0
0

Replies: 1

Hi there,

I have a use that goes something like this:

1. W2L Form is displayed on home page with email and password text boxes
2. I use salesforce_w2l_before_submit to post the form data to a URL on another domain
3. This URL either creates a user account or returns a response of username exists already

I get the code to work fine, by using curl to submit the code. I can create a user and I can receive a message back stating the username exists. What I can’t figure out is how to stop the form from submitting to SFDC and also display the form again with the username and password populated.

My code is below (added directly into salesforce.php), please let me know if I am going down the right path or if I should use some alternative methods:

//add before submit action to call function to create user on site
add_action(‘salesforce_w2l_before_submit’, ‘salesforce_w2l_before_submit_send_to_rc’, 10, 3 );

function salesforce_w2l_before_submit_send_to_rc( $post, $form_id, $form_type ){

foreach($post as $key => $value) {

$urlArray[] = $key.”=”.$value;

}

$postString = implode(“&”, $urlArray);

$response = do_post_request(“https://www.rc.com/user/getrc”,$post,null, $postString);

if (strpos($response,”Username already exists”) >0)
{
echo “Username already exists, please input a different username”;
}

}

function do_post_request($url, $data, $optional_headers = null, $postString)

{
$ch = curl_init($url);

curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_FOLLOWLOCATION => true
));

$output = curl_exec($ch);
return $output;

}

add_filter(‘sfwp2l_validate_field’,’password_requirement’, 10, 4);

function password_requirement( $error, $name, $val, $field ){

if( $name == ‘Password’ ){

if( strlen($_POST[‘Password’]) < 6 ){
$error[‘valid’] = false;
$error[‘message’] = ‘Please enter a password that contains at least 6 characters.’;
}

}

return $error;
}


Viewing all articles
Browse latest Browse all 504799

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>