Include extension form action to board logs?

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

Include extension form action to board logs?

Post by Kami-sama »

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
Kailey
Community Team Leader
Community Team Leader
Posts: 3732
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Include extension form action to board logs?

Post by Kailey »

Check out the log class. Example usage
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Include extension form action to board logs?

Post by david63 »

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!

I now no longer support any of my extensions but they will start to become available here
User avatar
Kami-sama
Registered User
Posts: 137
Joined: Sat May 26, 2018 3:07 pm

Re: Include extension form action to board logs?

Post by Kami-sama »

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: 137
Joined: Sat May 26, 2018 3:07 pm

Re: Include extension form action to board logs?

Post by Kami-sama »

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
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Include extension form action to board logs?

Post by david63 »

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!

I now no longer support any of my extensions but they will start to become available here
User avatar
Kami-sama
Registered User
Posts: 137
Joined: Sat May 26, 2018 3:07 pm

Re: Include extension form action to board logs?

Post by Kami-sama »

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”