# Why do I get undefined index for this code whenever I click the delete button?

**URL:** <https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827>\
**Category:** Plugins\
**Created:** [June 8, 2023, 7:39pm UTC](https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827 "2023-06-08T19:39:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aljawaid](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/aljawaid/32/1090_2.png) [@aljawaid](https://kanboard.discourse.group/u/aljawaid)\
**Post date:** [June 8, 2023, 7:39pm UTC](https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827/1 "2023-06-08T19:39:29Z")

</div>

Why do I get undefined index for this code whenever I click the button?

```auto
[php7:notice] PHP Notice: Trying to access array offset on value of type null in /var/www/.../public_html/app/Helper/LayoutHelper.php on line 90
[php7:notice] PHP Notice: Undefined index: project in /var/www/.../public_html/app/Helper/LayoutHelper.php on line 91

```

I click this in a button:

```php
<a href="<?= $this->url->href('ContactsItemsController', 'confirm', array('item_id' => $item['id'], 'plugin' => 'AddressBook'), false, '', false) ?>" class="btn btn-ab-delete js-modal-medium" title="<?=t('Delete Property') ?>">
<i class="fa fa-trash-o" aria-hidden="true"></i> <?= t('Delete') ?>
</a>

```

I read that `isset` is a solution but if using `isset` is the solution, where do I place it? I can’t figure it out.

I tried:

```auto
<a href="<?= $this->url->href('ContactsItemsController', 'confirm', array('item_id' => isset($item['id']), 'plugin' => 'AddressBook'), false, '', false) ?>" class="btn btn-ab-delete js-modal-medium" title="<?=t('Delete Property') ?>">
<i class="fa fa-trash-o" aria-hidden="true"></i> <?= t('Delete') ?>
</a>

```

But that never worked. Also, it is suggesting `project` in the error, and there is no mention of `project` in the code. The function of the actual code works fine.

Line 90-91 that the error is referring to is the `elseif` part of the below function:

```php
public function project($template, array $params, $sidebar = 'project/sidebar')
    {
        if (empty($params['title'])) {
            $params['title'] = $params['project']['name'];
        } elseif ($params['project']['name'] !== $params['title']) {
            $params['title'] = $params['project']['name'].' &gt; '.$params['title'];
        }

        return $this->subLayout('project/layout', $sidebar, $template, $params);
    }

```

Any help will be appreciated. I created an issue for the upcoming plugin here:

> <https://github.com/aljawaid/AddressBook/issues/2>
>
> In Kanboard, why do I get undefined index for this code whenever I click the but…ton?
> 
> \`\`\`
> \[php7:notice\] PHP Notice: Trying to access array offset on value of type null in /var/www/.../public\_html/app/Helper/LayoutHelper.php on line 90
> \[php7:notice\] PHP Notice: Undefined index: project in /var/www/.../public\_html/app/Helper/LayoutHelper.php on line 91
> \`\`\`
> 
> I click this in a button:
> \`\`\`php
> \<a href="\<?= $this-\>url-\>href('ContactsItemsController', 'confirm', array('item\_id' =\> $item\['id'\], 'plugin' =\> 'AddressBook'), false, '', false) ?\>" class="btn btn-ab-delete js-modal-medium" title="\<?=t('Delete Property') ?\>"\>
> \<i class="fa fa-trash-o" aria-hidden="true"\>\</i\> \<?= t('Delete') ?\>
> \</a\>
> \`\`\`
> 
> I read that \`isset\` is a solution but if using \`isset\` is the solution, where do I place it? I can't figure it out.
> 
> I tried:
> \`\`\`php
> \<a href="\<?= $this-\>url-\>href('ContactsItemsController', 'confirm', array('item\_id' =\> isset($item\['id'\]), 'plugin' =\> 'AddressBook'), false, '', false) ?\>" class="btn btn-ab-delete js-modal-medium" title="\<?=t('Delete Property') ?\>"\>
> \<i class="fa fa-trash-o" aria-hidden="true"\>\</i\> \<?= t('Delete') ?\>
> \</a\>
> \`\`\`
> 
> But that never worked. Also, it is suggesting \`project\` in the error, and there is no mention of \`project\` in the code. The function of the actual code works fine.
> 
> Line 90-91 that the error is referring to is the \`elseif\` part of the below function:
> 
> \`\`\`php
> public function project($template, array $params, $sidebar = 'project/sidebar')
> {
> if (empty($params\['title'\])) {
> $params\['title'\] = $params\['project'\]\['name'\];
> } elseif ($params\['project'\]\['name'\] !== $params\['title'\]) {
> $params\['title'\] = $params\['project'\]\['name'\].' &gt; '.$params\['title'\];
> }
> 
> return $this-\>subLayout('project/layout', $sidebar, $template, $params);
> }
> \`\`\`

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [June 8, 2023, 10:03pm UTC](https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827/2 "2023-06-08T22:03:03Z")

</div>

Your issue arrises with what you are sending as the `param` var to the helper.

> <https://github.com/aljawaid/AddressBook/blob/63929c9aff2dd75bb076fa6815467d6a7e850ad6/Controller/ContactsItemsController.php#L104>

Your array contains no refernce to `project`

---

<div class="post-metadata">

**Author:** ![aljawaid](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/aljawaid/32/1090_2.png) [@aljawaid](https://kanboard.discourse.group/u/aljawaid)\
**Post date:** [June 8, 2023, 10:15pm UTC](https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827/3 "2023-06-08T22:15:45Z")

</div>

oh hello…

okay but thats because `project` is not needed?

oh… do you think the layout should be `config` instead of `project`? its only a modal

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [June 8, 2023, 10:18pm UTC](https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827/4 "2023-06-08T22:18:09Z")

</div>

Thats up to you, but whether its needed or not, if you use that helper function its a requirement.

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [June 8, 2023, 11:05pm UTC](https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827/5 "2023-06-08T23:05:27Z")

</div>

Going back to isset question.

You are not using it correctly, so thats why it doesnt ever work for you. Its a boolean. When you use it, you are asking a question, then its up to you to tell the code what to do if its true and its false. Just putting isset in front of the variable, all you are doing is sending a true or false, which is pointless.

Example:

Isset?

Yes, do this.

No, do something else.

---

<div class="post-metadata">

**Author:** ![aljawaid](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/aljawaid/32/1090_2.png) [@aljawaid](https://kanboard.discourse.group/u/aljawaid)\
**Post date:** [June 9, 2023, 7:48am UTC](https://kanboard.discourse.group/t/why-do-i-get-undefined-index-for-this-code-whenever-i-click-the-delete-button/2827/6 "2023-06-09T07:48:20Z")

</div>

thanks, I think the `project` to `config` in the layout fixed it
