SOLVED: Where to add PHP of a form for it to work?

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
Kami-sama
Registered User
Posts: 75
Joined: Sat May 26, 2018 3:07 pm

SOLVED: Where to add PHP of a form for it to work?

Post by Kami-sama » Thu May 31, 2018 9:24 pm

Hello!

So I have a code (listed bellow). It is basically code form form and and php for the form results to be saved into a text file. I want to place form into overall header (in a separate div or maybe popup window).

My issue: where should I place the PHP part for it to work?

Placing it into "overall_header.html" does not work as the file needs to be *.php
What would be the correct place for such script?
Or is my path for file incorrect in such case?

Code: Select all

<html>
<head>

<?php

$fileWrite = '';    
$myFile = '/var/www/html/phpBB3/testFile.txt';
if(isset($_POST['fileWrite']) && !empty($_POST['fileWrite'])) {
$fileWrite = $_POST['fileWrite'].PHP_EOL;
}
if($fileWrite) {
$fh = fopen($myFile, 'a') or die("can't open file"); //Make sure you have permission
fwrite($fh, $fileWrite);
fclose($fh);
}

$fileWrite2 = '';    
$myFile = '/var/www/html/phpBB3/testFile2.txt';
if(isset($_POST['fileWrite2']) && !empty($_POST['fileWrite2'])) {
$fileWrite2 = $_POST['fileWrite2'].PHP_EOL;
}
if($fileWrite2) {
$fh = fopen($myFile, 'a') or die("can't open file"); //Make sure you have permission
fwrite($fh, $fileWrite2);
fclose($fh);
}

?>

</head>

<body>
	<form id="some" name="someName" method="post">
		<input type="number" id="some1" class="someClass" value="Lauma" name="fileWrite"/>
		<input type="number" id="some2" class="someClass" value="Kerlunius" name="fileWrite2"/>
		<input type="submit" value="submit" class="submitClass"/>
	</form>
</body>
</html>
Last edited by Mick on Fri Jun 01, 2018 8:34 am, edited 2 times in total.

User avatar
Lumpy Burgertushie
Registered User
Posts: 64566
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Where to add PHP of a form for it to work?

Post by Lumpy Burgertushie » Thu May 31, 2018 9:35 pm

you put the php code in a php file. form.php ( or whatever you want ) like this:

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('home');



$fileWrite = '';    
$myFile = '/var/www/html/phpBB3/testFile.txt';
if(isset($_POST['fileWrite']) && !empty($_POST['fileWrite'])) {
$fileWrite = $_POST['fileWrite'].PHP_EOL;
}
if($fileWrite) {
$fh = fopen($myFile, 'a') or die("can't open file"); //Make sure you have permission
fwrite($fh, $fileWrite);
fclose($fh);
}

$fileWrite2 = '';    
$myFile = '/var/www/html/phpBB3/testFile2.txt';
if(isset($_POST['fileWrite2']) && !empty($_POST['fileWrite2'])) {
$fileWrite2 = $_POST['fileWrite2'].PHP_EOL;
}
if($fileWrite2) {
$fh = fopen($myFile, 'a') or die("can't open file"); //Make sure you have permission
fwrite($fh, $fileWrite2);
fclose($fh);
}

// Output page
page_header($page_title, true);

$template->set_filenames(array(
	'body' => 'form.html')
);

page_footer();


then you put that file in the board root where all the other php files are.
then, you create a html file for the actual form html, like this:

Code: Select all

<form id="some" name="someName" method="post">
<input type="number" id="some1" class="someClass" value="Lauma" name="fileWrite"/>
<input type="number" id="some2" class="someClass" value="Kerlunius" name="fileWrite2"/>
<input type="submit" value="submit" class="submitClass"/>
</form>
just that code, nothing else for now.

save it as form.html



then you put that in the styles/yourstyle/template folder with all the other html files.

then you create a link to the form.php file somewhere in the overall_header.html file so that you can click on it to load the form.


robert
Last edited by Lumpy Burgertushie on Thu May 31, 2018 9:44 pm, edited 1 time in total.
I am available for custom work on a donation basis. Please send me a PM with your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

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

Re: Where to add PHP of a form for it to work?

Post by Kami-sama » Thu May 31, 2018 9:42 pm

Lumpy Burgertushie wrote:
Thu May 31, 2018 9:35 pm
you put the php code in a php file. form.php ( or whatever you want ) like this:




then you put that file in the board root where all the other php files are.
then, you create a html file for the actual form html, like this:

Code: Select all

<form id="some" name="someName" method="post">
<input type="number" id="some1" class="someClass" value="Lauma" name="fileWrite"/>
<input type="number" id="some2" class="someClass" value="Kerlunius" name="fileWrite2"/>
<input type="submit" value="submit" class="submitClass"/>
</form>
just that code, nothing else for now.

save it as form.html



then you put that in the styles/yourstyle/template folder with all the other html files.

then you create a link to the form.php file somewhere in the overall_header.html file so that you can click on it to load the form.


robert
Oh! Okey, this makes sense.

Now in the template file, would I call form.php or form.html? Or both?
How do you call them? Like: <!-- INCLUDE form.html --> ?


EDIT:
Okey. I think I almost got this.
I added to my form action="form.php"
The only problem is, that the form.php is actually loaded (it did add up values correctly)
ANy way to stay on the same page? I guess I need a return in the php itself maybe?
Last edited by Kami-sama on Thu May 31, 2018 9:49 pm, edited 1 time in total.

User avatar
Lumpy Burgertushie
Registered User
Posts: 64566
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Where to add PHP of a form for it to work?

Post by Lumpy Burgertushie » Thu May 31, 2018 9:47 pm

you don't call it at all.
also, be aware that I edited the post above to add your php code into the new form.php file.

you do what I said. you create the two files.
you put a link to form.php in your overall_header.html file in the header or maybe in the navbar_header.html file with the rest of the menu links.

then, when you want the form to pop up, you click on the link to the form.php file.

all of this is assuming that your php code will work when you fill in the form.



robert
I am available for custom work on a donation basis. Please send me a PM with your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

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

Re: Where to add PHP of a form for it to work?

Post by Kami-sama » Thu May 31, 2018 9:52 pm

Lumpy Burgertushie wrote:
Thu May 31, 2018 9:47 pm
you don't call it at all.
also, be aware that I edited the post above to add your php code into the new form.php file.

you do what I said. you create the two files.
you put a link to form.php in your overall_header.html file in the header or maybe in the navbar_header.html file with the rest of the menu links.

then, when you want the form to pop up, you click on the link to the form.php file.

all of this is assuming that your php code will work when you fill in the form.



robert
Thank you! I also edited my previous post :D

Basically, my php does not include calling the form itself.
The form calls the php. That is the flow.

What I did, I just included <!-- INCLUDE form.html --> to overall header
Then I added action to my form.
After submitting all values are sent correctly, but I am left on php page
Is there a way to auto return? Or just send the data without actually opening the php file?

EDIT:
Okey, solved with header("location:index.php");

Everything works great now :)
Even tho I did not understand why you wanted to call php file instead of html :DD
This can be marked as solved.

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: Mathieu M. and 11 guests