Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Template Name: Fayres directory entry form
- */
- ?>
- <!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" <?php language_attributes(); ?>>
- <head profile="http://gmpg.org/xfn/11">
- <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
- <title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title>
- <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
- <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/custom.css" type="text/css" media="screen, print" />
- <!--[if IE 7]><link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie7.css" type="text/css" media="screen" /><![endif]-->
- <!--[if IE 6]><link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie6.css" type="text/css" media="screen" /><![endif]-->
- <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/print.css" type="text/css" media="print" />
- <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
- <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />
- <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
- <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
- <?php wp_head(); ?>
- <link type="text/css" href="<?php bloginfo('template_url'); ?>/jquery/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
- <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/jquery/js/jquery-1.6.2.min.js"></script>
- <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
- <script>
- $(function() {
- $( "#datepicker" ).datepicker({
- dateFormat: 'dd/mm/yy',
- numberOfMonths: 3,
- showButtonPanel: true
- });
- });
- </script>
- </head>
- <body>
- <ul id="shortcuts" title="Accessibility shortcuts menu">
- <li><a href="#maincontent">Skip to main content</a></li>
- </ul>
- <div id="container"><div id="wrapper">
- <div id="branding">
- <a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?> homepage"><img src="<?php bloginfo('template_url'); ?>/images/logo.gif" alt="<?php bloginfo('name'); ?>" id="logo" /></a>
- <p id="strap"><?php bloginfo('description'); ?></p>
- <?php // Check if this is a post or page, if it has a thumbnail, and if it's a big one
- if ( is_singular() &&
- has_post_thumbnail( $post->ID ) &&
- ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail') ) &&
- $image[1] >= HEADER_IMAGE_WIDTH ) :
- // We have a new header image!
- echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
- else : ?>
- <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
- <?php endif; ?>
- </div><!--branding-->
- <div id="mainmenu" role="navigation">
- <?php // Navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assiged to the primary position is the one used. If none is assigned, the menu with the lowest ID is used. // ?>
- <?php wp_nav_menu( array( 'container' => '', 'theme_location' => 'primary' ) ); ?>
- </div><!--mainmenu -->
- <div id="contentcontainer">
- <div id="maincontent" class="withsidebar">
- <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
- <h1><?php the_title(); ?></h1>
- <?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
- <?php endwhile; endif; ?>
- <?php
- global $wpdb;
- global $post;
- $title = $_POST['title']; // get the inputted title
- $content = $_POST['content']; // get the inputted content
- $categorie = $_POST['cat']; // get the category selected by user
- $zombies = $_POST['zombies'];
- $venue = $_POST['venue_name'];
- $date = $_POST['datepicker'];
- $starttime = $_POST['start_time'];
- $endtime = $_POST['end_time'];
- $entry = $_POST['entry_fee'];
- $link = $_POST['link'];
- $address = $_POST['venue_address'];
- $contact = $_POST['contact_name'];
- $phone = $_POST['contact_number'];
- $email = $_POST['contact_email'];
- list ($day, $month, $year) = split ("/", $date);
- $usdate = $month."/".$day."/".$year;
- $countdowndate = $year."-".$month."-".$day;
- # run a query to check for a post containing the data that our user is about to submit
- # store results in $verifica
- $sql = "
- SELECT wposts.*
- FROM $wpdb->posts wposts
- LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
- LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
- LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
- WHERE wposts.post_status = 'publish'
- AND wposts.post_title = '$title'
- AND wposts.post_content = '$content'
- AND $wpdb->term_taxonomy.taxonomy = 'category'
- AND $wpdb->term_taxonomy.term_id IN($categorie)";
- $verifica = $wpdb->get_results($sql);
- if( 'POST' == $_SERVER['REQUEST_METHOD'] ) { // if form has been submitted
- # some validation
- if(empty($title)) {
- echo "Please give your post a title<br />";
- }
- if (empty($content)){
- echo "Please write your post's content<br />";
- }
- if ($categorie == -1){
- echo "Please assign a category to your post.<br />";
- }
- # if there are no similar posts ($verifica is empty) and user filled in the fields, insert post
- # also, redirect to the homepage to make sure we don't get 404-ed
- if (empty($verifica) && !empty($title) && !empty($content) && $categorie != -1) {
- $my_post = array(
- 'post_title' => $title,
- 'post_excerpt' => $content,
- 'post_status' => 'draft',
- 'post_author' => 1,
- 'tax_input' => array( 'fayre-region' => $categorie ),
- 'post_type' => 'fayres'
- );
- $my_post = wp_insert_post($my_post);
- add_post_meta($my_post, 'venue_name', $venue);
- add_post_meta($my_post, 'fayre_date', $countdowndate);
- add_post_meta($my_post, 'fayre_start_time', $starttime);
- add_post_meta($my_post, 'fayre_end_time', $endtime);
- add_post_meta($my_post, 'entry_fee', $entry);
- add_post_meta($my_post, 'link', $link);
- add_post_meta($my_post, 'venue_address', $address);
- add_post_meta($my_post, 'contact_name', $contact);
- add_post_meta($my_post, 'contact_number', $phone);
- add_post_meta($my_post, 'contact_email', $email);
- if (!function_exists('wp_generate_attachment_metadata')){
- require_once(ABSPATH . "wp-admin" . '/includes/image.php');
- require_once(ABSPATH . "wp-admin" . '/includes/file.php');
- require_once(ABSPATH . "wp-admin" . '/includes/media.php');
- }
- if ($_FILES) {
- foreach ($_FILES as $file => $array) {
- if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
- return "upload error : " . $_FILES[$file]['error'];
- }
- $attach_id = media_handle_upload( $file, $my_post );
- }
- }
- if ($attach_id > 0){
- //and if you want to set that image as Post then use:
- update_post_meta($my_post,'_thumbnail_id',$attach_id);
- }
- wp_redirect( home_url() );
- }
- # if $verifica is not empty, then we don't insert the post and we display a message
- else if( !empty($verifica) ) { echo "You are trying to submit the same post twice! Be nice."; }
- }
- ?>
- <form action="" method="post" name="FayreEntryForm" class="fayre-entry-form" enctype="multipart/form-data">
- <p>Submit your details for only £20 (we will phone to take your payment once you have filled out the form below).</p>
- <p><em>Please note this service is FREE to our advertisers, please contact the office for more information.</em></p>
- <h3>Fayre details</h3>
- <p>
- <label for="title">Name of fayre</label>
- <input type="text" name="title" id="title" class="large" />
- </p>
- <p>
- <label for="datepicker">Date of fayre</label>
- <input type="text" id="datepicker" name="datepicker" class="medium" />
- </p>
- <p>
- <label for="start_time">Opening time</label>
- <input type="text" id="start_time" name="start_time" class="small" />
- </p>
- <p>
- <label for="end_time">Closing time</label>
- <input type="text" id="end_time" name="end_time" class="small" />
- </p>
- <p>
- <label for="cat">Region</label>
- <?php wp_dropdown_categories('show_option_none=Select region&show_count=0&hide_empty=0&echo=1&taxonomy=fayre-region'); ?>
- </p>
- <p>
- <label for="venue_name">Venue name</label>
- <input type="text" name="venue_name" id="venue_name" class="large" />
- </p>
- <p>
- <label for="venue_address">Venue address</label>
- <input type="text" name="venue_address" id="venue_address" class="large" />
- </p>
- <p>
- <label for="entry_fee">Entry fee</label>
- <input type="text" name="entry_fee" id="entry_fee" class="small" value="£" />
- </p>
- <p>
- <label for="link">Fayre website</label>
- <input type="text" name="link" id="link" value="http://" class="large" />
- </p>
- <p>
- <label for="content">Brief description of fayre (up to 50 words)</label>
- <textarea name="content" id="content" cols="30" rows="5" class="large"></textarea>
- </p>
- <p>
- <label for="thumbnail">Image of venue (150x150 pixels)</label>
- <input type="file" name="thumbnail" id="thumbnail" />
- </p>
- <h3>Contact details</h3>
- <p>Please enter your contact details. This is just for our records, and won't be posted with your entry.</p>
- <p>
- <label for="contact_name">Contact name</label>
- <input type="text" name="contact_name" id="contact_name" class="medium" />
- </p>
- <p>
- <label for="contact_number">Contact phone no.</label>
- <input type="text" name="contact_number" id="contact_number" class="medium" />
- </p>
- <p>
- <label for="contact_email">Contact email</label>
- <input type="text" name="contact_email" id="contact_email" class="large" />
- </p>
- <p id="submitrow"><input type="submit" value="Submit entry"></p>
- <?php wp_nonce_field( 'FayreEntryForm' ); ?>
- </form>
- </div><!--maincontent-->
- <div id="sidebar">
- <ul class="widgets">
- <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Site sidebar') ) : ?>
- <?php endif; ?>
- </ul>
- </div><!--sidebar-->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement