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

  • SEARCH
  • Home
  • 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 9128193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:27:29+00:00 2026-06-17T07:27:29+00:00

In one of my forms I have a text input for a posts tags.

  • 0

In one of my forms I have a text input for a posts tags. At the moment, Cake is returning the tag id into this field rather than the name of the tag. I want to change it to show the name of the tag.

The posts controller is getting a result like this:

array(
    'Post' => array(
        'id' => '7',
        'title' => 'Testing again',
        'body' => 'wooooooo',
        'created' => '2013-01-09 19:20:53',
        'slug' => 'testing-again'
    ),
    'Tag' => array(
        (int) 0 => array(
            'id' => '4',
            'name' => 'tag1'
        ),
        (int) 1 => array(
            'id' => '3',
            'name' => 'tag2'
        ),
        (int) 2 => array(
            'id' => '5',
            'name' => 'tag3'
        )
    )
)

and the form is laid out like this:

<?php echo $this->Form->create('Post'); ?>
<?php echo $this->Form->input('Post.title'); ?>
<?php echo $this->Form->input('Post.body'); ?>
<?php echo $this->Form->input('Tag.Tag', array('type' => 'text', 'label' => 'Tags (seperated by space)')); ?>
<?php echo $this->Form->input('Post.slug'); ?>
<?php echo $this->Form->end('Save Changes'); ?>

Is there a way I can tell CakePHP to output the name field of the tags instead of id? Thanks.

  • 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-17T07:27:31+00:00Added an answer on June 17, 2026 at 7:27 am

    OK, so from what I’ve gathered from our comment discussion, this would be what you’re looking for. In your controller, just loop over all the set tags for the post. Assuming your find result is set in the $post variable, you can use the below code and save them all in a “plain” non-recursive array:

    $tags = array(); // This will hold all the tags
    foreach($post['Tag'] as $tag) {
        $tags[] = $tag['name'];
    }
    
    // Set the tags as view variable
    $this->set(compact('tags'));
    

    Then in your view you can just implode the array with a space and set it as value for your text field:

    echo $this->Form->input('Tag.Tag', array('type' => 'text', 'label' => 'Tags (seperated by space)', 'value' => implode(' ', $tags)));
    

    The find example in your OP would then return a value of tag1 tag2 tag3.

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

Sidebar

Related Questions

I have three input text boxes in my form. First one is teacher, second
I have a form in a PHP script and one text field. However when
I have two forms on one page and want to have the input boxes
I have a HTML Form contains input text fields and select tags.In jQuery I
I have an asp.net MVC app. One of the forms posts json data to
I have 2 forms within the same template. One adds Country tags to a
I thought I had this one sorted but I have run into a snag.
I have an ASP.NET form with three text inputs, one each for Work Phone,
I have one form with several text fields and one button. When i enter
I have a form with two text boxes, one select drop down and one

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.