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.

Access the custom reg fields with java script

Home Forums Community Forum Access the custom reg fields with java script

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

Topic Author Topic
Posted: Wednesday Aug 22nd, 2012 at 6:48 pm #22788
Robert Baptie
Username: bapo

I simply want to access the country_id field to find out which one was selected in the list of a custom registration field. I have a jQuery function that works on other pages but I cannot find out where to locate the call to this function to get it to run with the s2Member registration page? Help if you can! I need the file name I think???

I have the following code associated with the given hook:

add_action(“ws_plugin__s2member_before_custom_field_gen”, “my_dynamic_field_options”);

function my_dynamic_field_options($vars = array()) {
    $conn = null;
    try {
        $_field = &$vars["__refs"]["_field"];
        if ($_field["id"] === "country_id") {
            $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);            
            if (!$conn) {
                die('Could not connect: ' . mysql_error());
            }
            $sql = "SELECT
                        ISOen_name, ISO3166A2
                        FROM isocodevscountry
                        ";
            mysql_select_db(MYSQL_DB);
            $retval = mysql_query($sql, $conn);
            if (!$retval) {
                die('Could not get data: ' . mysql_error());
            }
            $count_countries = 0;
            while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
                if ($count_countries == "0") {
                    $_field["options"] = "{$row['ISO3166A2']}" . "|" . "{$row['ISOen_name']}" . "|" . "default" . "n";
                } else {
                    $_field["options"] .= "{$row['ISO3166A2']}" . "|" . "{$row['ISOen_name']}" . "n";
                }
                $count_countries++;
            }
            mysql_close($conn);
        } elseif ($_field["id"] === "city_id") {
            //Get selected Country
            //Fill list with reference to selected country        
        }
    } catch (Exception $ex) {
        echo"Error in login to data base " & $ex;
        mysql_close($conn);
    }
    

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Wednesday Aug 22nd, 2012 at 8:24 pm #22794
Eduan
Username: Eduan
Moderator

Hello Robert,

I may have the answer, but I need to know in which part of the registration you need this info, right at registration? Right after registration? etc.

You might want to check Dashboard -› s2Member® -› API / Notifications meanwhile.

Hope this helps. :)

Posted: Thursday Aug 23rd, 2012 at 2:31 am #22808
Robert Baptie
Username: bapo

It is the standard s2Member registration page with some HTML custom ‘select’ lists added via the s2member dashboard. The code above populates one of these lists. The name is country and the id specified in the dashboard is country_id. The list allows me to select elements from it but I need to populate a further list on the page (using javascript – jQuery), before I hit the registration form accept button. The first list is countries of the world – the second list must be cities associated with this country. This – I think – should be a straight forward thing to do?

Posted: Thursday Aug 23rd, 2012 at 9:30 am #22855
Eduan
Username: Eduan
Moderator

Hello Robert,

Well you might like to modify WordPress’ registration page so that it shows the fields the user selected through $_POST or $_GET, that way you’ll get easy and fast access to it.

That’s what I normally do, just remember to not do it with sensitive data (password etc.).

Hope this helps. :)

Posted: Friday Aug 24th, 2012 at 2:38 am #22920
Robert Baptie
Username: bapo

Eduan

Isn’t that server side coding in php – I need to be able to access the fields (specifically country_id as specified through s2member interface), through java script on the client before the form is submited?

My problem is what file to locate the javascript so that it is recoignised and runs on the page. This should be easy?

Any help here appreciated.

Posted: Friday Aug 24th, 2012 at 10:13 am #22971
Eduan
Username: Eduan
Moderator

Hello Robert,

Yes this should be fairly easy in jQuery, although I don’t understand why you are accessing the database in your code, even though at this point the database isn’t brought up in the registration.

Anyway, the jQuery I would use to get the value of a field would be:

$("#country_id").change(function() {
	$("#get").text(($(this).val()));
	alert($("#country_id").val());
});

or

$("#country_id option:selected").text();

Which ever works best for you. ;)

If they don’t work, please tell me. ;)

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.