# Add input to a form

**URL:** <https://discourse.cakephp.org/t/add-input-to-a-form/4208>\
**Category:** Need Help\
**Created:** [April 23, 2018, 2:10pm UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208 "2018-04-23T14:10:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)\
**Post date:** [April 23, 2018, 2:10pm UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/1 "2018-04-23T14:10:26Z")

</div>

I had to add an input to this form

$sess = CakeSession::read(‘Auth’);

```
                    echo $this->Form->create('Exportaffiliate', ['class' => 'form-horizontal']);
                    echo $this->Form->input('id');
                    echo '<div class="col-lg-6">' . $this->Form->input('subject', ['label' => __('Offer Subject')]) . '</div><div class="col-lg-6"></div>';
                    echo '<div class="col-lg-12">' . $this->Form->input('description', ['label' => 'Description of your offer', 'rows' => 12]) . '</div>';
                    echo $this->Form->input('user_id', ['type' => 'hidden', 'value' => $sess['User']['id']]);

                    //t0m dev inserisce nel form il valore del gruppo d'appartenenza dell'utente che crea
                    echo $sess['User']['group_id'];
                    echo $this->Form->input('user_group_id', ['type' => 'hidden', 'value' => $sess['User']['group_id']]);

                    $opt = [
                              'label' => \__('Save').' &#8250;',
                              'class' => 'btn btn-primary',
                              'escape' => false
                          ];
                    echo '<div class="col-lg-6">' . $this->Form->end($opt) .'</div>';

```

Tried to add the line of my interest:  
`echo $this->Form->input('user_group_id', ['type' => 'hidden', 'value' => $sess['User']['group_id']]);`

But the value can’t be echoed then. I tried to echo like this but it echos nothing.  
`echo '<div class="col-lg-6">'.$this->Form->value('user_group_id').'</div>';`

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [April 23, 2018, 7:32pm UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/2 "2018-04-23T19:32:53Z")

</div>

Where did you get this from ?

> [@tom1884it](#):
>
> $sess[‘User’][‘group\_id’]

In cakephp 3.x you should have something like :  
$this-\>request-\>session()-\>read(‘Auth.User.group\_id’);

---

<div class="post-metadata">

**Author:** ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)\
**Post date:** [April 23, 2018, 8:12pm UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/3 "2018-04-23T20:12:30Z")

</div>

Thank you for your reply. Maybe I’m not on v3.x.  
Well, anyway, $sess[…] works elsewhere. I’ll try, but I think that this has something concerning with forms. For example, can I add an input on a form without creating a referred column on the that form’s db table??

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [April 23, 2018, 8:35pm UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/4 "2018-04-23T20:35:23Z")

</div>

No problem ! Of course you can.

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [April 23, 2018, 8:37pm UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/5 "2018-04-23T20:37:40Z")

</div>

What does :  
debug($sess) return ?

---

<div class="post-metadata">

**Author:** ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)\
**Post date:** [April 23, 2018, 9:00pm UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/6 "2018-04-23T21:00:09Z")

</div>

I don’t think I’m having nothing to debug ($sess): as you see, on the working code, there is already an input based on $sess, and it’s working.

Today I want to add an input on the form, but form won’t take it! Maybe also because db table is not ready to receive it?..

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [April 24, 2018, 7:09am UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/7 "2018-04-24T07:09:03Z")

</div>

Nothing to do with the table. You can add as many inputs you need.

---

<div class="post-metadata">

**Author:** ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)\
**Post date:** [April 24, 2018, 7:54am UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/8 "2018-04-24T07:54:45Z")

</div>

But how do the form “add” a new field on db’s table (based on my new $this-\>Form-\>input(‘xxx’)?  
And how do it setup that field type?

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [April 24, 2018, 8:01am UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/9 "2018-04-24T08:01:30Z")

</div>

The field is not added to the table.  
These fields are used for extra information or verification (search term, password confim …).  
They are not saved in the DB.

---

<div class="post-metadata">

**Author:** ![tom1884it](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tom1884it/32/1023_2.png) [@tom1884it](https://discourse.cakephp.org/u/tom1884it)\
**Post date:** [April 24, 2018, 8:04am UTC](https://discourse.cakephp.org/t/add-input-to-a-form/4208/10 "2018-04-24T08:04:05Z")

</div>

Well, actually I want to save that on db, as the most part of that form inputs.
