Redireccion de formulario

  • Autor Autor sebasxnco
  • Fecha de inicio Fecha de inicio
S

sebasxnco

Épsilon
hola forobeta tengo el siguiente codigo php que permite enviar post a colaboradores sin tener que registrarse ni nada simplemente con un html, todo funciona bien, pero cuando soy a clic a publicar no redirecciona a otro pagina que supuesta-mente seria al home del sitio. alguien sabe como puedo solucionar eso.

PHP:
            <?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'];
                                # 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 wpostmeta.meta_key = 'Zombies'
                                        AND wpostmeta.meta_value = '$zombies'
                                        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 (empty($zombies)) {
                                                    echo "Please input any number of Zombies";  
                                          }
                                          # 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_content' => $content,
                                             'post_status' => 'draft',
                                             'post_author' => 1,
                                             'post_category' => array($categorie),
                                          );
                                                 
                                        $my_post = wp_insert_post($my_post);
                                        add_post_meta($my_post, 'Zombies', $zombies);

                                        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.";  }
                                  }
                        ?>

el html

HTML:
<!-- New Post Form -->
<div id="postbox">
	<form id="new_post" name="new_post" method="post" action="">
                <p><label for="authorname">Author name</label><br/>
		<input style="width:400px;height:17px;border:1px solid #ccc;padding:5px;" type="text" id="authorname" value="" tabindex="1" name="authorname" />
		</p>
		<p><label for="title">youtube video url</label><br/>
		<input style="width:400px;height:17px;border:1px solid #ccc;padding:5px;" type="text" id="title" value="" tabindex="1" name="title" />
		</p>
                <p><?php wp_dropdown_categories( 'show_option_none=Category&tab_index=4&taxonomy=Sports' ); ?></p>

		<p><label for="post_tags">Tags</label>
			<input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
		<p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
		
		<?php global $post; ?>
<input type="hidden" name="page" id="page" value="< ? php echo $post->ID; ? >"/>
		<input type="hidden" name="action" value="post" />
		<?php wp_nonce_field( 'new-post' ); ?>
	</form>
</div>
<!--// New Post Form -->
 
En la línea:
PHP:
<form id="new_post" name="new_post" method="post" action="">

Debes especificar en la propiedad action que fichero vas a trabajar, si deseas el mismo fichero pues colocale: mismonombre.php, si no colocale en donde se va a procesar tu fichero. Ten en cuenta que dicho fichero debe contener el código que procesará la información o códigos PHP que necesitas para tu trabajo.
 
En la línea:
PHP:
<form id="new_post" name="new_post" method="post" action="">

Debes especificar en la propiedad action que fichero vas a trabajar, si deseas el mismo fichero pues colocale: mismonombre.php, si no colocale en donde se va a procesar tu fichero. Ten en cuenta que dicho fichero debe contener el código que procesará la información o códigos PHP que necesitas para tu trabajo.
amigo cuando hago clic en enviar arroja un error con ese método, según decía en donde saque ese codigo iva en la misma pagina que el html.
 
amigo cuando hago clic en enviar arroja un error con ese método, según decía en donde saque ese codigo iva en la misma pagina que el html.

Entonces debe ser un fichero PHP no un HTML y en el action colocar action="tufichero.php" que sería el mismo... y debería llevar algo como:

PHP:
if(isset($_POST['submit'])) {
//resto de tu codigo php
}
 
segun entiendo en donde me informe de ese codigo no lo puedo hacer por que hace error, y por otro parte el codigo lleva esta linea para reconocer el envio if( 'POST' == $_SERVER['REQUEST_METHOD'] ) { // if form has been submitted , este el el sitio fuente http://wpshout.com/wordpress-submit-posts-from-frontend/ y este el código que uso totalmente funcional Enlace eliminado
 
Atrás
Arriba