title: Drupal 7 Form API run function on form submit
body: <p>I have created a custom module that I need to collect info and run a function when a form is filled out and submitted.</p>
  
  <p>It has two text areas and a button.</p>
  
  <p>This is what I have which shows up fine on the page:</p>
  
  <p>File: <code>myFunction.admin.inc</code></p>
  
  <pre><code>function myFunction_form($form)
  {
  
      $form['pages'] = array(
      '#type' =&gt; 'fieldset',
      '#title' =&gt; t('Data'),
      '#collapsible' =&gt; FALSE,
      '#collapsed' =&gt; FALSE,
    );
  
      $form['pages']['title'] = array(
      '#type'          =&gt; 'textarea',
      '#title'         =&gt; t('Title'),
      '#rows'          =&gt; 5,
      '#resizable'    =&gt; FALSE,
    );
  
    $form['pages']['body'] = array(
      '#type'          =&gt; 'text_format',
      '#title'         =&gt; t('Body'),
      '#rows'          =&gt; 5,
      '#resizable'    =&gt; FALSE,
      '#format' =&gt; 'full_html',
    );
  
    $form['submit'] = array('#type' =&gt; 'submit', '#value' =&gt; t('Run Function'));
  
      myFunction($form);
      return $form;
  
  }
  
  function myFunction()
  {
  //This is where I use the data collected from my form and do what I need to do.
  }
  </code></pre>
  
  <p>So the things I missing form this (and please tell me if i'm going the wrong way about this) is I need to validate the form was filled out and return error message if not.</p>
  
  <p>if the form was filled out then correctly pass the field data to my function which I did simply by adding <code>function myFunction()</code> before <code>return $form;</code> but this seems like the wrong way to do it. I don;t want the <code>myFunction()</code> to run if there is and errors with the form.</p>
  
  <p>Could someone please help me with this last part of my custom module.</p>
  
  <p>Please not that this module does NOT add anythig to the database. </p>
  
  <p>Again, please tell me if i'm going the wrong way about this.</p>