I have a form to get some user input in Drupal. I want to add some prefix to the user input.
For example, the user enters “Laptop”; I want to save it in the database as resource_Laptop. I want to add the prefix before the validation is done, to avoid it fails.
How do I do this? Will hook_form_alter()
help me here?
I have used this method, but not satisfied with this hack.
function mymodule_form_alter(){ drupal_add_js(" (function ($) { $(document).ready(function() { $('.field-suffix').hide(); $('#edit-submit').click(function(){ var s = $('#edit-machine-name').val(); if (s.indexOf('_resources') == −1) { $('#edit-machine-name').val($('#edit-machine-name').val() + '_resources'); } }); })(jQuery);", 'inline'); }