Create Special Question Type

Category: Community Surveys 9 months ago

I am trying to add my own question type see below ;

I manage to create a question type but it does not seem to display the name properly

When i click on it it also does not show the proper field

Is there a guide or wiki on this area , appreciate if someone can help me achieve this.

Thank you

Custom Special Field

Like it on Facebook, Tweet it or share this topic on other bookmarking websites.
  • Re: Create Special Question Type

    by » 9 months ago


    There is no easy way of adding a new field type. You need to modify multiple places.

    1. Name: add this in your language file to show correct name

    2. When you click on it, you need to handle the action. for this follow below steps.

    a. Add you question form in components/com_communitysurveys/layouts/YOURLAYOUTNAME/form/question folder. name the file as per the type of the question. You can copy existing question type file and modify it as needed. for example, if your question type is dept, add dept.php

    b. edit components/com_communitysurveys/helpers/constants.php and add type

    define("CS_SPECIAL_DEPT",          25);

    c. Edit components/com_communitysurveys/layouts/YOURLAYOUTNAME/form/question.php and add below into the types array

    CS_SPECIAL_DEPT => 'dept'

    d. Now, you need to add logic to save your field values as per the name of the fields in your dept.php files

    edit administrator/components/com_communitysurveys/models/question.php and add your logic in save function. see the switch ($question->question_type) block for special types questions.

    3. The next step is to show your new field type in the response form

    a. Edit components/com_communitysurveys/layouts/YOURLAYOUTNAME/response/question.php and add your question type into the array

    CS_SPECIAL_DEPT => 'dept'

    b. copy existing render file to your new render file in the folder components/com_communitysurveys/layouts/YOURLAYOUTNAME/response/question. You need to name it as dept.php as your question type in constants.php is dept. Modify the file as needed

    c. Now saving the user response. Edit components/com_communitysurveys/models/response.php and add your code for new question type.

    4. Now if you want to show new question type in your reports, you need to make similar modifications in LAYOUTNAME/reports/consolidated and LAYOUTNAME/results folders

    Hope this will help you.


    Follow me on twitter: https://twitter.com/corejoomla
    If you use our extensions, please post a rating and a review at the Joomla! Extensions Directory.
    CjFitCjForum | Polls | Answers | Quizzes | Quotes | Surveys | GPS Tools | CjBlog


  • Re: Create Special Question Type

    by » 9 months ago


    That is so awesome, thank you for taking the time to write that procedure for me and i had manage to create the dept :)


  • Re: Create Special Question Type

    by » 9 months ago


    Oh wait , my auto fill is not working

    I think i may not have done properly for this part,

    edit administrator/components/com_communitysurveys/models/question.php and add your logic in save function. see the switch ($question->question_type) block for special types questions.

    any idea what went wrong ?


  • Re: Create Special Question Type

    by » 9 months ago


    If you are changing the field names, you need to instruct the form to load them. See the save function in administrator/components/com_communitysurveys/controllers/questions.php to see how they are retrieved from request and sent to the above model.


    Follow me on twitter: https://twitter.com/corejoomla
    If you use our extensions, please post a rating and a review at the Joomla! Extensions Directory.
    CjFitCjForum | Polls | Answers | Quizzes | Quotes | Surveys | GPS Tools | CjBlog


  • Re: Create Special Question Type

    by » 9 months ago


    Ok thanks, i will try again


  • Re: Create Special Question Type

    by » 9 months ago


    You are right , i miss out the following

    $questionParams->autofill_dept               = $this->input->post->get('autofill_dept', 0, 'int');

    under  public function save($key = null, $urlVar = 'qid')

    Now when i load the survey it will autofill the value i want

    The next thing is since its autofill, can i simply hide this element ?

    If i can auto fill a textfill can i autofill a dropdown with a list of value from my database ?


  • Re: Create Special Question Type

    by » 9 months ago


    You can hide it using css. You have the full control on how you can fill the values. 

    administrator/components/com_communitysurveys/models/questionsbase.php 

    add your values to questions in getItems function. You can use jdatabase to get values.

    https://docs.joomla.org/Selecting_data_using_JDatabase

    They can be available on your form.


    Follow me on twitter: https://twitter.com/corejoomla
    If you use our extensions, please post a rating and a review at the Joomla! Extensions Directory.
    CjFitCjForum | Polls | Answers | Quizzes | Quotes | Surveys | GPS Tools | CjBlog


    Thank you said by: teojerah

  • Re: Create Special Question Type

    by » 9 months ago


    Creating Custom Field in Survey (Contributed By maverick)

    1.  Name: add this in your language file to show correct name (language\en-GB\en-GB.com_communitysurveys.ini)

    2.  When you click on it, you need to handle the action. for this follow below steps.

     a.  Add your question form in
      components/com_communitysurveys/layouts/default/form/question folder.
      name the file as per the type of the question.
      You can copy existing question type file and modify it as needed. for example, if your question type is dept, add dept.php

     b.  edit components/com_communitysurveys/helpers/constants.php
      and add type
      define("CS_SPECIAL_DEPT",          25);

     c.  Edit components/com_communitysurveys/layouts/default/form/question.php
      and add below into the types array
      CS_SPECIAL_DEPT => 'dept'
      Edit components/com_communitysurveys/layouts/default/form/questions.php
      Add this section
      <li class="dropdown-item">
       <a href="#" id="qntype-header" onclick="document.questionForm.qtype.value=<?php echo CS_SPECIAL_DEPT;?>;CjSurveyApi.submitAjaxForm(this, '#questionForm', 'question.add', 'onBeforeAddQuestion', 'onAfterAddQuestion'); return false;">
       <i class="fa fa-user"></i> <?php echo JText::_('COM_COMMUNITYSURVEYS_QUESTION_TYPE_DEPT');?>
       </a>
      </li>

     d.  Now, you need to add logic to save your field values as per the name of the fields in your dept.php files >>>
      edit administrator/components/com_communitysurveys/models/question.php
      and add your logic in save function. see the switch ($question->question_type) block for special types questions.

    3.  The next step is to show your new field type in the response form
     a.  Edit components/com_communitysurveys/layouts/default/response/question.php
      and add your question type into the array CS_SPECIAL_DEPT => 'dept'

     b.  copy existing render file to your new render file in the folder components/com_communitysurveys/layouts/default/response/question.
      You need to name it as dept.php as your question type in constants.php is dept.
      Modify the file as needed

     c.  Now saving the user response.
      Edit components/com_communitysurveys/models/response.php
      and add your code for new question type.

    4.  Now if you want to show new question type in your reports, you need to make similar modifications in LAYOUTNAME/reports/consolidated and LAYOUTNAME/results folders


  • Re: Create Special Question Type

    by » 8 months ago


    Hi coming back to this subject, in development of my site i noticed that after the upgrade i will lost all my customisation.

    Can you advice me what must i do to retain my customisation before i upgrade.

    Thank you this is very important


  • Re: Create Special Question Type

    by » 8 months ago


    Language: you can add override strings from backend overrides page instead of adding them into core files.

    Layouts: Use layout overrides feature.
    http://wiki.corejoomla.com/Overriding_CjForum_layouts


    Follow me on twitter: https://twitter.com/corejoomla
    If you use our extensions, please post a rating and a review at the Joomla! Extensions Directory.
    CjFitCjForum | Polls | Answers | Quizzes | Quotes | Surveys | GPS Tools | CjBlog


You do not have permissions to reply to this topic.

Powered by CjForum

Site Search

Trending Topics

Upload Track button not working
  • 9 replies
Hallo, I have a problem uploading new gps tracks. Clicking on the...

Latest questions
  • 1 reply
I am trying to recreate the very slim (just a header and topic...

Owner
  • 1 reply
I only have two questions per survey. Is it possible to place them...

GPS TOOLS v5.1.1 : IMPOSSIBLE TO CREATE TRACK
  • 1 reply
Hi Maverick, IMPORTANT ISSUE : After installing v5.1.1, it's...

Import Wordpress posts
  • 1 reply
Is there a migrator to do this? I have a site with nearly 600 posts...

Subscribe Newsletter