I'm working my way around Drupal API with limited success.
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 same URL with the right "code" I get a different code, no longer displaying the previous form.
No redirects, all the requests (posts and gets) should be targeted to domain.com/entry
This is a code I have (simplified):
function entry_menu() {
$items['entry'] = array(
'page callback' => 'entry_handler',
'access arguments' => array('access entry'),
type => MENU_CALLBACK,
);
return $items;
}
function entry_handler() {
return drupal_get_form('entry_daily_code');
}
function entry_daily_code($form, &$form_state) {
$form['code'] = array(
'#type' => 'textfield',
'#title' => 'Code for Today',
);
form['submit'] = array(
'#type' => 'submit',
'#value' => 'Access',
);
return $form;
}
function entry_daily_code_submit($form, &$form_state) {
if (isset($form_state['values']['code']) && $form_state['values'] == "1234") {
drupal_set_message(t('Success'));
}
else {
drupal_set_message(t('Fail'));
}
}
I imagine that what I want to do should happen in "entry_handler".
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.
Made a diagram to illustrate my point, in case it wasn't coming across:
Thanks for any pointers in the right direction.