Hi!

This seems like the silliest oversight, but how can I add this Name attribute to a Form? I can add/change the Method, ID etc, but no name?

Weird.

TIA

Comments

dman’s picture

use

$form = array (
  '#attributes' => array('name' => 'formname'),
  ...
);

For that and any extra attributes you want to add to form (or other) elements.
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...

Why 'name' anyway? isn't ID good enough for you?

toxicdesign’s picture

Oh yeah :) Thanks man...

Why do I want a "Name" and not just ID?

Well I want to submit the form with javascript (when a user clicks on a radio button in the form), and I'm too scared to use:

document.getElementById('myorm').submit();

Instead of just the old fashioned way of "document.myform.submit();

If you have anysight into this, I'll listen!

Of course I'm sure there is a nice way to do this with jquery, but haven't had much success with that yet.

Cheers!

(and yes Drupal trully kicksass)

jaskegreen’s picture

Does this work the same for adding a title to the form? For example, I want to add a title for a section of the form to give users a better understanding of what the section is about without having that title show in the Excel download.

Thanks,
Jason

dman’s picture

"name" is an old HTML tag attribute. Not visible to the user.

You want to either -
- add an element to the form of #type=markup with the value of the text you want to insert
- add the text as a #prefix of a tag within the form
or
- use a fieldset to actually structure your sections.

None of these will change the way the data is saved.

jaskegreen’s picture

Right, so I created another fieldset called label and got it to come up as one of the choices when making a survey, but couldn't get it to pull the info from the db to show on the survey node. I know I'm missing that last part, but don't know what to change to get the label to print out on the page.

Any advice and examples of coding would be helpful.

Thanks,
Jason

PS - This would probably be better discussed in another issue I created for this topic. See http://drupal.org/node/202535.

quicksketch’s picture

Status: Active » Closed (fixed)

Forms and survey modules are no longer being maintained, use Webform module instead.

---Closing down issue queue of survey module---