Textfields and values with a value of 0 get blanked out if stepped forward/backwards I have a multipage form programmed with the drupal FAPI having in total 3 pages of fields consisting of textfields, textareas and radios, the form can be stepped forwards and backwards.

On page 2 of the form i have a few textfields where the user needs to enter numeric values. If these fields are not applicable, the user is asked to enter a 0.

The problem I have now if the user fills out that page No. 2, fills in a few 0 in these textfields and steps forwards/backwards, and afterwards steps back to that very page, the fields formerly filled with 0 are blank.

I really have no clue how to solve that as I need to use numeric values.

I now could set the default value to 0 instead of an empty value, but that would force the initial form to have already a 0 set. I do not want to solve it like this.

I have the feeling that the 0 is probably treated as a NULL (but actually in PHP 0 and NULL are different), but I am not sure. Dumping out the form array shows that indeed that 0 values are blank.

A textfield looks like this:

$form['t_2_1_2'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('... label text ...'),
    '#description' =&gt; ' ... desc. text ...',
    '#required' =&gt; TRUE,
    '#default_value' =&gt; !empty($form_state['values']['t_2_1_2']) ?
        $form_state['values']['t_2_1_2'] : '',
);


The structure of the entire form handling is very much based on the drupal multipage form example in the drupal form examples package!

Is there any way how I can solve that issue, that a value of 0 persists in the form, even stepping forward/backward?

I already tried to investigate similar problems, and found one where where the suggestion was to prepend a space to the 0 value, but that is a hack and I do not / can not use that as such!

Any hints are greatly appreciated, as I am sitting on this problem too long now and my time is running out to solve that issue. Thanks in advance for your hints!

Update: As nobody could help me here and my time is running, I solved the problem by using an 'x' instead of the '0' value, changed the validation to check for either a numeric value or an 'x'. Now the values all persist in the form fields, when I jump backwards/forwards in that multipage form. If the user used 'x', the value will be converted into an '0' value in the submit handler because the data is stored into mysql, and these fields are of type integer. At least a way I can live with.
You could also simply allow users leave the field empty and convert any empty “numeric” fields to a '0' in your submit handler. That might be a better user experience since it would save users the trouble of having to enter any values in those fields.