Include extension form action to board logs?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Include extension form action to board logs?

Post by Kami-sama » Thu Jul 19, 2018 2:47 pm

Hey guys!

So if my extension is a form. User adds values to form fields and with SUBMIT these values are saved in a TXT file on server side. Is it possible to include such action in board logs? Showing form field name, value and user name who submitted.

Any suggestions are welcome!

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1944
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Include extension form action to board logs?

Post by kinerity » Thu Jul 19, 2018 3:08 pm

Check out the log class. Example usage
Kailey Truscott - Community Team

User avatar
david63
Jr. Extension Validator
Posts: 14931
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Include extension form action to board logs?

Post by david63 » Thu Jul 19, 2018 3:10 pm

You can write anything you want to the phpBB log table - take a look at any of my extensions as virtually all of them write to the log file - certainly the ones with an ACP configuration.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Include extension form action to board logs?

Post by Kami-sama » Thu Jul 19, 2018 7:44 pm

david63 wrote:
Thu Jul 19, 2018 3:10 pm
You can write anything you want to the phpBB log table - take a look at any of my extensions as virtually all of them write to the log file - certainly the ones with an ACP configuration.
Well, in my case there are no ACP configurations. Form is displayed in overall header.
And form action calls PHP file where calculations are done and saved.

Looking at examples I am not sure where to place the log generating line.
I've seen people adding it to class ext extends base
((my main php is located in same place as other peoples ext.php, that's why I'm taking it as example))

My PHP looks something like this

Code: Select all

<?php
    
	$path = dirname(__FILE__) . '/files';

        $pLauma = '';
    	$myFile = $path . '/pLauma.txt';
    	if (isset($_POST['pLauma']) && !empty($_POST['pLauma'])) {
			$pLauma = $_POST['pLauma'].PHP_EOL;
		}
		if ($pLauma) {
			$fh = fopen($myFile, 'a') or die("can't open file"); //Make sure you have permission
			fwrite($fh, $pLauma);
			fclose($fh);
        	
        		$lines = file($path . '/pLauma.txt');
			$array = array_sum($lines);
			file_put_contents($path . '/rLauma.txt', $array);
        }


	header("location:../../../index.php");

Not sure how to include the line when it is like this. (without functions and etc)
I would like to include the log inside the IF

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Include extension form action to board logs?

Post by Kami-sama » Thu Jul 19, 2018 8:13 pm

kinerity wrote:
Thu Jul 19, 2018 3:08 pm
Check out the log class. Example usage
Thank you for the examples. Maybe you know why in them they are using case:?
What is that? I supposed I could use it without such clause?

User avatar
david63
Jr. Extension Validator
Posts: 14931
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Include extension form action to board logs?

Post by david63 » Thu Jul 19, 2018 9:18 pm

Kami-sama wrote:
Thu Jul 19, 2018 8:13 pm
Maybe you know why in them they are using case:?
Can I suggest that you review your PHP programming knowledge.

In order to use the log class you will need to inject it into your extension.
Kami-sama wrote:
Thu Jul 19, 2018 7:44 pm
I've seen people adding it to class ext extends base
I havn't and I cannot see many, if any, reasons why an extension would add a log entry in the ext.php file.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Include extension form action to board logs?

Post by Kami-sama » Thu Jul 19, 2018 9:58 pm

david63 wrote:
Thu Jul 19, 2018 9:18 pm
Kami-sama wrote:
Thu Jul 19, 2018 8:13 pm
Maybe you know why in them they are using case:?
Can I suggest that you review your PHP programming knowledge.

In order to use the log class you will need to inject it into your extension.
Kami-sama wrote:
Thu Jul 19, 2018 7:44 pm
I've seen people adding it to class ext extends base
I havn't and I cannot see many, if any, reasons why an extension would add a log entry in the ext.php file.
Haha, my PHP knowledge is rather non existent :D First time dealing with it actually.

But I think I do understand what you mean.
Will just have to work out how to call it with my setup.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 67 guests