1

I'm trying to figure the best way to get a form id from the search block form for example. I want grab the id that's in the input field and insert that name in my label tag. For example

<input id="edit-search-block-form--4"...

would go into

<label for="edit-search-block-form--4"...

I know you can call the for attributes beginning with

$form['name_of_form_field'] '

but how do I place that id into a variable then place that variable into my label and output it?

  • So you are wanting to alter the search form to use the field array keys as additional classes or hidden values on the labels of the fields in the search form? Drupal often does a good job of adding lots of css classes that identify what the object is. Is there not something already present that you could use? What is the end goal? – DeveloperWeeks Jul 29 '15 at 16:19
  • It's a section 508 accessibility issue, people that use screen readers wont have a label tag to read above the form input field. I want just grab the automated id in the input field of the search_block_form and place that id name in the "for" attribute of the label tag that I will insert into the code. Would be nice to know how to call the label tag and print it properly in Drupal as well. – StoryTech Jul 29 '15 at 21:23

Your Answer

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

Browse other questions tagged or ask your own question.