latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

About: solmagnus

Sorry, I've not written a description yet. I'll get to it soon!


Topics I'm Subscribed To

Viewing topic 1 (of 1 total)
Topic Count Last Reply
hidden fields and validation in pro forms

By:  solmagnus in: Community Forum

voices: 2
replies: 8

4 years, 9 months ago  Cristián Lávaque

Viewing topic 1 (of 1 total)

Topics I've Started

Viewing topic 1 (of 1 total)
Topic Count Last Reply
hidden fields and validation in pro forms

By:  solmagnus in: Community Forum

voices: 2
replies: 8

4 years, 9 months ago  Cristián Lávaque

Viewing topic 1 (of 1 total)

My Latest Replies (From Various Topics)

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Saturday Mar 17th, 2012 at 11:53 am #8451
solmagnus
Username: solmagnus

I’ve just managed to get back to this today as the client delayed the project… lucky me. So I was able to spend some time today to work it out properly. I don’t have the special template nor the code hack. I’ve hidden the description div in my css (and the username div because I’m auto-generating that).

I’ve done everything in mu-plugins/s2-hacks.php.

Firstly, at init, I grab the desc attribute (I figured out how to get this). I validate the email address against my list and if it’s invalid save an extra response. Then I set the email to an empty string to force an error. Then with the ws_plugin__s2member_pro_before_sc_paypal_form hook, I output the jquery validation and my extra response. That means I get two error responses but I can live with that because technically it is an invalid email address and my response adds some extra information.

add_action('ws_plugin__s2member_pro_before_sc_paypal_form','extra_validation',10);
function extra_validation ($vars = array()) {
	$js = "
<script>
jQuery(document).ready(function($) {
	$('#s2member-pro-paypal-registration-form').find(':submit').click(function(e) {
		mylist = '" . $vars['attr']['desc'] . "';
	if( ! inList( $('#s2member-pro-paypal-registration-email').val(), mylist) ) {
            e.preventDefault(); // Prevent the form from submitting
            alert('You cannot register with an email address in the domain you specified. Please try again with a valid email or contact us if you wish to register.');
            return false;
        }
	});
});
function inList(address, domains) {
	var whitelist = domains.split('|');
    var pieces = address.split('@');

    var i = whitelist.length;
    while (i--) {
        if (whitelist[i] === pieces[1]) return true;
    }
    return false;
}
</script>
";
	echo $js;
	if(isset($GLOBALS['response_extra'])) {
		echo $GLOBALS['response_extra'];
	}
}

add_action('init','extra_stuff',1);
function extra_stuff() {
	if (strpos($_SERVER["REQUEST_URI"], "/register-1") !== false) {
     	if(!isset($_POST["s2member_pro_paypal_registration"])) {
     		$_POST["s2member_pro_paypal_registration"]["username"] = generate_username();
     	} else {
     		$post_vars = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST["s2member_pro_paypal_registration"]));
			$post_vars["attr"] = unserialize (c_ws_plugin__s2member_utils_encryption::decrypt ($post_vars["attr"])); /* And run a Filter. */
			$post_vars["attr"] = apply_filters ("ws_plugin__s2member_pro_paypal_registration_post_attr", $post_vars["attr"], get_defined_vars ());
			if (!is_valid_email_domain($post_vars['email'], $post_vars['attr']['desc'])) {
				$_POST["s2member_pro_paypal_registration"]["email"] = '';
				GLOBAL $response_extra;
			$response_extra = '	
    <div id="s2member-pro-paypal-registration-form-response-section" class="s2member-pro-paypal-form-section s2member-pro-paypal-registration-form-section s2member-pro-paypal-form-response-section s2member-pro-paypal-registration-form-response-section">
		<div id="s2member-pro-paypal-registration-form-response-div" class="s2member-pro-paypal-form-div s2member-pro-paypal-registration-form-div s2member-pro-paypal-form-response-div s2member-pro-paypal-registration-form-response-div">
			<div id="s2member-pro-paypal-form-response" class="s2member-pro-paypal-form-response-error s2member-pro-paypal-registration-form-response-error">You cannot register with an email address in the domain you specified. Please try again with a valid email or contact us if you wish to register.</div>
		</div>
		<div style="clear:both;"></div>
	</div>
	';
			}
		}
	}
}

So anyway what I’ve done is probably not the “correct” way but it works!

Posted: Thursday Mar 15th, 2012 at 6:05 am #8213
solmagnus
Username: solmagnus

Thanks for your reply Cristián. I did try that with an action on init which worked in part. However I could only get the email address from the post vars and not the ‘desc’ attribute. I tried several things to get the value of the ‘desc’ attribute but couldn’t. I also wasn’t able to set the ‘response’ to write out in the template.

Posted: Wednesday Mar 14th, 2012 at 9:16 pm #8192
solmagnus
Username: solmagnus

Here I am replying to my own question again. Just in case anyone is interested I have this working. What I did was.

– utilized the ‘description’ field in the form shortcode for each form to hold the email domain whitelist for my levels
– customized the template to include the javascript validation on the email domain whitelist contain in the description parameter
– added a function is_valid_email_domain($email,$domains) into mu_plugins/s2-hacks.php (plus a detailed note for future upgrading of s2member-pro)
– and finally the really bad bit…
– added two lines of validation into includes/classes/gateways/paypal/paypal-responses.inc.php calling my custom function with the email and “desc” attribute and supplying the error response

I’ve probably gone about it all wrong but I installed s2member yesterday and there’s too much to figure out in a day!

Being able to specify an email domain whitelist for validating against would be a kind of handy feature to have built-in.

Posted: Wednesday Mar 14th, 2012 at 5:18 pm #8165
solmagnus
Username: solmagnus

No responses but to myself. I’ve been at this for an entire day and have a deadline looming. I’ve tried all manner of things. Seems like whenever this type of question has been asked with regard to extra email validation there is no actual answer to the question.

My only option to hack the core to add in my validation – unless someone can help me with an answer.

Posted: Wednesday Mar 14th, 2012 at 1:55 pm #8127
solmagnus
Username: solmagnus

I just realised that I could hijack the description field to pass my list into the template seeing as I’m using my own template to put in the extra javascript validation. I’ve no idea what this field is about.

custom=”www.mycompany.com” must start with your domain. Additional values can be piped in ( ex: custom=”www.mycompany.com|cv1|cv2|cv3|etc” ). Not valid when cancel=”1″.

Or I could possibly re-purpose one of the other fields associated with payments because my levels are all free.

Anyway that solves setting the whitelist for each level but I still don’t know which hooks I can use to do the extra email validation. I’ve read loads of posts and watched ‘s2Member (Custom Fields Dynamically?)’ video but the email field isn’t a custom field.

Viewing 5 replies - 1 through 5 (of 5 total)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.