Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: KKJ
- */
- ?>
- <?php
- $formTitleField = 'Formulir-KKJ'; // change this as needed
- $formTitleField = 'form_title'; // change this as needed
- if (is_array($_POST) && !empty($_POST)) {
- $title = isset($_POST[$formTitleField]) ?
- $_POST[$formTitleField] : 'Untitled';
- $posted_data = array();
- $uploaded_files = array();
- // Get posted values
- foreach ($_POST as $key => $val) {
- if ($key != $formTitleField) {
- $posted_data[$key] = $val;
- }
- }
- // Get uploaded files
- if (is_array($_FILES) && !empty($_FILES)) {
- foreach ($_FILES as $key => $file) {
- if (is_uploaded_file($file['tmp_name'])) {
- $posted_data[$key] = $file['name'];
- $uploaded_files[$key] = $file['tmp_name'];
- }
- }
- }
- // Prepare data structure for call to hook
- $data = (object) array(
- 'title' => $title,
- 'posted_data' => $posted_data,
- 'upload' => $_FILES['upload']['name'],
- 'uploaded_files' => array ( 'upload' => 'http://localhost/gbisawangan.org/assets/gbr/'));
- // Call hook to submit data
- do_action_ref_array('cfdb_submit', array(&$data));
- }
- if(isset($_POST['submitted'])) {
- if(trim($_POST['contactName']) === '') {
- $nameError = 'Please enter your name.';
- $hasError = true;
- } else {
- $name = trim($_POST['contactName']);
- }
- if(trim($_POST['email']) === '') {
- $emailError = 'Please enter your email address.';
- $hasError = true;
- } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
- $emailError = 'You entered an invalid email address.';
- $hasError = true;
- } else {
- $email = trim($_POST['email']);
- }
- if(trim($_POST['comments']) === '') {
- $commentError = 'Please enter a message.';
- $hasError = true;
- } else {
- if(function_exists('stripslashes')) {
- $comments = stripslashes(trim($_POST['comments']));
- } else {
- $comments = trim($_POST['comments']);
- }
- }
- if(!isset($hasError)) {
- $emailTo = get_option('tz_email');
- if (!isset($emailTo) || ($emailTo == '') ){
- $emailTo = get_option('admin_email');
- }
- $subject = '[PHP Snippets] From '.$name;
- $body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
- $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
- wp_mail($emailTo, $subject, $body, $headers);
- $emailSent = true;
- }
- } ?>
- <?php get_header(); ?>
- <section class="container clearfix">
- <div id="header" class="">
- <header class="container page_info clearfix breadcrumb">
- <h1 class="regular bottom_line"><?php the_title(); ?></h1>
- </header><!-- .entry-header -->
- </div>
- <div class="clear"></div>
- <div id="primary" class="site-content content clearfix">
- <div id="content" role="main">
- <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
- <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
- <div class="entry-content">
- <?php if(isset($emailSent) && $emailSent == true) { ?>
- <div class="thanks">
- <p>Thanks, your email was sent successfully.</p>
- </div>
- <?php } else { ?>
- <?php the_content(); ?>
- <?php if(isset($hasError) || isset($captchaError)) { ?>
- <p class="error">Sorry, an error occured.<p>
- <?php } ?>
- <form action="<?php the_permalink(); ?>" id="contactForm" method="post">
- <ul class="contactform">
- <li>
- <label for="contactName">Name:</label>
- <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="required requiredField" />
- <?php if($nameError != '') { ?>
- <span class="error"><?=$nameError;?></span>
- <?php } ?>
- </li>
- <li>
- <label for="email">Email</label>
- <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="required requiredField email" />
- <?php if($emailError != '') { ?>
- <span class="error"><?=$emailError;?></span>
- <?php } ?>
- </li>
- <li> <input type="file" name="upload"/> </li>
- <li><label for="commentsText">Message:</label>
- <textarea name="comments" id="commentsText" rows="20" cols="30" class="required requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
- <?php if($commentError != '') { ?>
- <span class="error"><?=$commentError;?></span>
- <?php } ?>
- </li>
- <li>
- <input type="submit">Send email</input>
- </li>
- </ul>
- <input type="hidden" name="submitted" id="submitted" value="true" />
- </form>
- <?php } ?>
- </div><!-- .entry-content -->
- </div><!-- .post -->
- <?php endwhile; endif; ?>
- <div class="clear padding10"></div>
- </div><!-- #content -->
- </div><!-- #primary .site-content -->
- <?php get_sidebar(); ?>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement