Advertisement:

Author Topic: Undefined index: action error  (Read 528 times)

Offline Matthias

  • Semi-Newbie
  • *
  • Posts: 79
  • Gender: Male
Undefined index: action error
« on: May 16, 2019, 07:01:22 AM »
Used SMF Version 2.0.15

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

index.php
Code: [Select]
// 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
Code: [Select]
// 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:
Code: [Select]
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
Code: [Select]
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?

Offline SychO

  • Lead Customizer
  • Sophist Member
  • *
  • Posts: 1,240
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: Undefined index: action error
« Reply #1 on: May 16, 2019, 07:06:43 AM »
check if $_REQUEST['action'] is set before checking its value

Imazighen

Offline Matthias

  • Semi-Newbie
  • *
  • Posts: 79
  • Gender: Male
Re: Undefined index: action error
« Reply #2 on: May 16, 2019, 07:51:16 AM »
Do you have an example?

Offline SychO

  • Lead Customizer
  • Sophist Member
  • *
  • Posts: 1,240
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: Undefined index: action error
« Reply #3 on: May 16, 2019, 08:07:40 AM »
instead of directly checking if: $_REQUEST['action']=='something'
check that it is set first: isset($_REQUEST['action']) && $_REQUEST['action']=='something'

Imazighen

Offline Matthias

  • Semi-Newbie
  • *
  • Posts: 79
  • Gender: Male
Re: Undefined index: action error
« Reply #4 on: May 16, 2019, 09:23:55 AM »
I have tried this and get a white page
Code: [Select]
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?

Offline SychO

  • Lead Customizer
  • Sophist Member
  • *
  • Posts: 1,240
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: Undefined index: action error
« Reply #5 on: May 16, 2019, 09:32:44 AM »
conditions have to be between parenthesis: "if (conditions)" not "if conditions"

Imazighen

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,162
  • Gender: Male
    • Kindred-999 on GitHub
Re: Undefined index: action error
« Reply #6 on: May 16, 2019, 10:11:29 AM »
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.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Matthias

  • Semi-Newbie
  • *
  • Posts: 79
  • Gender: Male
Re: Undefined index: action error
« Reply #7 on: May 16, 2019, 10:21:24 AM »
Thats how it works
Code: [Select]
// 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();

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 70,993
    • StoryBB/StoryBB on GitHub
Re: Undefined index: action error
« Reply #8 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 ;)
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Matthias

  • Semi-Newbie
  • *
  • Posts: 79
  • Gender: Male
Re: Undefined index: action error
« Reply #9 on: May 16, 2019, 02:27:27 PM »
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.

Offline Matthias

  • Semi-Newbie
  • *
  • Posts: 79
  • Gender: Male
Re: Undefined index: action error
« Reply #10 on: May 16, 2019, 02:38:30 PM »
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
« Last Edit: May 16, 2019, 03:08:58 PM by Matthias »