Hi guys,

I'm having a serious issue about my forms in my drupal 7 website.

I have a custom design for my forms thanks to hook_form_alter and css customization.
Everything works fine, on my hook_form_alter I have some prefix and suffix to be able to make several distinct blocs of information.
My issue is when I have errors (when I intentionally don't fill all mandatory fields) after pressing the submit button while I have an uploaded image (that is 1 of my fields) : on this specific case, all the custom design flies away. I would like to get it back even when I have uploaded images.

The following images sum up my issue.
I'm sorry about the lack of information on the following images, it is simply to preserve the content we made while the website isn't online.

1st stage, this is our custom design, no bug, no worries :
First stage

2nd stage, we test the submit while there is lack of mandatory information :
Second stage

3rd stage, we upload a photo to our form (the error is because of our previous test) :
Third stage

4th stage, we test the submit while there is a lack of mandatory information, AND the image recently uploaded :
4th stage

I tried to make an after_build function to redeclare prefixes and suffixes, but it seems I'm in a distinct block and not in my custom form anymore after this error. I can't see my "dpm($form)" declared on my customhookform.

I really don't know what could possibly make this happen.
Thanks much for your time, it is much appreciated.

Comments

nevets’s picture

Have you tried using the field groups module for grouping and the display suite module for form layout.

Angelysto’s picture

Oh you again ! Hi nevets, thanks for your time :)

Well my issue is with the image field, so I'll :
1°) extract it from my customhook group and try simple css customization
2°) try the field groups module if 1°) isn't working
3°) check how display suite works otherwise (I haven't used it before)

I'll notice you guys if it's a success, I'm sorry I might have asked before trying my best to solve this one.

drm’s picture

So your hook is not refiring when the form is regeneted after the validation fail? It's hard to know why from here, but an alternative, certainly not ideal, is to put the structuring html and css in the form using jquery which you would always load for that url, rather than with hooks. Like I said, not idea, but if you can't get it to work with the hook, it is a fallback.