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.

Individual Custom Fields in Registration Form

Home Forums Community Forum Individual Custom Fields in Registration Form

This topic contains 5 replies, has 2 voices. Last updated by  Sarah Hills 4 years, 3 months ago.

Topic Author Topic
Posted: Wednesday Sep 19th, 2012 at 7:47 am #25780

Hi,

I’m currently modifying the Pro Registration Form (via a copy of paypal-registration-form.php in my theme directory).

However, I need to do what it seems a fair few others are trying to do – display custom fields individually (e.g. I have a ‘phone’ field which it makes sense to display alongside ’email’. I also want to change the ‘Additional Info’ header text.

I’ve seen Raam’s solution here: http://www.s2member.com/forums/topic/custom-sign-up-page/, but as Joel points out, this means any updates to the custom fields in the Admin area will be ignored. It’s also a bit of a manual process!

How can we get around this problem? I guess I’m looking for the equivalent of %%custom_fields%% for individual fields – e.g. %%custom_field_phone%%

Thanks,
Sarah

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Wednesday Sep 19th, 2012 at 5:40 pm #25858
David Welch
Username: dwbiz05

*NOTE: You should only use this function if you have a legal copy of s2member pro. Much of this code was copied from the s2member files.

I created a quick little class that you can put in an mu-plugin to add some of this functionality. It’s not perfect but it seems to work for me when I use it this way. Again, I have not done extensive testing on this function.

Step 1 -> Create a directory / file in this location:

http://yourdomain.com/wp-content/mu-plugins/s2-hacks.php

Step 2 -> Add this code to that file (s2-hacks.php):

<?php
//Dave Welch - Custom Fields In Custom Template Class

class DW_custom_template {
	public static function get_s2_custom_field($id,$level=0){
		
		$_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST));
		/*
		Obtain a possible response and/or validation error.
		*/
		$response = c_ws_plugin__s2member_pro_paypal_responses::paypal_registration_response($attr);
		/*
		Empty post vars on successful response.
		*/
		$_p = ($response["response"] && !$response["error"]) ? array(): $_p;
		
		$custom_field_array = json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true);
	
		foreach($custom_field_array as $k => $v){
			if($v['id'] == $id){
				$id_key = $k;
				break;
			}
		}
		
		//print_r($custom_field_array);
		
		$fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level($level, "registration");
		$custom_fields = '';
		$field = $custom_field_array[$id_key];
		if(!empty($custom_field_array)){
			if(isset($field['id']) && $field['id'] == $id){
				if(in_array($field["id"], $fields_applicable))//Field is applicable to Level 0? 
				{
					$field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
					$field_id_class = preg_replace("/_/", "-", $field_var);
					
					if(!empty($field["section"]) && $field["section"] === "yes") // Starts a new section? 
						$custom_fields .= '<div id="s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-divider-section" class="s2member-pro-paypal-form-div s2member-pro-paypal-registration-form-div s2member-pro-paypal-form-custom-reg-field-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').' s2member-pro-paypal-form-custom-reg-field-'.$field_id_class.'-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').' s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-divider-section'.((!empty($field["sectitle"])) ? '-title' : '').'">'.((!empty($field["sectitle"])) ? $field["sectitle"] : '').'</div>';
					
					$custom_fields .= '<div id="s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-div" class="s2member-pro-paypal-form-div s2member-pro-paypal-registration-form-div s2member-pro-paypal-form-custom-reg-field-'.$field_id_class.'-div s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-div">'."\n";
				
					$custom_fields .= '<label for="s2member-pro-paypal-registration-custom-reg-field-'.esc_attr($field_id_class).'" id="s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-label" class="s2member-pro-paypal-form-custom-reg-field-'.$field_id_class.'-label s2member-pro-paypal-registration-form-custom-reg-field-'.$field_id_class.'-label">'."\n";
					$custom_fields .= '<span'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? ' style="display:none;"' : '').'>'.$field["label"].(($field["required"] === "yes") ? ' *' : '').'</span></label>'.((preg_match("/^(checkbox|pre_checkbox)$/", $field["type"])) ? '' : '<br />')."\n";
					$custom_fields .= c_ws_plugin__s2member_custom_reg_fields::custom_field_gen(__FUNCTION__, $field, "s2member_pro_paypal_registration[custom_fields][", "s2member-pro-paypal-registration-custom-reg-field-", "s2member-pro-paypal-custom-reg-field-".$field_id_class." s2member-pro-paypal-registration-custom-reg-field-".$field_id_class, "", ($tabindex = $tabindex + 1), "", $_p, $_p["s2member_pro_paypal_registration"]["custom_fields"][$field_var], "registration");
					
					$custom_fields .= '</div>'."\n";
					
					return $custom_fields;
				}
				else {
					return 'Not Applicable Field';
				}
			}
			else {
				return 'Invalid ID';
			}
		}
		else {
			return 'No Custom Fields';
		}
	}
}
?>

Step 3 -> Place this line of code in your template where you want your custom field to be. You will use the Unique ID for that field to call it.

<?php echo DW_custom_template::get_s2_custom_field('your-field-id-here'); ?>

If you have any questions, let me know. If it doesn’t work let me know too.. again this has been tested very little. lol

Hope it helps,

Dave

Posted: Thursday Sep 20th, 2012 at 10:22 am #25953

Hi David,

Many thanks for this and for taking the time to reply.

I am planning to try this out early next week – will report back then as to how it goes!

Thanks,
Sarah

Posted: Tuesday Sep 25th, 2012 at 11:51 am #26440

Just tried this out & it works great thank you! Thanks for the v. clear instructions.

Any idea whether this would work for a custom profile update form too?? Just off to give it a go now…

Posted: Wednesday Sep 26th, 2012 at 11:24 am #26575
David Welch
Username: dwbiz05

I haven’t looked at that template, but if it uses the same css layout and html structure for the form elements, I don’t see why it wouldn’t.

Dave

Posted: Friday Sep 28th, 2012 at 5:17 am #26815

Further discussion in this post

Viewing 5 replies - 1 through 5 (of 5 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.