I am trying to make a match check on the phone in the joomshop component, I just don’t understand how to get the variable to be checked. The function that checks if such user exists:

function check_user_exist_ajax() { $mes = array(); $username = JRequest::getVar("username"); $email = JRequest::getVar("email"); $mobil_phone = JRequest::getVar("mobil_phone"); $db = JFactory::getDBO(); /* $mes[] = sprintf(_JSHOP_USER_EXIST_EMAIL, $mobil_phone); */ if (isset($mobil_phone)){ $query = "SELECT id FROM `#__jshopping_users` WHERE mobil_phone = '".$mobil_phone."'"; $db->setQuery($query); $db->query(); if ($db->getNumRows()){ $mes[] = sprintf(_JSHOP_USER_EXIST_EMAIL, $mobil_phone); } } if ($username){ $query = "SELECT id FROM `#__users` WHERE username = '".$db->escape($username)."'"; $db->setQuery($query); $db->query(); if ($db->getNumRows()){ $mes[] = sprintf(_JSHOP_USER_EXIST, $username); } } if ($email){ $query = "SELECT id FROM `#__users` WHERE email = '".$db->escape($email). "'"; $db->setQuery($query); $db->query(); if ($db->getNumRows()){ $mes[] = sprintf(_JSHOP_USER_EXIST_EMAIL, $email); } } if (count($mes)==0){ print "1"; }else{ print implode("\n",$mes); } die(); } 

I can not get a phone number $ mobil_phone = JRequest :: getVar ("mobil_phone"); Returns an empty field. Explain how JRequest :: getVar gets data

    1 answer 1

    JRequest obsolete class!

     $input = JFactory::getApplication()->input; // объект JInput $mobil_phone = $input->getString('mobil_phone'); // в классе JInput есть методы для получения конкретных типов данных, в этом случае мы получаем строку $method = $input->getMethod(); // так мы можем получить метод по которому был отправлен запрос на сервер $mobil_phone = $input->$method->getString('mobil_phone'); // так получаем данные из метода по которому был отправлен запрос на сервер, вместо $method мы можем указать непосредственно сам метод get, post и тп 

    basically all fields of the form in Jumla are grouped into jform, that is, the field name will be jform [mobil_phone]

    and here, in order to get the values ​​of this field, you first need to get an array of jform, and then the necessary element by key

     $input = JFactory::getApplication()->input; $data = $input->get('jform', array(), 'array'); // $data['mobil_phone'] // это и будет значения нашего поля 
    • The old version was there, in general, I figured out that the problem was that I didn’t know how to transfer these variables to the controller, the JS file was minified, so it was difficult to understand that everything was transferred via AJAX - Samar