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.

hidden fields and validation in pro forms

Home Forums Community Forum hidden fields and validation in pro forms

This topic contains 8 replies, has 2 voices. Last updated by  Cristián Lávaque 4 years, 9 months ago.

Topic Author Topic
Posted: Wednesday Mar 14th, 2012 at 1:21 pm #8120
Username: solmagnus

I have s2member paypal pro forms and I want to send a string of email domains to different access levels. The email will be validated against the domain list and if it’s there it’s valid.

I have put some javascript validation straight in the form template. That’s all fine and works. But it’s only a half-assed job to rely on javascript. I need to validate it in the back-end also in case the visitor doesn’t have javascript enabled.

This is what I thought I may be able to do:

– create a separate registration form for each level
– send a hidden string containing the domain list for the level to the form via a parameter added to the shortcode for the registration form
– use the mu-plugins/s2-hacks.php to add the extra validation to the email address

Is this possible? If so what hooks would I use?

P.S. If it’s not possible to add the parameter to the shortcode. I could possibly hard-code the string in the template and use a different template via the ‘template=’ parameter in the shortcode for each registration form which would work for the javascript at least. This would not be ideal though.

  • This topic was modified 4 years, 10 months ago by  solmagnus.

List Of Topic Replies

Viewing 8 replies - 1 through 8 (of 8 total)
Author Replies
Author Replies
Posted: Wednesday Mar 14th, 2012 at 1:55 pm #8127
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=”” must start with your domain. Additional values can be piped in ( ex: custom=”|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.

Posted: Wednesday Mar 14th, 2012 at 5:18 pm #8165
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 9:16 pm #8192
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/ 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: Thursday Mar 15th, 2012 at 4:25 am #8205


Sorry I just got to your posts. You’re doing great for your first day!

Took note of the feature request, thanks for the suggestion. Will see what we can do about it.

Yeah, I see what you don’t like editing the core files. The way I’d go about it is probably use the mu-plugins file and just check the [hilite mono]$_POST[/hilite] array to see if the registration form was submitted. If so, do the email check against the domain names list and if it doesn’t pass, return the person to the registration page.

I hoep that helps. :)

Posted: Thursday Mar 15th, 2012 at 6:05 am #8213
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: Friday Mar 16th, 2012 at 3:05 pm #8394

What do you need the description for in the mu-plugins hack? For the domains list you mentioned putting there? You can have the domains in an array right in the hack, right?

Posted: Saturday Mar 17th, 2012 at 11:53 am #8451
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.

function extra_validation ($vars = array()) {
	$js = "
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;
	echo $js;
	if(isset($GLOBALS['response_extra'])) {
		echo $GLOBALS['response_extra'];

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 style="clear:both;"></div>

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

Posted: Tuesday Mar 20th, 2012 at 5:43 am #8590

Cool! Glad you solved it, and thanks for sharing it. :)

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

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

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.