Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal FAPI form calls callback twice
    primarykey
    data
    text
    <p>First post on stack overflow... so go easy on me! </p> <p>There doesn't seem to be a suitable solution to the Drupal FAPI multiple callback issue for simple form submissions. </p> <p>THE PROBLEM: My form, when submitted, adds two entries to the respective database table. Given that there is only one call to add it to the database, I feel it's safe to assume that the query is run twice (hence the dual entries).</p> <p>The following code may help to provide a basis for a solution. Oh, it's Drupal 7 too, so documentation is still very much D6 centric.</p> <pre><code>function mymodule_sidebar_form_add_submit(&amp;$form, &amp;$form_state) { $form_values = $form_state['values']; $se_title = check_plain(trim($form_values['title'])); $se_link = url(trim($form_values['link'])); $se_content = check_plain(trim($form_values['content'])); $se_image = isset($form_values['image']) ? $form_values['image'] : ''; // The multi-line part below is actually a single line the real code $query = sprintf("INSERT INTO sidebar_element(title, image_url, content) VALUES ('%s', '%s', '%s');", $se_title, $se_image, $se_content); db_query($query); drupal_set_message(t('Sidebar Element has been added successfully.')); } </code></pre> <p>... and my form function contains a submit button:</p> <pre><code> $form['submit'] = array( '#value' =&gt; t('Add Sidebar'), '#type' =&gt; 'submit', '#title' =&gt; t('Add Sidebar'), '#submit' =&gt; array('mymodule_sidebar_form_add_submit'), ); </code></pre> <p>I guess the questions I need answered are:</p> <ol> <li>Why is there a double callback in the first place?</li> <li>Is there a way to identify the first callback?</li> </ol> <p>Thanks in advance to all.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload