Hi,

I have a views exposed form and I am trying to target the form id, getting confused!

From what I have read "inspect HTML to get the form ID"

<form id="views-exposed-form-patient-search-page-1" method="get" accept-charset="UTF-8" action="/cortex/patient">

So from what I have read 'views-exposed-form-patient-search-page-1' should be the form id, this don't work!

Tried 'views_exposed_form_patient_search_page_1' Still no luck!

Any ideas where I'm going wrong?

Comments

nevets’s picture

If I am implementing hook_form_alter, I temporarily have add the line drupal_set_message("Form Id: $form_id") and visit the page in question. The devel module is also useful in this regard.

ludo1960’s picture

OK, so I have an exposed view and created a menu path for the page display, I tried the code in the view header, but all I get is "Form Id: "

I have the devel module Development block enabled, but I'm not sure which option to use to find the form_id

nevets’s picture

The code expects to be in an implementation of hook_form_alter() which would be part of a module.

ludo1960’s picture

Thanks again Nevets,,u da man!

jim0203’s picture

Check out

http://www.lullabot.com/articles/modifying-forms-5-and-6

Specifically the section "Find the form ID"

ludo1960’s picture

Jim, the info there on find the form id was just as I originally posted, ie look at the html source. To my cost I have found out that it is not always the case, Nevet's code works a treat!

YK85’s picture

hello,

I was wondering what the form id ending up being?

As you mentioned this code does not work:
function project_extras_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'views_exposed_form_search_page_1' :

This code works but it affects all exposed forms on the site.
function project_extras_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'views_exposed_form' :

Could you please help me to target just the view search or view search page 1.
Thank you!

ludo1960’s picture

When posting code, please us the code tags to make it easier to read for us!

The answer to your question is already in this thread see http://drupal.org/node/672688#comment-2428084

nevets’s picture

You can use logic like

	if ( $form_id == 'views_exposed_form' ) {
		$view = $form_state['view'];
		if ( $view->name == 'colors' && $view->current_display == 'page_1' ) {
			// do something with form
		}
	}

You will need to change name ('colors') and display ('page_1') to reflect your actual view.

YK85’s picture

thanks nevets! your code above worked perfectly =)

mohaly’s picture

Thanks Nevets for you solution, it works with me in Drupal 7.

Regards,

marianojp’s picture

Paste this code inside your template.php. It's should give you the form id of the views exposed form.

function phptemplate_views_exposed_form($form) {
     dsm($form);
     return($form);
}