Possible bug with custom fields

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,667
Possible bug with custom fields
«  »
  • Create a custom field in the gallery
  • Make it a checklist
  • Make it required
  • Make it searchable
  • Edit an item, don't fill that field
  • Observe errors when saving
Code: [Select]
// Add them to the form
  foreach ($fields as $field)
  {
- if ($field['type'] == 'checkbox')
+ if ($field['type'] == 'checkbox' && empty($field['searchable']))
  $field['value'] = explode(', ', $field['value']);
 
  // Options...
  $value = isset($_POST['custom_field'][$field['id']]) && (is_array($_POST['custom_field'][$field['id']]) || trim($_POST['custom_field'][$field['id']]) != '') ? $_POST['custom_field'][$field['id']] : '';
 
+ // JTR: preparsecode() corrupts the array by converting it to a string.
+ if (isset($_POST['custom_field'][$field['id']]) && !is_array($_POST['custom_field'][$field['id']]))
- preparsecode($value);
+ preparsecode($value);
 
  // Do the value checks
  if ($field['type'] == 'checkbox')
  {
- foreach ($value as $val)
- if (!in_array($val, $field['options']))
- fatal_error(sprintf($txt['aeva_cf_invalid'], $field['name']));
-
  // Nothing set?
  if (empty($value) && $field['required'])
  fatal_error(sprintf($txt['aeva_cf_empty'], $field['name']));
  elseif (empty($value))
  continue;
 
+ foreach ($value as $val)
+ if (!in_array($val, $field['options']))
+ fatal_error(sprintf($txt['aeva_cf_invalid'], $field['name']));
+
  // Set the proper value
  $value = implode(', ', $value);
  }
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Nao

  • Dadman with a boy
  • Posts: 16,061
Re: Possible bug with custom fields
« Reply #1,  »
Is... that a fix, you posted below? Because your topic says 'possible bug', not 'bug with possible fix'... ;)
You could just as well post a PR..? Or maybe there's one... I must admit, I don't check the git page often.

(As a quick note: I believe the custom field feature for AeMe was written by Dragooon originally, so I'm probably not well versed in it.)