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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:39:32+00:00 2026-05-25T17:39:32+00:00

I have two forms, one to edit room details and the other to edit

  • 0

I have two forms, one to edit room details and the other to edit Extras. Within the forms I pull in a file upload and pass in the id. For some reason one requires a url and the id does not get passed in. Both have the same code. Can see why they are differnt.

Room form

            <div class="boxgrid grid_8">
            <?php echo $this->element('attachments',array('control'=>'upgrades','id'=>$this->data['AddOn']['id'],'att'=>$this->data['Attachment'])); ?>
            </div>

Room upload

Form->create(‘Room’, array(‘type’ => ‘file’));?>

    <legend><?php __('Upload Room Images'); ?></legend>
<?php
    echo $this->Form->input('id');
?>
<input type="hidden" name="data[Attachment][0][model]" value="Room" id="Attachment0Model" />
<input type="hidden" name="data[Attachment][0][group]" value="attachment" id="Attachment0Group" />
<div class="input file required"><input type="file" name="data[Attachment][0][file]" class="" id="Attachment0File" /></div>


<div class="submit"><button>Upload</button></div>
<div>Upload files</div>

Extras Form

            <div class="boxgrid grid_8">
            <?php echo $this->element('attachments',array('control'=>'upgrades','id'=>$this->data['AddOn']['id'],'att'=>$this->data['Attachment'])); ?>
            </div>

Extras Upload

Form->create(‘Upgrade’, array(‘type’ => ‘file’,’url’=>’/admin/upgrades/addfiles’,’id’=>’AddOnAdminAddfilesForm’));?>

    <legend><?php __('Upload Addon Images'); ?></legend>
<?php
    echo $this->Form->input('id');
?>
<input type="hidden" name="data[Attachment][0][model]" value="AddOn" id="Attachment0Model" />
<input type="hidden" name="data[Attachment][0][group]" value="attachment" id="Attachment0Group" />
<div class="input file required"><input type="file" name="data[Attachment][0][file]" class="" id="Attachment0File" /></div>


<div class="submit"><button>Upload</button></div>
<div>Upload files</div>

Javascript on each form:

<script type="text/javascript">
  $(document).ready(function() {

    $("div#uploader").resloader();
    $("div#uploader").load('<?=BASE_URL?>/admin/upgrades/addfiles/<?=$this->data['AddOn']['id']?>',null,function(){}).fadeIn();

Upgrades Contoller

            function admin_addfiles($id = null) {
            $this->layout = null;

                if (!$id && empty($this->data)) {
                    $this->Session->setFlash(__('Invalid Add On', true));
                    $this->redirect(array('controller' => 'upgrades',  'action' => 'index'));
                }

                if (!empty($this->data)) {
                    $this->layout = null;
                    //if(empty($this->data['AddOn']['id'])){unset($this->data['AddOn']);}

                    // restructure data for uploader plugin // NEED TO GET RID OF THIS ? MOVE IT
                    $tmp_file = $this->data['Attachment'][0]['file'];
                    $tmp_file['extension'] =  array_reverse(explode('.', $tmp_file['name']));
                    $tmp_file['extension'] = $tmp_file['extension'][0];
                    $tmp_file['title'] = strtolower(substr($tmp_file['name'],0,(0-strlen('.'.$tmp_file['extension']))));
                    $this->data['Attachment'][0]['alternative'] = ucwords(str_replace('_',' ', $tmp_file['title']));

                    if ($this->AddOn->saveAll($this->data, array('validate' => 'first'))) { 

                        $id = $this->AddOn->Attachment->getLastInsertID();
                        $att = $this->AddOn->Attachment->query("SELECT * from attachments WHERE id = ".$id);
                        $this->set('attachment',$att[0]['attachments']);

                    } else {
                        $tmp_file['name'] = 'INVALID FILE TYPE';
                    }


                    //debug($this->data);
                    $this->set('file', $tmp_file);
                    $this->RequestHandler->renderAs($this, 'ajax');
                    $this->render('../elements/ajax');

                }

                if (empty($this->data)) {
                    $this->data = $this->AddOn->read(null, $id);
                }

            }

        }
  • 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-05-25T17:39:32+00:00Added an answer on May 25, 2026 at 5:39 pm

    Your problem is with the $this->data. Check how it is filled in your controller.

    Both views are NOT the same, the main difference is in the create form.

    Form->create(‘Room’, array(‘type’ => ‘file’));?>

    Form->create(‘Upgrade’, array(‘type’ => ‘file’,’url’=>’/admin/upgrades/addfiles’,’id’=>’AddOnAdminAddfilesForm’));?>

    As you can see, one has the first parameter ‘Room’ and the other one is ‘Upgrade’, this IS important since you call the id like this

    echo $this->Form->input(‘id’);

    Cake expects that for the first case you have something like, $this->data[‘Room’][‘id’] and the second one $this->data[‘Upgrade’][‘id’]

    If you pass from the controller your id variable like this

    $this->set('id',$id);
    

    then in the view you can do somthing like this

    <?php
        echo $this->Form->input('id', array('value'=>$id, 'type'=>'hidden'));
    ?>
    

    Hope this solves your answer, if not, please post the $this->data value of each and the part of the controller where you assign $this->data

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

Sidebar

Related Questions

I (currently) have two forms, one that needs to call the other. In other
I have two forms on one page and want to have the input boxes
I have two Forms. One with where all the main code is being executed.
I have two forms, one with a radio button that users must select to
I have two forms. First one is to decide button numbers by using jslider.
I have two forms, and so two different submit buttons, for one page (page
How can two forms share the same inputs? I have two forms, one for
I have encountered a problem in my application. I have two forms, one that
I have created two forms in my Windows Application. One Form acts as a
I'm using the jQuery Validation JS I have two contact forms, the main 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.