-
-
Save jakejackson1/c042b5c80b393a13b6eddd165d674258 to your computer and use it in GitHub Desktop.
Our completed Part 4 Hello World Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Hello World | |
* Version: 0.2 | |
* Description: A basic "Hello World" PDF template showing custom PDF templates in action | |
* Author: Jake Jackson | |
* Group: Sol System | |
* License: GPLv2 | |
* Required PDF Version: 4.0-beta | |
*/ | |
/* Prevent direct access to the template (always good to include this) */ | |
if ( ! class_exists( 'GFForms' ) ) { | |
return; | |
} | |
/** | |
* All Gravity PDF v4/v5/v6 templates have access to the following variables: | |
* | |
* @var array $form The current Gravity Form array | |
* @var array $entry The raw entry data | |
* @var array $form_data The processed entry data stored in an array | |
* @var object $settings The current PDF configuration | |
* @var array $fields An array of Gravity Form fields which can be accessed with their ID number | |
* @var array $config The initialised template config class – eg. /config/zadani.php | |
*/ | |
/* | |
* Load our template-specific settings | |
*/ | |
$show_meta_data = $settings['world_show_meta_data'] ?? 'No'; | |
/* | |
* Include your PHP variables in this section | |
*/ | |
$location = $form_data['field'][3] ?? ''; | |
$name = $form_data['field'][1]['first'] ?? ''; | |
?> | |
<!-- Any PDF CSS styles can be placed in the style tag below --> | |
<style> | |
h1 { | |
text-align: center; | |
text-transform: uppercase; | |
color: #a62828; | |
border-bottom: 1px solid #999; | |
} | |
</style> | |
<h1>Hello World</h1> | |
<p>You're from <?php echo esc_html( $location ); ?>, <?php echo esc_html( $name ); ?>? How cool is that!</p> | |
<?php if ( $location === 'Earth' ): ?> | |
<p>The birth-rate on Earth has dropped almost 25% in the past 50 years due to colonisation of the solar system.</p> | |
<?php endif; ?> | |
<?php if ( $location === 'Moon' ): ?> | |
<p>The lunar colony was first established in 2115 with a population of 200. Now it supports over 900,000 people.</p> | |
<?php endif; ?> | |
<?php if ( $location === 'Mars' ): ?> | |
<p>Mars was the second body to be colonised in the solar system in 2135, 20 years after the moon.</p> | |
<?php endif; ?> | |
<?php if ( $location === 'Titan' ): ?> | |
<p>Titan's colony is only recently established. You're one of only 500 people currently living there!</p> | |
<?php endif; ?> | |
<?php if ( $show_meta_data === 'Yes' ): ?> | |
<p> | |
<strong>User IP:</strong> <?php echo esc_html( $form_data['misc']['ip'] ); ?><br> | |
<strong>Submission Timestamp:</strong> <?php echo esc_html( $form_data['misc']['date_time'] ); ?><br> | |
<strong>User Agent:</strong> <?php echo esc_html( $form_data['misc']['user_agent'] ); ?><br> | |
<strong>Source URL:</strong> <?php echo esc_html( $form_data['misc']['source_url'] ); ?> | |
</p> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment