0

I am using "remote" request option of jquery Validate plugin and also data is passed.

Is there any way to check what value is passed in the request?

I want to output userID variable that is being passed.

Here's a part of validation:

            personal_email: {
                email: true,
                remote: {
                    param:{
                        url: app.baseurl('user/check_personal_email'),
                        type: 'POST',
                        data: 
                        {
                            userID : function()
                            {
                                return $("#userID").val();
                            }
                        }

                    }
                    // ,
                    //  depends: function(element)
                    //  {
                    //      return ($('#editTrue').val() == undefined && $('#editTrue').val() == null);
                    //  }
                }
            },

And here's the controller's function that handles the request and send the result:

public function checkPersonalEmailExists($f3)
{
    $userID = $f3->get('POST.userID');
    echo "<script>console.log( 'User ID: " . $userID . "' );</script>";
    $email = $f3->get('POST.personal_email');
    $user = new UserModel();
    $records = $user->checkIfPersonalEmailExists($email);

    if(count($records) > 0)
    {
        foreach ($records as $record) 
        {
            $user_id = $record['id'];
        }
        echo ($userID == $user_id) ? 'true' : 'false';
    }
    else
    {
        echo 'true';
    }
}

I tried echo "<script>console.log( 'User ID: " . $userID . "' );</script>";.

Any help is very much appreciated. Thanks.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Azima
  • 3,835
  • 15
  • 49
  • 95
  • `echo "";` need to be `echo $userID;` – Alive to die - Anant Dec 14 '17 at 10:19
  • I don't think that works in the middle of a request... not working... :( – Azima Dec 14 '17 at 10:22
  • `remote` is looking for `user/check_personal_email`, but your function is named `checkPersonalEmailExists`.... that can't be working? – Sparky Dec 14 '17 at 19:04
  • PHP constructs the page on the server at the time it's first loaded. You can't `echo` something after an Ajax submission since you're not reloading the page. And if you did reload the page, that would defeat the whole purpose of using Ajax in the first place. You'd have to have Ajax loaded on the page ahead of time and trigger it when you need. – Sparky Dec 14 '17 at 19:08
  • If you want to see what values are sent within the Ajax request, you can just inspect the Ajax request directly from your browser's developer's tools. https://stackoverflow.com/questions/1820927/request-monitoring-in-chrome – Sparky Dec 14 '17 at 19:16

0 Answers0