Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Dec 2014
    Posts
    2
    Member #
    41009

    Question Check if a field value is present using json

    What I would need to achieve is to have a field on registering a new user to be checked if the value is present in another database using json. And if it is, go ahead registering the user otherwise throw an error message.
    Anybody have any ideas?

  2.  

  3. #2
    Senior Member sasha_bolcina's Avatar
    Join Date
    Sep 2014
    Location
    Serbia
    Posts
    274
    Member #
    40099
    Liked
    47 times
    If you are using jquery and the input field has id='required' you can check it when ajax response data is received.

    like:

    Code:
    var requiredFieldVal = $("#required").val();
    var url = "/url/to/server/side/jsonScript.php" // receives parameter "required" with value of the input field, checks if it is equal to db entry and returns json
    
    $.ajax({
      dataType: "json",
      url: url,
      data: { required: requiredFieldVal },  // object parsed and sent to server, input parameters
      success: function (data) {
                        if ( data.confirmed ) { // this depends of json structure you made. I use "confirmed" as json key with value "true".
                             // continue with registration
                        } else {
                            // display error
                        }
                   }
    });

  4. #3
    Junior Member
    Join Date
    Dec 2014
    Posts
    2
    Member #
    41009

    A little more help?

    Thank you.

    Sorry, I'm quite new, where would I put the code? Using the Rules module or directly in theme or where?

  5. #4
    Senior Member sasha_bolcina's Avatar
    Join Date
    Sep 2014
    Location
    Serbia
    Posts
    274
    Member #
    40099
    Liked
    47 times
    Read Working with JavaScript and jQuery

    And wrap your jquery code with
    $(document).ready(function){
    // jquery code here
    });


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:55 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com