News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Adding A New Function?

Started by zoolman, February 21, 2011, 05:08:51 AM

Previous topic - Next topic

zoolman

I have now put the code above the posts so it is outside of the moderation form. This will be version 1. I'll then look into it on a per post basis. I might as well learn to walk before I can run ;)

The code is really the same as previously mentioned. Now when I click on submit it does attempt to do something because it returns to the forum index. This is at least a step in the right driection as it did nothing before. However, I don't think my function is getting called. I put a javascript alert box in there to check and it never shows up. What am I still doing wrong?

Arantor

If it's falling through to the forum index that would imply it's never loading the function approvalsubmit, which makes me wonder if it's set up right in index.php (though your code looked right)

What happens in that function? Does it go anywhere else, or try and redirect anywhere?

zoolman

No it doesn't redirect anywhere although eventually I intend to redirect back to the topic. I have actually stripped out the function code until I can check that it is being called. One step at a time ;) It's not getting called and I can't see why now.

zoolman

Can anyone help with this? I just can't get the function to be called.

I've added the action to the actionArray, put this action into my form but when I click the submit button it just returns to the home forum index. The function isn't being called because for testing I've put a javascript alert box right at the top of the function.

Arantor

QuoteThe function isn't being called because for testing I've put a javascript alert box right at the top of the function.

That's not a guarantee, actually. Source functions are actually pushed through output buffers, and invariably won't actually output anything.

And you've definitely made sure the form/link URL points to $scripturl followed by ?action=thenewaction and that's spelt the same in index.php? (Just trying to cover all the bases; had people in the past type it out here and be correct but the original was typo'd)

zoolman

Yes checked for typos etc.

If the javascript alert isn't guaranteed to work, what would be the best to see if the function is being called or not?

Arantor

Personally, I tend to use trigger_error() in the function and verify that it's going into the log.

Thing is, if it's going back to the board index, that implies it's never being called anyway because boardindex is a fallback action, and specifically it's the *last* fallback action, through after 'are guests not allowed', 'is there a topic', 'is there a specific board', and 'does the theme do anything really specific with wrapped actions'.

zoolman

Right well I'll check everything again. I'm just going round in circles a little bit now. I've gone through the examples of adding a custom action and everything seems fine. One more check I guess ;)

zoolman

I'm at a loss  now. I've double checked everything. The action in the actionArray is fine. I've put a trigger_error function at the top of my function. It never gets added to the logs so the function isn't being called.

Any ideas at all?

Arantor


zoolman


Arantor

Hmm, now I'm really confused.

OK, one idea that occurred to me. Create a function in your file, called template_main(), whose sole purpose is to echo 'Hello world'. Then in your action handler, global $context, and set $context['sub_template'] = 'main'

zoolman

Did that but no difference though.

Arantor

OK, really daft question time, the modified files (especially index.php) are definitely being modified with the changes? Just I've seen cases where people have been convinced they've made changes, and they haven't been saved to the server, or they're looking at files on their PC but haven't uploaded them to the server.

Since right now there is no way that it should be failing with the edits you've described.

zoolman

Definitely. I am only running this on my local server and editing the files directly. I still double checked for my own sanity.

zoolman

#35
I'm starting to wonder if it is SimplePortal that is messing things up. I have just noticed that it isn't going back to the forum index page. My mistake there. It goes to home (which is the portal) but with no content in it (just the headers and footers).

I've noticed that the forum is on index.php?action=forum

I wonder if this is messing it up. Or am I just coming up with silly ideas in desperation? I'm going to remove SimplePortal anyway just to check.


Update:
Uninstalling SimplePortal made no difference. The only difference is it now returns to the forum home page whereas with SimplePortal installed it was going to that blank page I mentioned.

Arantor

No, it's not silly at all, I'd already checked what edits SP makes for myself and concluded that it shouldn't have the effect of thoroughly breaking it.

It still looks for all the world as though the action isn't defined for some reason.

zoolman

It is just a case of adding it to the actionArray though isn't it? in index.php (the root one)

Arantor

Yes, you add it to that, and that dictates what file to load and what function to run.

zoolman

In desperation I cleared the cache. Now when I click submit I get a HTTP 500 Internal Server Error - The webpage could not be displayed

Does this mean my function is now being called and it is something to do with the template_main stuff you got me to add?

Advertisement: