MyBB Community Forums

Full Version: PHP in a Custom page with Mybb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi is there a way in which I can still use mybb header, footer and do all the stuff with PHP in a custom page.

I have considered to look at ZingaBurga's template conditionals but, I am not sure, wheather it will give all the functionality I was planning to do and as well I read some security issues using like that.

Also I would mention, is there a way apart from Page manager plugin.
There are no security issues using Template Conditionals afaik, but that plugin doesn't provide functionality you need (as the name says it provides conditionals functionality in templates).

If you don't want to use Page Manager (I recommend it though), read this tutorial http://community.mybb.com/thread-116225.html
Thanks for your suggestion bro, in fact I am already using the one you suggested on more than 10 pages.

But I am in a tricky situation where I want to do the following:
Suppose if want to take some inputs from form fields, do some action on that data with php and display the result on same page. Like the example here on SO
I don't think that's trickier than any other page made in Page Manager or with that tutorial. Just use the $mybb->input instead of $_POST (make $mybb global) and it should work.
Thanks for your research and help. I wouldn't prefer the Page Manager as I would like have the URL not to be with misc.php?<something> and so I am looking for the way I explained. Thanks a lot for your interest in help me again.
You can use this by appending the "$template" variable, which allows you to use PHP between certain HTML elements.

<?php
define("IN_MYBB", 1);
require_once "global.php";

add_breadcrumb("Test Page");

$template .= '
<html>
{$headerinclude}
	<head>
		<title>Test Page</title>
	</head>
	
	<body>
			{$header}
			
			// Other content goes here
			
	</body>
{$footer}
</html>';


$template=str_replace("\'", "'", addslashes($template));
eval("\$testpage=\"".$template."\";");
output_page($testpage);
?>
(2013-06-20, 03:21 PM)Jambuster Wrote: [ -> ]You can use this by appending the "$template" variable, which allows you to use PHP between certain HTML elements.

<?php
define("IN_MYBB", 1);
require_once "global.php";

add_breadcrumb("Test Page");

$template .= '
<html>
{$headerinclude}
	<head>
		<title>Test Page</title>
	</head>
	
	<body>
			{$header}
			
			// Other content goes here
			
	</body>
{$footer}
</html>';


$template=str_replace("\'", "'", addslashes($template));
eval("\$testpage=\"".$template."\";");
output_page($testpage);
?>

This is the error I was getting (I have already tried this):
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in testpage.php(49) : eval()'d code on line 29

Also to mention you, this is the example code code I am trying to do.
Theres only 27 lines of code, so you have whitespace below the closing PHP tag, remove the white space, save it and re-upload.
(2013-06-20, 04:39 PM)Jambuster Wrote: [ -> ]Theres only 27 lines of code, so you have whitespace below the closing PHP tag, remove the white space, save it and re-upload.

Bro, I have given a sample code which is similar to what I wanted to implement. Ok now will go with the code I have given, this is the code I am having in testpage_c.php

<?php
define('IN_MYBB', 1); // (1a)
require "./global.php"; // (1b)

add_breadcrumb("Test Custom page", "testpage_c.php"); // (2)

$template = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Untitled Document</title>
 </head>

<body>
 <form id="form1" name="form1" method="post" action="">
 <label>Please type in a message
 <input type="text" name="msg" id="msg" />
 </label>
 <label>and your name
 <input type="text" name="name" id="name" />
 </label>

 <p>
 <label>Submit
 <input type="submit" name="submit" id="submit" value="Submit" />
 </label>
 </p>
 </form>

 <?php
    $msg = $_POST["msg"];
    $name = $_POST["name"];
	if(!empty($msg)) 
	{
	$posts = "$msg - $name\n";
	echo $posts;
	}
 ?>

</body>';


$template = str_replace("\'", "'", addslashes($template));
eval("\$testpage=\"".$template."\";");
output_page($testpage);
?>

And now this is error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in testpage_c.php(45) : eval()'d code on line 26

Any thoughts on what went wrong here?
^ see post #4
Quote:Just use the $mybb->input instead of $_POST (make $mybb global) and it should work
Pages: 1 2