Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal 6 Validation for Form Callback Function
    primarykey
    data
    text
    <p>I have a simple form with a select menu on the node display page. Is there an easy way to validate the form in my callback function? By validation I don't mean anything advanced, just to check that the values actually existed in the form array. For example, without ajax, if my select menu has 3 items and I add a 4th item and try to submit the form, drupal will give an error saying something similar to "an illegal choice was made, please contact the admin."</p> <p>With ajax this 4th item you created would get saved into the database. So do I have to write validation like</p> <pre><code>if ($select_item &gt; 0 &amp;&amp; $select_item &lt;= 3) { //insert into db } </code></pre> <p>Or is there an easier way that will check that the item actually existed in the form array? I'm hoping there is since without ajax, drupal will not submit the form if it was manipulated. Thanks.</p> <p><strong>EDIT:</strong> So I basically need this in my callback function?</p> <pre><code>$form_state = array('storage' =&gt; NULL, 'submitted' =&gt; FALSE); $form_build_id = $_POST['form_build_id']; $form = form_get_cache($form_build_id, $form_state); $args = $form['#parameters']; $form_id = array_shift($args); $form_state['post'] = $form['#post'] = $_POST; $form['#programmed'] = $form['#redirect'] = FALSE; drupal_process_form($form_id, $form, $form_state); </code></pre> <p>To get $_POST['form_build_id'], I sent it as a data param, is that right? Where I use form_get_cache, looks like there is no data. Kind of lost now.</p>
    singulars
    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.
 

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