Note that there are some explanatory texts on larger screens.

plurals
  1. POdrupal: simple form and answer in the same url
    text
    copied!<p>I'm working my way around Drupal API with limited success.</p> <p>I want to have a URL with a form in it, so that when I "GET" that URL I get the form (have that), when I input a wrong "code" into that form and POST that same URL I get the same form with an error message (have that too), but when I POST that <strong>same URL</strong> with the right "code" I get a different code, no longer displaying the previous form.</p> <p>No redirects, all the requests (posts and gets) should be targeted to domain.com/entry</p> <p>This is a code I have (simplified):</p> <pre class="lang-php prettyprint-override"><code>function entry_menu() { $items['entry'] = array( 'page callback' =&gt; 'entry_handler', 'access arguments' =&gt; array('access entry'), type =&gt; MENU_CALLBACK, ); return $items; } function entry_handler() { return drupal_get_form('entry_daily_code'); } function entry_daily_code($form, &amp;$form_state) { $form['code'] = array( '#type' =&gt; 'textfield', '#title' =&gt; 'Code for Today', ); form['submit'] = array( '#type' =&gt; 'submit', '#value' =&gt; 'Access', ); return $form; } function entry_daily_code_submit($form, &amp;$form_state) { if (isset($form_state['values']['code']) &amp;&amp; $form_state['values'] == "1234") { drupal_set_message(t('Success')); } else { drupal_set_message(t('Fail')); } } </code></pre> <p>I imagine that what I want to do should happen in "entry_handler".</p> <p>It needs to know the status returned by the form, and to either return the form, or a different content, but I'm failing at that.</p> <p>Made a diagram to illustrate my point, in case it wasn't coming across: <img src="https://www.evernote.com/shard/s4/sh/5cf53bc9-6d2a-4338-846f-3c2cff35e6c5/f3d81fb81ff31b6f8a3735c683e7c2a4/deep/0/Blank.png" alt="diagram"></p> <p>Thanks for any pointers in the right direction.</p>
 

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