-
AuthorPosts
-
January 22, 2014 at 3:26 am #213157
Hello, I have a custom form to allow users to post from the front end to a custom post type (pending).
The form function perfectly well on other themes (I have tested on other themes I have written). The form also works fine if I include the enfold header but comment out the include for the footer. Similarly, the form works if I comment out the header but include the footer. So whats the problem….well, when both header and footer are included the form does not post.
Any ideas as to what in the theme could be prevent normal functionality?
Here is my form:
<div class="entry-content-wrapper clearfix" style="border: solid 0px black"> <form class="avia_ajax_form" method="POST" form id="new_post" name="new_post" method="post" action="" enctype="multipart/form-data"> <fieldset style="border: 0px;"> <p id="IGN" class="form_element_half"> <label for="offender_ign" placeholder="IGN">Offender IGN <abbr title="required" class="required">*</abbr></label> <input id="offender_ign" type="text" value="" tabindex="5" name="offender_ign" class="text_input is_empty"> </p> <p id="type_of_offence" class="form_element_half_2 form_element_half"> <!--<label for="cat">Type:</label> <?php wp_dropdown_categories( 'tab_index=10&taxonomy=portfolio_entries&hide_empty=0' ); ?> --> <label for="type_of_offence">Type of Offence</label> <select id="type_of_offence" class="select " name="category"> <?php // ======= Custom post types category drop down ======== $taxonomy = 'portfolio_entries'; $terms = get_terms($taxonomy); // Get all terms of a taxonomy if ( $terms && !is_wp_error( $terms ) ) : foreach ( $terms as $term ) { echo '<option value="' . get_term_link($term->slug, $taxonomy) . '">' . $term->name . '</option>'; } endif; ?> </select> </p> <p id="element_description"> <label for="description" class="textare_label hidden textare_label_avia_description">Description</label> <textarea id="description" rows="7" cols="40" class="text_area " name="description"></textarea> </p> <p id="element_image_upload"> <label for="image_upload">Image Upload</label> <input id="image_upload" type="file" value="" class="text_input" name="image"> </p> <p id="element_tags"> <label for="post_tags">Tags <small>(Comma Separated List)</small></label> <input id="post_tags" type="text" value="" class="text_input " name="post_tags"> </p> <p id="hidden_submit"> <input type="hidden" name="form" value="1"> <!-- on click, do wordpress action new_post --> <input type="submit" class="button" name="submit" value="Submit"> </p> <!-- ensure post is coming from site and not elsewhere --> <input type="hidden" name="action" value="new_post" /> <?php wp_nonce_field( 'new-post' ); ?> </fieldset> </form> </div>
The form functions:
<?php if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") { // Do some minor form validation to make sure there is content if (isset ($_POST['offender_ign'])) { $title = $_POST['offender_ign']; } else { echo 'Please enter the In Game Name (IGN) of the offender'; } if (isset ($_POST['description'])) { $description = $_POST['description']; } else { echo 'Please enter some notes about the hate speech'; } $tags = $_POST['post_tags']; // ADD THE FORM INPUT TO $new_post ARRAY $new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_category' => array($_POST['category']), // Usable for custom taxonomies too 'tags_input' => array($tags), 'post_status' => 'pending', // Choose: publish, preview, future, draft, etc. 'post_type' => 'portfolio' //'post',page' or use a custom post type if you want to ); //SAVE THE POST $pid = wp_insert_post($new_post); //SET OUR TAGS UP PROPERLY wp_set_post_tags($pid, $_POST['post_tags']); // Image handling if ($_FILES) { foreach ($_FILES as $file => $array) { $newupload = insert_attachment($file,$pid); // $newupload returns the attachment id of the file that // was just uploaded. Do whatever you want with that now. } } //REDIRECT ON SAVE $link = "/success"; wp_redirect( $link ); } // END THE IF STATEMENT THAT STARTED THE WHOLE FORM //POST THE POST YO do_action('wp_insert_post', 'wp_insert_post'); ?>
January 22, 2014 at 8:35 pm #213513Hi Vince!
Have you checked the PHP error log?
Regards,
JosueJanuary 27, 2014 at 4:57 pm #215395This reply has been marked as private.January 28, 2014 at 1:14 am #215587Hi Vincent!
Try removing the “avia_ajax_form” class from the form element.
Cheers!
JosueJanuary 28, 2014 at 1:34 am #215591This reply has been marked as private.January 28, 2014 at 1:43 am #215592You are welcome, glad we could help :)
Regards,
Josue -
AuthorPosts
- The topic ‘Custom front end form not posting’ is closed to new replies.