I was testing out the new version and saw that a FIle Upload question that is Mandatory doesnt have astericks * like other fields (although validation is fine, it does make sure you are trying to upload something there). Thanks

Comments

armyofda12mnkeys’s picture

I saw in the file.inc code that it says...
' //'#required' => $component['mandatory'], // Drupal core bug with required file uploads' so maybe you guys know about it, uncommenting this line makes the page display the *, but not sure if its safe to uncomment this line as some bug you say occurs?

quicksketch’s picture

Thanks, I think the core bug is simply that it doesn't do anything. Webform has to do the validation manually. However, I didn't think about the asterisk not showing up. I don't think there's any harm in making it required. I'll test if it gives us any trouble, but if you can try it out and post how it goes, that'd be great.

sethcohn’s picture

Priority: Minor » Normal

Selects (checkboxes and radios) are missing the asterisks as well, and also missing Description fields.

quicksketch’s picture

Priority: Normal » Minor

sethcohn, I opened a new issue for your request #277270: Select doesn't have description or required. Please continue there.

armyofda12mnkeys’s picture

well tested: side effect of this is it validates twice once from Drupal and once from that custom validation maybe?

# Upload your orgs info field is required.
# Upload your orgs info field is required. (italics)

quicksketch’s picture

Title: required FIle Upload doesnt have astericks * » Required File Upload fields don't have asterisks (*)
Status: Active » Fixed

Cool, yep it looks like this problem has been solved in core. Webform likely included that fix for Drupal 4.7. I've removed the custom validation functions and we can use the ones now provided by core. And, as a bonus the asterisk now shows up. :)

Thanks for your report!

quicksketch’s picture

Status: Fixed » Active

Doh! I rolled back my changes because the #required property on file uploads prevents *any* submissions from happening. Even if you do select a file, Drupal thinks there isn't a value and won't allow the submission of the form. Looks like this problem definitely does still exist, even in Drupal 6.

advseb’s picture

subscribe

gdkt11’s picture

subscribe

arithmetric’s picture

Version: 5.x-2.1 » 5.x-2.6
Status: Active » Needs review
StatusFileSize
new1.34 KB

One potential solution is to add the formatted asterisk to the title property of the form element when it's generated.

I'm attaching a patch (against the CVS tag DRUPAL-5--2) that does this.

It doesn't come out quite the same as fields that use the #required property, because theme_form_element puts a colon (:) after the title, so it looks like:

Attach your file here *:

Instead of like:

Attach your file here: *

I wish it could be consistent, but I do think it's important to show that the field is required.

quicksketch’s picture

Status: Needs review » Needs work

The appropriate way to fix this would be to put a custom #theme property on the form element, then in the theme function add the #required = TRUE property. This way it would have the appearance of being required, but not be mishandled by FAPI.

arithmetric’s picture

Status: Needs work » Needs review
StatusFileSize
new1.33 KB

Here's a patch that takes this approach. If the webform file upload field is set to mandatory, then I use a custom theme function to add #required before handing off to theme_file.

eatrains’s picture

I'm having this same problem.

tawebworks’s picture

Title: Required File Upload fields don't have asterisks (*) » Problem running patch via Mac Terminal

I attempted to run the patch and got this message:

[Tami-Whitesides-Computer-10:~] tamiwhit% patch < /Users/tamiwhit/Desktop/websites/Meck\ Promise/sites/all/modules/webform/components/webform-file-required_mark_theme.patch
can't find file to patch at input line 8
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: file.inc
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/file.inc,v
|retrieving revision 1.2.2.19.2.32
|diff -u -r1.2.2.19.2.32 file.inc
|--- file.inc 4 Mar 2009 05:05:18 -0000 1.2.2.19.2.32
|+++ file.inc 11 Apr 2009 21:38:55 -0000
--------------------------

Can anyone help me with this issue?

quicksketch’s picture

Title: Problem running patch via Mac Terminal » Required File Upload fields don't have asterisks (*)

You need to be in the directory that contains webform.module. Looks like you ran the patch from your home directory. Please do not ask general patching questions as it can derail the conversation thread.

tawebworks’s picture

Title: Required File Upload fields don't have asterisks (*) » Required File Upload fields don't have asterisks (*)

Thank you for your assistance, quicksketch. I was able to get the patch applied. Now, where do I ask about a problem caused by that patch? (Just so I know.)

tawebworks’s picture

Detour, I applied your patch and now my file upload field components disappear completely. Have you had any more chance to work on this patch?

quicksketch’s picture

Version: 5.x-2.6 »
Status: Needs review » Fixed

I've fixed this in 3.x as part of #216529: File Upload Doesn't Work With Page Break -- Upgrade File Component to use FID values instead of file arrays. Unfortunately this won't make it back to the 2.x version or Drupal 5.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

edhel’s picture

Version: » 5.x-2.6

I fix this issue on Drupal 5.6 by such code in template.php:

function phptemplate_form_element($element, $value) {
  if ($element['#type'] == 'file' && !empty($element['#validate']['_webform_required_file']) && $element['#validate']['_webform_required_file'][2]) $element['#required'] = TRUE;
  return theme_form_element($element, $value);
}