Custom Page with custom style

For support and discussion related to templates, themes, and imagesets in phpBB 3.0.
Anti-Spam Guide
conan_troutman
Registered User
Posts: 222
Joined: Mon Jul 19, 2010 11:06 am

Re: Custom Page with custom style

Post by conan_troutman »

as I said I am a comlete newbie to this... I have edited code to add mods but always folloed guids ths my first attemt at making something work that is not writtten for phpbb

if you got

http://www.p3l-clan.co.uk/fpcform.php

and click the submit button with out entering anything you will see my error message (minus the actuall error message from the script where

Code: Select all

("$resp->error");
showed as I cant get it to show just got error message so removed it all together

then if you dont fill in the form but do the captcha you will see an error message but not in my forum style

I want to combine the two so the forum style shows includes the error message from both scripts and if everything is success full it posts me a message

the script currently looks like

Code: Select all

<?php
require_once('recaptchalib.php');
  $privatekey = "private";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
	
    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);

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

    page_header('No Success');

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

    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();
	

  } else {
    // Your code here to handle a successful verification
  

if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "the_management@p3l-clan.co.uk";
    $email_subject = "Fair Play Clans";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = "";
    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
    $error_message .= 'The Clan Name you entered does not appear to be valid.<br />';
  }
  if(!eregi($string_exp,$last_name)) {
    $error_message .= 'The Contact Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'You did not tell us about your clan.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
  
  } else {
    // Your code here to handle a successful verification
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "Clan Name: ".clean_string($first_name)."\n";
    $email_message .= "Contact Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Website: ".clean_string($telephone)."\n";
    $email_message .= "About Your Clan: ".clean_string($comments)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

    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);

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

    page_header('Success');

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

    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();

}
}
?>
the error triggered HTML looks like

Code: Select all

<!-- INCLUDE overall_header.html -->
<script language="javascript" type="text/javascript">
function closeWindow() {
window.open('','_parent','');
window.close();
}
</script> 


<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div ALIGN=CENTER class="content">

 <A HREF="javascript:history.go(-1)">Go Back</A> try again.....</a>
	
  </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE breadcrumbs.html -->
<!-- INCLUDE overall_footer.html -->


what I want

is

Code: Select all

<!-- INCLUDE overall_header.html -->
<script language="javascript" type="text/javascript">
function closeWindow() {
window.open('','_parent','');
window.close();
}
</script> 
<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
   <div ALIGN=CENTER class="content">
      <p>




<?php "$resp->error" ?>

 <?php if(!eregi($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        $string_exp = "^[a-z .'-]+$";
      if(!eregi($string_exp,$first_name)) {
        $error_message .= 'The Clan Name you entered does not appear to be valid.<br />';
      }
      if(!eregi($string_exp,$last_name)) {
        $error_message .= 'The Contact Name you entered does not appear to be valid.<br />';
      }
      if(strlen($comments) < 2) {
        $error_message .= 'You did not tell us about your clan.<br />';
      }
      if(strlen($error_message) > 0) {
        died($error_message);
      }
  ?>




 <A HREF="javascript:history.go(-1)">Go Back</A> try again.....</a>
 </p>
   </div>
 <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE breadcrumbs.html -->
<!-- INCLUDE overall_footer.html -->


hope that explains my aim

sorry for being an idiot
Last edited by conan_troutman on Wed Feb 16, 2011 8:30 pm, edited 1 time in total.

conan_troutman
Registered User
Posts: 222
Joined: Mon Jul 19, 2010 11:06 am

Re: Custom Page with custom style

Post by conan_troutman »

right I think I am getting this... slowly

I now have the following as the code and on both sets of error I get the custom page with the go back message

now I just need to tie in the actual error to show... problem is... it is also showing the error now for when all fields and captcha are filled in correctly

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);

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

    page_header('No Success');

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

    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();
	
	
require_once('recaptchalib.php');
  $privatekey = "private";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
	die ("$resp->error");
	

  } else {
    // Your code here to handle a successful verification
  

if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "the_management@p3l-clan.co.uk";
    $email_subject = "Fair Play Clans";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = "";
    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";

  if(!eregi($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
    $error_message .= 'The Clan Name you entered does not appear to be valid.<br />';
  }
  if(!eregi($string_exp,$last_name)) {
    $error_message .= 'The Contact Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'You did not tell us about your clan.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
  
  } else {
    // Your code here to handle a successful verification
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "Clan Name: ".clean_string($first_name)."\n";
    $email_message .= "Contact Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Website: ".clean_string($telephone)."\n";
    $email_message .= "About Your Clan: ".clean_string($comments)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

    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);

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

    page_header('Success');

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

    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();

}
}
?>
Last edited by conan_troutman on Wed Feb 16, 2011 8:29 pm, edited 1 time in total.

conan_troutman
Registered User
Posts: 222
Joined: Mon Jul 19, 2010 11:06 am

Re: Custom Page with custom style

Post by conan_troutman »

I have it simplified now

send-email.php looks like this

Code: Select all

  <?php
  require_once('recaptchalib.php');
  $privatekey = "private ";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
	?><A HREF="javascript:history.go(-1)">Go Back</A> try again.....</a><?php
    die ("" ."( " . $resp->error . ")");
	 
  } else {
    // Your code here to handle a successful verification
  }
  ?>
  <?php
if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "fairplay@p3l-clan.co.uk";
    $email_subject = "Fair Play Application";
     
     
    function died($error) {
        // your error code can go here
		?><A HREF="javascript:history.go(-1)">Go Back</A> try again.....</a><?php
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = "";
    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
    $error_message .= 'Clan Name does not appear to be valid.<br />';
  }

  if(!eregi($string_exp,$last_name)) {
    $error_message .=  'Contact Name does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'Information is blank.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "Clan Name: ".clean_string($first_name)."\n";
    $email_message .= "Contact Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Website: ".clean_string($telephone)."\n";
    $email_message .= "Information: ".clean_string($comments)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>
 
<!-- include your own success html here -->
 <script language="javascript" type="text/javascript">
function closeWindow() {
window.open('','_parent','');
window.close();
}
</script>
Thank you for contacting us. We will be in touch with you very soon.<br>
 <a href="javascript:closeWindow();">you may now close this tab</a>
<?php
}
?>
my send-email.html

is

Code: Select all

<!-- INCLUDE overall_header.html -->

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div ALIGN=CENTER class="content">
      <p>
	      
 ERROR / SUCCESS MESSAGE HERE
	
  </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE breadcrumbs.html -->
<!-- INCLUDE overall_footer.html -->
I just cant figeure out how to show the succes and error message as indicated by ERROR / SUCCESS MESSAGE HERE in the html code

I can either get the success.html to work or the nosuccess.html to work but not both.

so maybe simplifying it to a single html and making that call the errors would be better, but I dont know how

also if I put the

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);

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

    page_header('Send Form');

    $template->set_filenames(array(
        'body' => 'send-email.html',
    ));

    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();
    ?>
at the top of the first page the script to send the email does not work

if I put it where I can place my own confirmation message the script works perfect but only the success message is in the sites template the other error messages are plain blank screens with text

conan_troutman
Registered User
Posts: 222
Joined: Mon Jul 19, 2010 11:06 am

Re: Custom Page with custom style

Post by conan_troutman »

I sorted this the solution was amazingly simply...

I created a new php file and called it x.php linked that to a html template called x.html

I switched on the option to use php in html under the admin section

and then used <!-- INCLUDEPHP y.php --> to link back to the php with all the coding and html included

this gave me exactly what I wanted, all pages looking like the belong on the website, and any that didn't I just linked them in the same way

here is the finished product

http://www.p3l-clan.co.uk/fpcform.php

thanks to for edging me in the right direction

Locked

Return to “[3.0.x] Styles Support & Discussion”