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

2 Answers 2

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

2
  • This doc explains for a third party component, but i want to add this field in the existing register part of Joomla! Jan 16, 2018 at 10:35
  • See updated answer.
    – Nagarjun
    Jan 16, 2018 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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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