Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building a custom form that will show some details from a web service.

On my page callback I have two fields and submit button:


$form['starting_date'] = array(
   '#type' => 'date_popup',
   '#title' => 'Starting date',
   '#date_format' => 'd.m.Y',

$form['end_date'] = array(
   '#type' => 'date_popup',
   '#title' => 'End date',
   '#date_format' => 'd.m.Y',

$form['submit'] = array(
   '#type' => 'submit',
   '#value' => t('Check'),
   '#submit' => array('reports_list'),


function reports_list($form, &$form_state) {


I'm inserting the code that connects with the web service, passing the form_state values of selected dates and after that I'm trying to display the table with the web service details on the same page, but after clicking on submit it simply refresh the page and doesn't show anything.

I can see connecting with the web service is successful.

On custom submit function this for an example is not displaying:


$form['results'] = array(
   '#type' => 'markup',
   '#markup' => '<p>TEST</p>',

I'm doing something wrong, I guess...

EDIT: I've tried to display something in the submit function like this:


$form['results'] = array(
   '#type' => 'markup',
   'markup' => 'TEST10',

echo render($form['results']);

It's not working.

share|improve this question
That how form submit work.you could call die() at the end of report_list to see what it is displaying before refresh. But this could be done only for temporary purpose. Other wise you will have to redirect the form value to another page callback and do the displaying there – Nabil Feb 6 '14 at 12:23
I think your date_popup element is wrong. It must be 'date_popup' instead of date_popup – xurshid29 Feb 6 '14 at 12:26
I'm sorry, that was just typo, but in my code is with 'date_popup'. I'll edit my post. The date popup is showing with no problems, but I think on submit function I'm doing something wrong. – user2519032 Feb 6 '14 at 12:28
ok, another thing is you don't need to generate another $form array in submit callback. instead just display message. Or if you want to create another $form array, you need to render it with render() function. – xurshid29 Feb 6 '14 at 12:30
just use drupal_set_message() function then. – xurshid29 Feb 6 '14 at 12:45
up vote 2 down vote accepted

I think your problem is due to a misunderstanding of how Drupal forms work.

Drupal uses the PRG pattern for form submissions. That means for you, that you can't set form elements in the submit handler.

You can either set a message using drupal_set_message() which will be displayed on the next page.

Or you can instruct the form to rebuild, which will result in a redirect to the same form page that you came from with your form builder being called again. In the form builder function you can then check if the form has previously been submitted and then build the form accordingly. This second option is usually referred to as a multistep form. Have a look at this blog post for an example: http://davidsonj.com/blog/how-create-multi-step-form-drupal-7

share|improve this answer
Thank you very much for clearing that. – user2519032 Feb 6 '14 at 12:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.