can you tell me what happens when this code is writen into a .module file?

$form = drupal_get_form('myModule_main_form');

function myModule_main_form($form, &$form_state) {
  $form['submit'] = array(
	  '#type' => 'submit',
    '#value' => t('Submit'),
	);
  return $form;
}

It seems it brokes the site completely. And it doesn't get restored even after removal of the module folder. Obviously something changes in the database, but I have no idea what exactly. I broke two sites this way.
I was just trying to expariment whith for API following instruction on
http://api.drupal.org/api/drupal/includes--form.inc/group/form_api/7
so maybe there is a trap for begginer developers there.

Comments

devin carlson’s picture

Status: Active » Closed (fixed)

That code renders the form "myModule_main_form" to HTML and assigns it to the variable $form. The function below "describes" the form using the Form API (fapi).

Doing that shouldn't break your site (I've experimented with doing the same thing(s) myself). You should be able to simply remove the code and any errors that were caused should go away.

Also, try naming your first variable something other than $form and make sure that you are changing the text "myModule" to whatever the name of your module is. If you are still having problems, clear your site cache. You should never remove the modules folder.

regginos’s picture

Thanks Devin! A lot of time passed since I posted that support request. Since then I have worked a lot with forms and I have a much better understanding how form API works. I still don't know what caused the trouble in my code that time, and I don't find it that important anymore. Propably the variable name "$form" was the source of the problem. Anuway, thanks again for your time!