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 8514537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:53:53+00:00 2026-06-11T04:53:53+00:00

I am really new in cakephp. I have two controllers named ‘questions’ and ‘answers’

  • 0

I am really new in cakephp. I have two controllers named ‘questions’ and ‘answers’. In answers view i have a admin_add.ctp file which includes a select box that show the list of questions. But the problem is when someone select the question then it will show all the answers in different input fields depending on the selected question_id though my admin_add.ctp contains a single input fields. So the fields have to be added when dynamically to the admin_add ctp when someone make a change. My answers table contains a field ‘question_id’ as foreign_key. Here is my admin_add.ctp file..

<?php echo $this->
    Html->script(array('answers_add','jquery-ui-1.8.18.custom.min'), array('inline'
    => false)); ?>
    <div class="answers form">
        <?php echo $this->
            Form->create('Answer');?>
            <fieldset>
                <legend>
                    <?php echo __( 'Admin Add Answer'); ?>
                </legend>
                <?php echo $this->
                    Form->input('question_id', array('empty'=>'Please select the question'));?>
                    <span class="labelToAnswerBox">
                        Add your answers
                    </span>
                    <ul id="allAnswerHolder">
                        <li class="eachAnswer">
                            <?php echo $this->
                                Form->input('answer', array('id' => false, 'class' => 'answerInput', 'name'
                                => 'data[Answer][answer][]','div' => false, 'label' => false, 'after' =>
                                '
                                <input type="button" value="X" class="removeAnswer">
                                ', 'before' => '
                                <span class="ui-icon ui-icon-arrowthick-2-n-s">
                                </span>
                                ')); ?>
                        </li>
                    </ul>
                    <span class="addAnswer">
                        Add
                    </span>
                    <?php echo $this->
                        Form->input('Status', array('type'=>'hidden', 'id'=>'status')); echo $this->Form->input('Status1',
                        array('type'=>'hidden', 'id'=>'status1')); ?>
            </fieldset>
            <?php echo $this->
                Form->end(__('Submit'));?>
    </div>
    <?php echo $this->
        element('left');?>  

Can anyone help me? Thanks in advance.

  • 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-11T04:53:55+00:00Added an answer on June 11, 2026 at 4:53 am

    Try like below:

    Write change() method for that select box with AJAX request:

    $('select#AnswerQuestionId').on('change', function() {
       var questionID = $(this).val();
       // send ajax
       $.ajax({
          url: 'admin/answers/add/' + questionID,
          method: 'get',
          dataType: 'json',
          success: function(response) {
              // for example
              // response = [{'Answer': {'id': 1, 'answer': 'ans 1'} }, {'Answer': {'id': 2, 'answer' : 2}}....];
              // now loop over the response
              var html = '';
              $.each(response, function(index, val) {
                  html + = '<div id="answer_'+ val.Answer.id +'">'+ val.Answer.answer +'</div>'
              });
              // append this html to target container
              $('#target_container').append(html);
          }
       });
    });
    

    In CakePHP side try like following:

    public function admin_add($id = null) {
        if( !empty($id) )
        {
            $this->Answer->recursive = -1;
            $answers = $this->Answer->find('all', 
                                            array(
                                             'fields' => array('Answer.answer', 'Answer.id'), // assume the answer contains in answer field in db
                                             'conditions' => array('Answer.question_id' => $id)
                                            )
                                          );
            echo json_encode( $answers );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really new to the programming but I am studying it. I have
I am really new with PHP and all I have to do is to
I am really new to Python and I have been looking for an example
I am new to CakePHP, and while I really enjoy the ease of being
Very new to web programming still and I don't really have a specific question
I'm trying to use Ajax in CakePHP, and not really getting anywhere! I have
I am really new at Java. I have been trying to allow text selection
I really new to Python and coding in general, but I have been making
im really new to flash, how do i go about creating a variable which
im really new to linq-to-SQL so this may sound like a really dumb question,

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.