PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Default form values

Common Questions/Problems/Tips. Posted by Administrators & Support Reps.

Default form values

Postby man-O-media » March 22nd, 2011, 8:09 pm

Hi all...

Is there some "reasonably" easy way to set a default value for a custom registration field?
For example, field #3 (a required field) is home_phone_number.
I also have a field named preferred_contact_number.
When the user is registering, I would like the data they enter into home_phone_number to appear in preferred_contact_number as a default value which they can change if desired.

And of course, in a more general sense, is there some "reasonably" easy way to set a default value for a custom registration field?
For example, field #2 is state which could for my needs default to our state.

Thanks, Daine
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Default form values

Postby Cristián Lávaque » March 23rd, 2011, 12:08 am

Hi Daine.

When you create the custom registration fields, the types check box, radio button and select menu, allow you to name a default value. I'm checking how it could be done with the text and text area types, though.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Default form values

Postby Jason Caldwell » March 23rd, 2011, 1:01 am

Thanks for the great question.
~ and thanks for bringing this to my attention Cristián.

There is currently no easy way to set a default value for a Custom Registration Field that is a "text" or "textarea" input field. You can only set default values for check boxes, radio buttons, and select/drop downs. In other words, the default value of a "text" or "textarea" input field is always blank; awaiting user input. That being said, s2Member incorporates the jQuery library into your Login/Registration system, and also into your theme. So it's relatively easy ( for a developer ) to use jQuery for this, by adding a Hook in the following way.

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php

Create this file too:
/wp-content/mu-plugins/s2-hacks.js

Inside the PHP file, insert this code:
Code: Select all
<?php
add_action 
("login_head", "s2_hacks_js", 15);
function s2_hacks_js ()
    {
        echo '<script type="text/javascript">';
        include_once dirname (__FILE__) . "/s2-hacks.js";
        echo '</script>';
    }
?>

Inside the JS file, insert this code:
Code: Select all
jQuery(document).ready (function($)
    {
        /* Sets default value of home_phone_number to: 999-999-9999. */
        if (!$.trim (('input#ws-plugin--s2member-custom-reg-field-home-phone-number').val ()))
            $('input#ws-plugin--s2member-custom-reg-field-home-phone-number').val ('999-999-9999');
        /**/
        /* Sets the default value of preferred_contact_number to the value being entered for home_phone_number. */
        $('input#ws-plugin--s2member-custom-reg-field-home-phone-number').keyup (function() /* Key press. */
            {
                $('input#ws-plugin--s2member-custom-reg-field-preferred-contact-number').val ((this).val ());
            });
    }); 

This code has now been tested/confirmed to work with WordPress v3.1 and s2Member v3.5.7.
* All of this code is untested, but should do the trick for you. This code assumes that you're using the default Login/Registration system for WordPress ( i.e. /wp-login.php?action=register ). If you have any trouble, please let us know. In either case, please report back if you can. Thank you.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Default form values

Postby man-O-media » March 27th, 2011, 2:26 am

Well Jason,

I guess this says it all:
So it's relatively easy ( for a developer ) to use jQuery for this, by adding a Hook in the following way.


I was going to say it all worked but things are not good.

I created the .js file and added the php function to my s2-hacks.php.
Initally, when I first refreshed the screen everything went blank but after a few refreshes and commenting out lines in the php file, the screen came back.
I then slowly removed the comments and everything worked.

I went into the .js file and added a few more lines to put default values in and all seemed OK,

Then I went back to the s2 settings page to make another adjustment in a custom field.
When I got to the settings page, the s2 logo was large and in the middle of the page. The column of settings was not there, or better said the column was a list of text on the left.
I tried logging out and the screen went blank
I tried another browser and could not log in, screen went blank.

I tried this a number of times with no luck so I decided to revert.

I replaced the s2member folder with a clean copy and replaced the bug fix .js file but I still can not login.
The moment I hit enter, the screen goes blank :cry:

I hope you have some ideas...

Daine
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Default form values

Postby Jason Caldwell » March 27th, 2011, 3:17 am

Hi Daine. Thanks for reporting back.
Video
I've just done a video on this code for you.
Please let us know if you continue to have trouble.

Please click this link to download/view the MP4 video file:
http://www.s2member.com/wp-content/uplo ... jQuery.mp4
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Default form values

Postby man-O-media » March 27th, 2011, 10:43 am

Jason...

I've just done a video on this code for you.
Please let us know if you continue to have trouble.

I don't even really know what to say...

I really had to :lol: when I saw your posting:
I knew my problem was related to something I had done but the fact that it was something soooo simple yet so elegantly explained blew my mind.

Blank space... Jeeeze, you learn something new every day :D

Of course, the time of day also adds an element of sublime pleasure...

It is sad to say but it seems to me that it isn't often these days that one is so pleasantly confronted by people who really care.
My motto is: "I will only do the very best I can do" and it is exremely clear that you have the same ethic.

All this is a round about way to say Thank You !!!

Daine
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Default form values

Postby Jason Caldwell » March 30th, 2011, 11:42 pm

You're very welcome Daine. It was my pleasure :-) Thank you for your assistance here in the forums too, we really appreciate you being so helpful!
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Default form values

Postby man-O-media » August 19th, 2011, 1:36 pm

Jason Caldwell wrote:* This code assumes that you're using the default Login/Registration system for WordPress ( i.e. /wp-login.php?action=register )

And it still works great :D
But (you knew this question would eventually come) now that I am starting to work with the Pro Forms, I would like to step over to the Pro free regisration form. even without the CAPCHA.

How would one enable this functionality with the Pro Forms?

Thanks, DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Default form values

Postby man-O-media » September 27th, 2011, 10:59 pm

man-O-media wrote:
Jason Caldwell wrote:* This code assumes that you're using the default Login/Registration system for WordPress ( i.e. /wp-login.php?action=register )

And it still works great :D

So I have to give this a bump...
I hope you will soon have a fix for the tab index issue and the Pro Registration form as one of my sites is getting regularly hit with robot registrations but if I am going to step over to the pro reg form, I would really like to have this functionality and while I have tried a multitude of different ways of identifying the fields in the Pro Reg form, nothing I have tried works.

This is the original code which I have modified for my various fields.
Code: Select all
jQuery(document).ready (function($)
    {
        /* Sets default value of home_phone_number to: 999-999-9999. */
        if (!$.trim ($ ('input#ws-plugin--s2member-custom-reg-field-home-phone-number').val ()))
            $('input#ws-plugin--s2member-custom-reg-field-home-phone-number').val ('999-999-9999');
        /**/
        /* Sets the default value of preferred_contact_number to the value being entered for home_phone_number. */
        $('input#ws-plugin--s2member-custom-reg-field-home-phone-number').keyup (function() /* Key press. */
            {
                $('input#ws-plugin--s2member-custom-reg-field-preferred-contact-number').val ($ (this).val ());
            });
    });

But as you say, the code is based on the wordpress default registration form. So how would one refer to these fields in the s2member Pro Reg form?

Thanks, DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Default form values

Postby Jason Caldwell » October 1st, 2011, 4:51 pm

Thanks for the follow-up on this thread.
Tab index issues inside Pro Form integrations were corrected in the release of s2Member Pro v110926+.

In Pro Forms, Custom Registration Fields are prefixed by:
Code: Select all
s2member-pro-paypal-[checkout|sp-checkout|registration]-custom-reg-field-
depending on the type of Pro Form being integrated.

For instance, here is a code sample that might be used for a Free Registration Form. If you're ever in doubt, it's best to view the source code of the Pro Form after it's been output on your Post/Page. Many site owners prefer to use Firebug for this.
Code: Select all
jQuery(document).ready (function($)
    {
        /* Sets default value of home_phone_number to: 999-999-9999. */
        if (!$.trim ($('input#s2member-pro-paypal-registration-custom-reg-field-home-phone-number').val ()))
            $('input#s2member-pro-paypal-registration-custom-reg-field-home-phone-number').val ('999-999-9999');
        /**/
        /* Sets the default value of preferred_contact_number to the value being entered for home_phone_number. */
        $('input#s2member-pro-paypal-registration-custom-reg-field-home-phone-number').keyup (function() /* Key press. */
            {
                $('input#s2member-pro-paypal-registration-custom-reg-field-preferred-contact-number').val ($(this).val ());
            });
    }); 
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Default form values

Postby man-O-media » October 1st, 2011, 9:46 pm

Jason Caldwell wrote:Thanks for the follow-up on this thread.
Tab index issues inside Pro Form integrations were corrected in the release of s2Member Pro v110926+.

Odd... I am still sitting at version: 110815
In fact I was kind of surprised.
I did not look at your site to see if a new version was out but I did notice that you were again posting messages so figured you were back from the dead which would mean a new release was finished :) Yet I have not received any automatic update notices on either site where I have s2 installed...

Anyway, many thanks for your reply... You said...
In Pro Forms, Custom Registration Fields are prefixed by:
Code: Select all
s2member-pro-paypal-[checkout|sp-checkout|registration]-custom-reg-field-
depending on the type of Pro Form being integrated.


Right, I get that and I am using Firebug so clearly I am doing something else wrong as I have tried that prefix.
This is my code...
Code: Select all
jQuery(document).ready (function($)
    {
        /* This line works in the default wp registration form. */
        if (!$.trim ($ ('input#ws-plugin--s2member-custom-reg-field-city').val ()))
            $('input#ws-plugin--s2member-custom-reg-field-city').val ('New York');
        /* This line does not work in the pro registration form. */
        if (!$.trim ($('input#s2member-pro-paypal-registration-custom-reg-field-city').val ()))
            $('input#s2member-pro-paypal-registration-custom-reg-field-city').val ('New York');
      
      /**/
        /* Sets the default value of preferred_contact_number to the value being entered for home_phone_number. */
        $('input#ws-plugin--s2member-custom-reg-field-primary-phone').keyup (function() /* Key press. */
            {
                $('input#ws-plugin--s2member-custom-reg-field-calling-post-phone').val ($ (this).val ());
            });
    });


This is the trigger code in s2-hacks.php.
Is this perhaps where my problem lies?
Code: Select all
<?php
add_action ("login_head", "s2_hacks_js", 15);
function s2_hacks_js()
    {
        echo '<script type="text/javascript">';
        include_once dirname (__FILE__) . "/s2-hacks.js";
        echo '</script>';
    }
?>


Thanks, DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Default form values

Postby Jason Caldwell » October 1st, 2011, 9:59 pm

Hey there! Thanks for the follow-up.

Yes, that's for the login header, try this for the site itself.

Code: Select all
<?php
add_action 
("wp_head", "s2_hacks_js", 15);
function s2_hacks_js()
    {
        echo '<script type="text/javascript">';
        include_once dirname (__FILE__) . "/s2-hacks.js";
        echo '</script>';
    }
?>
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Default form values

Postby man-O-media » October 1st, 2011, 10:20 pm

Yup... makes all the difference!

Many thanks...
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011


Return to Common Questions/Problems/Tips

Who is online

Users browsing this forum: No registered users and 2 guests

cron