Dobrý den,
Vytvořil jsem si jednoduchý formulář na vkládání příspěvků.(časem ho budu rozšiřovat)
Nicméně pokud je formulář vložený do souboru home.php a je z něho udělaná default ně první stránka http://domena.cz/, odeslání a ukládání formuláře funguje.
Pokud tento formulář pak vložím do template pro konkrétní stránku např.: page-formular.php (http://domena.cz/formular), tak při odesílání formuláře mi vždycky skočí chyba 404.
Pokud tuto adresu zadám ručně. formulář naběhne a při odeslání se zase objeví chyba 404
Nenapadá Vás čím by to mohlo být?
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* @package WordPress
* Template Name: formular
*/
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
// Do some minor form validation to make sure there is content
if (isset ($_POST['jmeno'])) {
$jmeno = $_POST['jmeno'];
} else {
echo 'Please enter a title';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
} else {
echo 'Please enter the content';
}
// Add the content of the form to $post as an array
$post = array(
'post_title' => $jmeno,
'post_content' => $description,
'post_status' => 'publish', // Choose: publish, preview, future, draft, etc.
'post_type' => 'post', //'post',page' o
);
wp_insert_post($post); // Pass the value of $post to WordPress the insert function
wp_redirect( site_url() );
} // end IF
// Do the wp_insert_post action to insert it
do_action('wp_insert_post', 'wp_insert_post');
get_header(); ?>
<h3 class="center">Podat hlášení</h3>
<form id="new_post" class="form_post" name="new_post" method="post" action="">
<label for="jmeno">Jméno</label><br />
<input type="text" id="jmeno" value="" name="jmeno"/>
<label for="description">Popis</label><br />
<textarea id="description" name="description" cols="10" rows="6" required></textarea>
<input type="submit" value="Podat oznámení" id="submit" name="submit" class="submit" />
<input type="hidden" name="post_type" id="post_type" value="post" />
<input type="hidden" name="action" value="post" />
<?php wp_nonce_field( 'new-post' ); ?>
</form>