• Resolved kilianso

    (@kilianso)


    Hello! Let’s say someone is signing-up for the first time using Google SSO. Now since it’s a new user, i want them to add additional info during registration, like their website, their instagram handle and so on. How can i add custom fields to the registration form and save those values to their profile?

    Any example code where this has been done in the past, would be very helpful.
    Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter kilianso

    (@kilianso)

    Nevermind, i think i just found the solution on my own. https://nextendweb.com/nextend-social-login-docs/backend-developer/#custom-fields

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @kilianso

    Yes, if you would like to ask some extra information before the registration then you need to do some custom coding.
    The documentation and the example that you found:

    is exactly what you were looking for.

    Tip:
    By default we ask all of the extra details on the WordPress default login page ( /wp-login.php ), if you don’t like that, then you can use our “Page for register flow setting”, that you can find on our General tab:

    with that setting you could make Nextend Social Login to display the form in a page of your theme. ( Just make sure the page that you select for our “Page for register flow” setting is not used by anything else, as that could create a conflict. )

    Best regards,
    Laszlo.

    Thread Starter kilianso

    (@kilianso)

    Hey Laszlo

    Thanks for the tips.

    I was able to set it up and did a test using your “favorite color” example. Now since i’m using a custom page (user-signup-additional) for the register flow, i’m struggling to control the form validation.

    My error messages are placed directly after the opening body tag causing a strange visual result. How can i control the position of validation error messages? Like directly below the affected form field?

    And what would be the recommended approach if i have a more complex form and don’t want to pollute the the nsl_before_register with all the additional form markup? As an example, i’d like to let new users set a country from a dropdown and based on the country, a city dropdown should update. Building that on top of the example showed in your developer docs is just not feasible for this kind of form logic. Also, i’d like to have a custom submit button and form layout. So basically a entirely custom form to add additional fields before completing registration.

    I’m using Timber/Twig for rendering. Is there a way to just setup a template and pass data from and to the Nextend registration flow?

    Many thanks
    Kilian

    • This reply was modified 2 years, 9 months ago by kilianso.
    • This reply was modified 2 years, 9 months ago by kilianso.
    • This reply was modified 2 years, 9 months ago by kilianso.
    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @kilianso

    As for the validation error messages:
    If you mean the validation error messages that you added over the “nsl_registration_validate_extra_input” filter ( while you are also using the “Page for register flow” setting ), then those should be already rendered with the form it self, just above the form.
    Since those errors are also rendered by the same [nextend_social_login_register_flow] shortcode that renders the registration form with the extra fields.
    And we don’t have an option to customize the place where these errors show up, I am sorry.

    If you rather meant the floating error message on the top right corner, when you use the “OAuth redirect uri proxy page” setting, then that is not connected to these validation error messages. But that floating message is rather connected to failed registration / login attempt, and usually shows up when we still have some error messages that your site didn’t display anywhere yet. We can not know in advance where these errors will show up, since when there is a failed registration / login attempt, you can get redirected to anywhere ( for example if our registration / login is prevented by a third party plugin, that could redirect the user to their own page and with this floating popup we can still inform the user about the error even on that page, although we can not know anything about the context ).

    As for using a template:
    If you include and render the contents of the template in the function that you hooked to the “nsl_registration_form_start” action, then that could probably work, just don’t forget to match the “name” attributes of the input fields with the codes that validate the process the posted data.
    However please note that I haven’t tested it.

    Another suggestion:
    I assume you need that extra data on some pages, let’s call them “protected” pages.
    If you want to avoid custom coding / managing the registration form fields and validation at two places, then I would rather suggest you to handle these extra fields in your theme it self ( where you probably already have this implemented ). So what you could rather do, is triggering a redirect to the “profile” page each time when the user tries to reach a “protected” page and they have some required profile fields that doesn’t contain data. So basically the protected pages could only be reached if all the required fields are filled up.

    Best Regards,
    Laszlo.

    Thread Starter kilianso

    (@kilianso)

    Hey Laszlo

    Thanks for your fast answer. Regarding the form validation: It does something really strange. It seems like the validation error is placed in the head of the site rather than within the form container. This causes some weird glitch where all the other head stuff is placed within body as well.

    Additionally, the form validation does not appear within the form and the form labels (without inputs) are repeated on top of the page.

    Check out this screensshot:
    https://ibb.co/6FDVRZt

    I don’t use the OAuth redirect url proxy page. Just a custom page for register flow.

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @kilianso

    Is it possible that you print-ed/echo-ed the error message directly in the validation function? If you did, then that is the problem. Since as you see in the example:

    you shouldn’t render anything on the “nsl_registration_validate_extra_input” filter, but the error message should be added into the errors object, like in the example:

                    $errors->add('favorite_color_missing', '<strong>' . __('ERROR') . '</strong>: Favorite Color can not be empty.', array('form-field' => 'favorite_color'));
    

    You could check this easily, by removing all of the custom codes that you currently used to modify Nextend Social Login, and try using the code example from the documentation, without any modification.

    Could you check please if that makes any difference?

    Thread Starter kilianso

    (@kilianso)

    Hey @laszloszalvak

    No, i did not made any changes. Just copied your example code. The problem remains the same.

    Where do you handle this error object?

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @kilianso

    That specific error object is handled in the customRegisterFlowShortcode() function in this file:

    • wp-content/plugins/nextend-facebook-connect/includes/userData.php

    which is basically the function behind the [nextend_social_login_register_flow] shortcode.

    Anyways could you send us a link of the page where we can check this problem? If you don’t want to share the URL of the page on this forum, then please rather open a support ticket here:

    so we could make some tests.

    Thread Starter kilianso

    (@kilianso)

    Okay so i figured out, what’s causing the validation problem. Leaving that here in case someone or you @laszloszalvak is running into the same issue.

    On single pages and single posts i’m using the first few words of the content as the meta description. This is also the case for a page that is set as “page for register flow.”

    Now since Nextend is dynamically prepending html to the content to style and output validation errors, it interferes with the meta description mechanism. Causing a semantic error where html is not getting stripped and therefore, the layout breaks. Even using striptags does not help and the html by Nextend persists in the meta description.

    This could also cause conflicts with SEO plugins.
    So my (clearly not perfect) solution is to check if the slug is the page for register flow and then just output a static description. This is resolving the issue and the form validation appears at the right spot with the right styling of Nextend.

    Few more questions:
    1. How can i overwrite the form or parts of it? Like adding additional CSS classes to the submit button or even replace it entirely?
    2. How can i display data on that page for register flow, that already has been fetched from social media? E.g. I’d like to show a page that says: “Complete your registration” where you can already see your profile image, first- and lastname and nickname but then, you need to fill out additional fields to submit your registration.
    3. How can i display a field like “nickname” and if already set, let the user change it in that moment?
    4. How can i change / style that “Hold on” overlay that appears before redirect?

    Thank you so much! Fantastic support ??

    • This reply was modified 2 years, 9 months ago by kilianso.
    • This reply was modified 2 years, 9 months ago by kilianso.
    • This reply was modified 2 years, 9 months ago by kilianso.
    • This reply was modified 2 years, 9 months ago by kilianso.
    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @kilianso

    I am glad you managed to find the cause of the problem.

    As for the questions:
    1.) I am sorry, but you can not override the existing parts of the form. We only allow adding extra content to the form over the mentioned “nsl_registration_form_start” action, but we don’t allow the modifications of the form it self.
    But with custom CSS you could override the style of the form elements. E.g. each page has a unique ID that is present on the body tag, e.g.: .page-id-43
    So with that you could write a CSS selector that targets the form elements on our Register flow page only. However I don’t suggest hiding the submit button, since that way the user won’t be able to complete the registration.

    2.) With the “nsl_registration_form_start” and “nsl_registration_form_end” actions you can render extra data into the form.
    These actions have 2 parameters, the first parameter contains some user data specific to the form, and the second parameter is the Provider instance. The provider instance has methods that you could run to get the fetched data, e.g.:
    $provider->getAuthUserData('first_name');
    like you see in another code example of the developer documentation:

    If you are not sure about the available keys, then you could check them in the getAuthUserData() function of each providers. So basically you could write those out in your extra fields.

    3.) You could add the Nickname field the same way as the Favorite Color field was added in the code example:

    What you do with the data only depends on the code that you write on the “nsl_registration_store_extra_input” action.

    4.) In our Global Settings > General tab you can find the “Redirect overlay” setting:

    and with that you could change the way the overlay appears.
    If you would like to customize it, then we don’t have options for it I am sorry, but by stronger CSS selectors or maybe with !important rules, you could override our styles.

    Note: If you would like to modify the:

    • Hold On
    • You are being redirected to another page…

    texts, then you can find those in our language files, so with custom translations you could modify them:

    You can create custom translations for even English language, so that way you could override the default English texts as well.

    Best regards,
    Laszlo.

    Thread Starter kilianso

    (@kilianso)

    Hey Laszlo

    Great answer! Thank you.

    One more follow up.

    1. You write:

    If you are not sure about the available keys, then you could check them in the getAuthUserData() function of each providers

    How? Where is this documented? If i just do $provider->getAuthUserData() without params, it fails since it expects a key. But how do i get those keys and aren’t they normalized across providers through your plugin? I mean, let’s say the key on Tiktok is firstName and on Google it’s first_name, would i need to write additional logic to uniform the data for displaying, or do your plugin take care of that? And is this even the case or is it safe to just call $providers->getAuthUserData(‘first_name’) across all providers?

    2. And what about the Avatar? How can i display that one on e.g. the page for register flow?

    3. Wouldn’t it make sense to put all the data the provider offers in the $userData object? I mean userId, avatarURL, first_name, last_name, username, email… just everything. What’s the reason of separating these things even though the data is available anyway?

    Thanks a lot for your amazing support!

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @kilianso

    1.) This is not documented, since if you want to use these core methods you need to have developer knowledge, and before you would use them you should have already checked what they actually do and how they work, since we can not provide support for custom coding and problems caused by custom codes. That’s the main reason I rather suggested it in my previous reply to inspect the getAuthUserData() function in the corresponding files. You can find them easily by searching for the expressions an IDE ( like PHPStorm ) or in a file manager that has such feature ( like Total Commander ).

    About the keys:
    The keys are normalized, however not all providers return the same data. ( E.g. some providers don’t have avatar feature. ) If you inspect the getAuthUserData() method, you will see that it returns an empty string for if the provider doesn’t doesn’t have such key.

    2.) As I mentioned above, you can render the content into our registration flow form via the “nsl_registration_form_start” action. If you search for the name of this action in our files, you will see that the second parameter is the provider instance, so you could get the avatar from that via the getAuthUserData() method, and then render it with custom HTML, the same way you add the extra fields.

    3.) At that point, the $userData contains the default sanitized data and can also contain the custom data that was posted over the registration form ( so you can validate the data ) while the getAuthUserData() returns only raw data that comes directly from the provider, so their purpose are different.
    In the $userData we try to use minimal data, which is actually used there, and if you need additional data that is not in the array, then you should get it with the getAuthUserData() method.

    Please note that this topic has gone towards the direction of custom coding way too much, and as you also saw at the top of our developer documentation:
    https://nextendweb.com/nextend-social-login-docs/backend-developer/
    we can not provide support for it. So if you still have coding related questions, then please rather check the logic of our codes in our files.

    Best regards,
    Laszlo.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Custom fields in registration form’ is closed to new replies.