1

I'am on Joomla! 3.8.3, on the register form i have added some custom fields. I want when the user submit the form, make a check on one custom field to check if the value entered is in the list of values in a specific table.

Is it possible to do it ?

Thanks by advance

1

It is possible by developing a custom field.

https://docs.joomla.org/J3.x:Adding_custom_fields

In your custom field output, render JavaScript that reads and send Ajax request to check values.

If you want to add a custom field to a core component, such as Joomla! Articles, you need to create a plugin and add template override to your core component view. See documentation below.

https://docs.joomla.org/Adding_custom_fields_to_core_components_using_a_plugin

  • This doc explains for a third party component, but i want to add this field in the existing register part of Joomla! – user3533235 Jan 16 '18 at 10:35
  • See updated answer. – Nagarjun Jan 16 '18 at 14:00
1

Yes it is possible to check a value with ajax.

You could disable the default functionality of the form submit, for example (using jQuery):

$('FORM_ELEMENT').submit(function(e){
  //dont submit the form
  e.preventDefault();

  //if valid url_to_ajax_function should return true or false for example {"found": true}
  $.get("url_to_ajax_function?variable=value", function(data){
     //check if return ajax request is true
     if(data.found){
         //found, so submit the form
         $(this).submit()
     }else {
         alert('value not found');  
     }
  });
});

note that this is dummy code, and is only used here to show that it is technically possible, but this is the call as you could make it. It is definitely possible, but some jQuery knowledge is a must.

Another good way to check if the user has a valid field submitted (for example when a user has javascript disabled, so an extra failsave), a plugin could be created. You should use the observer onUserAfterSave(). Joomla documentary for creating plugin with onUserAfterSave().

Hope this will help you in the right direction!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.