How to auto-submit a form using Drupal Form API? I need help with making a drupal form. I've made the form and it works perfectly fine, all it does is capture the email, ip, and date and time of a user. The problem is I don't want the user to have to click a button in order to submit the form, I want the form to automatically submit after a second or something.

//form hook, form elements start here

function form_casl_form($form, &amp;$form_state) {
//sometext here
 $form['some_text'] = array(
    '#markup' =&gt; '&lt;p&gt;&lt;b&gt;Simply click the button to subscribe.&lt;/b&gt;
    &lt;/p&gt;'
);


  //submit button
  $form['submit_button'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Subscribe'),

  );
  return $form;
}
    //validate hook


Is there anyway to do this? I'm very close to finishing and this is the only thing I'm stuck on, any ideas would be appreciated!
This one is a pretty easy method by adding 'onChange' to the '#attributes' array:

/**
 * Custom form handler.
 */
function FORM_EXAMPLE($form, &amp;$form_state) {

  $form['complete_projects_radios'] = [
    '#type'          =&gt; 'radios',
    '#title'         =&gt; t('Project status'),
    '#default_value' =&gt; 0,
    '#options'       =&gt; [
      0 =&gt; t('Current'),
      1 =&gt; t('Complete'),
    ],
    // Define the onChange like so:
    '#attributes'    =&gt; [
      'onChange' =&gt; 'this.form.submit();',
    ],
  ];

  $form['complete_projects_submit'] = [
    '#type'       =&gt; 'submit',
    '#value'      =&gt; t('Apply'),
    // The submit itself is necessary, but now it can be hidden:
    '#attributes' =&gt; [
      'style' =&gt; ['display: none;'],
    ],
  ];

  return $form;
}