Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:21:54+00:00 2026-06-17T10:21:54+00:00

I am having problem displaying values set by select elements created by FormHelper .

  • 0

I am having problem displaying values set by select elements created by FormHelper. I have searched the internet but doesn’t seem to be able to find the answer. Here is the scene:

I have a questionnaire form that has many options. In the model I put those items into an array, say ($frequencyOptions) and when formhelper is used,

$this->Form->input('frequency',array("options"=> $frequencyOptions));

Currently, the option value is the array index, which looks like:

    <option value="">(choose one)</option>
    <option value="0">Rare</option>
    <option value="1">Frequent</option>
    <option value="2">Moderate</option>

Of course I know that if I set the key as well when constructing the $frequencyOptions variable like

$frequencyOptions = array("Rare" => "Rare", ...

I will be able to store the value in text.

However, since some of these options are very very long, I would prefer to save them in INT in the database.

Yet the challenge I have at this moment is how to display those fields in the “list” in the index page. When I use the form field to display in the view or edit action, it is okay because the select element will be used again. However, if I want to display it in plain text, how should I “translate” it?

One thing I can think of is to create these “conversion” methods in the Model, but I think calling model method in views is not a good practice in MVC.

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:21:55+00:00Added an answer on June 17, 2026 at 10:21 am

    I’d think adding a method to your Model would be the way to go. How about this:

    // In your Model class
    
    // Store the index-to-name map in the Model as well
    var $frequencyOptions = array(...);
    
    public function translateFrequency(&$data) {
        foreach ($data as &$record) {
            $index = $record['ModelName']['frequency'];
            $record['ModelName']['frequency'] = $this->frequencyOptions[$index];
        }
    }
    
    // In your Controller action:
    $data = $this->ModelName->find(...);
    $this->ModelName->translateFrequency($data);
    

    And then it should display the human-readable value when passed to the index page. If preferred, the above method could be changed so it works on $this->data inside the Model.

    Note: The method has to be changed if it should work for a single record data array as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem on displaying values that were from a textarea. I wanted
I'm having a problem displaying an image from an ObjectData Source created by function
I have a simple login page but i am having trouble displaying the logged
I'm having a problem displaying selected value with Html.DropDownListFor. I have a view that
Problem I'm having trouble with a regular expression. I have a set of strings.
I am having problem in displaying Tiff images in browser.I have my images stored
I'm having a problem displaying data from a function to text box within a
Im having a problem with removing non-utf8 characters from string, which are not displaying
I am having a very strange problem with pound signs displaying incorrectly (or not
hey there, Im having problems displaying my results in this program but the program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.