Search code examples
expressionengine

Expressionengine Let user know if url_title is already used


I have a safecracker form that allows users to enter title, url_title body content. If url_title is already in used, by default, a numerical number gets added to url_title so it’s unique. But instead of having this automated behavior where number gets added to url_title, Is there a way i can notify the user that the url_title typed is already taken so user can enter a new one.


Solution

  • To validate the {url_title} in your SafeCracker form on the fly before submission, you could write an Ajax routine that would check and compare the value of the <input /> against the url_title column in the exp_channel_titles database table.

    When SafeCracker was being developed by Barrett Newton, there used to be Developer documentation for Custom Fieldtypes and Extension Hooks, but since EllisLab took over SafeCracker I believe they've been removed.

    However, since SafeCracker handles its server-side form validation using the CodeIgniter Form Validation class, you should be able to extend the validation class to meet your needs by creating a callback function to validate the {url_title} on form submission, instead of silently allowing ExpressionEngine to append a digit to the field data.