News:

Wondering if this will always be free?  See why free is better.

Main Menu

Undefined index: action error

Started by Matthias, May 16, 2019, 07:01:22 AM

Previous topic - Next topic

Matthias

Used SMF Version 2.0.15

I have added a custom action "welcome" an set it as homepage.

index.php

// Action and board are both empty... BoardIndex!
if (empty($board) && empty($topic))
{
require_once($sourcedir . '/Welcome.php');
return 'WelcomeMain';
}


For the linktree I did the following:
Sources/Load.php

// Start the linktree off empty..
if (!empty($board) OR !empty($topic) OR $_REQUEST['action'] == 'forum' OR $_REQUEST['action'] == 'collapse' OR $_REQUEST['action'] == 'unread' OR $_REQUEST['action'] == 'recent')
$context['linktree'] = array(array('url' => $scripturl . '?action=forum', 'name' => isset($txt['forum_name']) ? $txt['forum_name'] : 'Community'));
else
$context['linktree'] = array();


Everything works as it should, but when I call the homepage (domain.tld or domain.tld/index.php) I get the following error message:

https://www.domain.tld/index.php?https://www.domain.tld/
8: Undefined index: action
File: /var/www/vhosts/domain.tld/httpdocs/Sources/Load.php
Line: 607


Line 607 is that, what I have changed

if (!empty($board) OR !empty($topic) OR $_REQUEST['action'] == 'forum' OR $_REQUEST['action'] == 'collapse' OR $_REQUEST['action'] == 'unread' OR $_REQUEST['action'] == 'recent')


I think the error comes up, because at domain.tld or domain.tld/index.php there is nothing attached, e.g.
domain.tld/index.php?board=1.0
domain.tld/index.php?action=something

Does anyone have any idea how to fix the error?
Quality first

SychO

check if $_REQUEST['action'] is set before checking its value
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

Matthias

Quality first

SychO

instead of directly checking if: $_REQUEST['action']=='something'
check that it is set first: isset($_REQUEST['action']) && $_REQUEST['action']=='something'
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

Matthias

I have tried this and get a white page

if isset($_REQUEST['action']) && ($_REQUEST['action'] == 'forum' OR $_REQUEST['action'] == 'collapse' OR $_REQUEST['action'] == 'unread' OR $_REQUEST['action'] == 'recent')
$context['linktree'] = array(array('url' => $scripturl . '?action=forum', 'name' => isset($txt['forum_name']) ? $txt['forum_name'] : 'Community'));
else
$context['linktree'] = array();


What could be wrong?
Quality first

SychO

conditions have to be between parenthesis: "if (conditions)" not "if conditions"
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

Kindred

incidentally, with that logic, the welcome page will NOT show on index.php (with no argument)

if that is your intention, then OK...   but, from your description, it seemed like you want it to show on the base index page as well as recent and unread.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Matthias

Thats how it works

// Start the linktree off empty..
if ((!empty($board) OR !empty($topic) OR (isset($_REQUEST['action']) && $_REQUEST['action'] == 'forum' OR $_REQUEST['action'] == 'collapse' OR $_REQUEST['action'] == 'unread' OR $_REQUEST['action'] == 'recent')))
$context['linktree'] = array(array('url' => $scripturl . '?action=forum', 'name' => isset($txt['forum_name']) ? $txt['forum_name'] : 'Community'));
else
$context['linktree'] = array();
Quality first

Arantor

I'd have just installed a portal to do this for me, personally, I don't feel the need to write *everything* from scratch ;)

Matthias

Quote from: Kindred on May 16, 2019, 10:11:29 AM
incidentally, with that logic, the welcome page will NOT show on index.php (with no argument)

What do you mean exactly?
When I call domain.tld or domain.tld/index.php there are shown the action=welcome page.
Quality first

Matthias

#10
Quote from: Arantor on May 16, 2019, 10:25:19 AM
I'd have just installed a portal to do this for me, personally, I don't feel the need to write *everything* from scratch ;)

Ok, but I'm comming up from YaBBSE with my active Sites.
They are still running SMF 1.1.21. It was easier then to use custom actions. Now I'm going to adjust that for 2.0.x
Quality first

Advertisement: