Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.4k views
in Q2A Core by
Hi - I'm new to Q2A, and am setting it up but need to set some strict user fields on the account page.

Aside from single/multi-line and linkedIURL text, I'd love to be able to add a drop-down menu as a user field option.

Does anybody have any advice on how to accomplish this?

Unfortunately, I'm primarly an Obj-C developer, so anything that's as light on PHP as possible would be awesome! :D

 

Cheers!
Q2A version: Mar 2013

2 Answers

0 votes
by
edited by

Although it is not drop-down, I show Core Hack for adding check-box.

qa-include/qa-app-users.php (L50) :
define('QA_FIELD_FLAGS_CHECKBOX', 4); // add Type definition
qa-include/qa-page-admin-userfields.php(L158) :
$typeoptions=array(
  0 => qa_lang_html('admin/field_single_line'),
  QA_FIELD_FLAGS_MULTI_LINE => qa_lang_html('admin/field_multi_line'),
  QA_FIELD_FLAGS_LINK_URL => qa_lang_html('admin/field_link_url'),
  QA_FIELD_FLAGS_CHECKBOX => qa_lang_html('addon/field_checkbox'),  // add type
);
qa-include/qa-page-user.php (L438) :
// replace [start]
/*
$qa_content['form_profile']['fields'][$userfield['title']]=array(
  'type' => $fieldsediting ? 'text' : 'static',
  'label' => qa_html($label),
  'tags' => 'NAME="field_'.$userfield['fieldid'].'"',
  'value' => $valuehtml,
  'error' => qa_html(@$errors[$userfield['fieldid']]),
  'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
);
*/
if ($userfield['flags'] & QA_FIELD_FLAGS_CHECKBOX) {
  if(qa_get_state()=='edit') {
    $qa_content['form_profile']['fields'][$userfield['title']]=array(
      'label' => $label,
      'tags' => 'NAME="field_'.$userfield['fieldid'].'"',
      'type' => 'checkbox',
      'value' => qa_html($value),
      'error' => qa_html(@$errors[$userfield['fieldid']]),
    );
  } else {
    $qa_content['form_profile']['fields'][$userfield['title']]=array(
      'label' => $label,
      'tags' => 'NAME="field_'.$userfield['fieldid'].'" DISABLED="disabled"',
      'type' => 'checkbox',
      'value' => qa_html($value),
      'error' => qa_html(@$errors[$userfield['fieldid']]),
    );
  }
} else {
  $qa_content['form_profile']['fields'][$userfield['title']]=array(
    'type' => $fieldsediting ? 'text' : 'static',
    'label' => $label,
    'tags' => 'NAME="field_'.$userfield['fieldid'].'"',
    'value' => $valuehtml,
    'error' => qa_html(@$errors[$userfield['fieldid']]),
    'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
  );
}
// replace [end]
qa-include/qa-page-account.php (L325) :
// replace [start]
/*
$qa_content['form_profile']['fields'][$userfield['title']]=array(
 'label' => qa_html($label),
  'tags' => 'NAME="field_'.$userfield['fieldid'].'"',
  'value' => qa_html($value),
  'error' => qa_html(@$errors[$userfield['fieldid']]),
  'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
);
*/
if ($userfield['flags'] & QA_FIELD_FLAGS_CHECKBOX) {
  $qa_content['form_profile']['fields'][$userfield['title']]=array(
    'label' => $label,
    'tags' => 'NAME="field_'.$userfield['fieldid'].'"',
    'type' => 'checkbox',
    'value' => qa_html($value),
    'error' => qa_html(@$errors[$userfield['fieldid']]),
  );
} else {
  $qa_content['form_profile']['fields'][$userfield['title']]=array(
    'label' => $label,
    'tags' => 'NAME="field_'.$userfield['fieldid'].'"',
    'value' => qa_html($value),
    'error' => qa_html(@$errors[$userfield['fieldid']]),
    'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
  );
}
// replace [end]
qa-lang/custom/qa-lang-addon.php
<?php
return array(
  'field_checkbox' => 'Check Box',
);
/*
Omit PHP closing tag to help avoid accidental output
*/

I don't make actually. if me, I will realize drop-down by lower method.

1. Input "title" + "selections(separeted by comma)" + "default" by connection with semicolon at Field Name.
2. explode at display processor.

I am pleased if it becomes someone's reference. 

by
Thanks for taking the time to share this code - The checkbox seems to be working.

However, I don't understand how you transform it into a drop-down as you seem to be suggesting in your 'lower method' section at the end of your answer?

Thanks
by
Hi Rory. Since I thought from before that I wanted also drop-down, I'm  challenging now. Give me time a little?
by
you rock Sama55. I am also looking forward to this
0 votes
by

I released "Extra Field" hacking. Try it.

New Hack: Extra Userfield

...