我无法在wordpress中验证此表单发布,发送提交为空白且未显示错误
广告-post.php中
<?php
/*
Template Name: Publicar Post
*/
$wpdb->hide_errors();
nocache_headers();
global $userdata;
get_currentuserinfo(); // grabs the user info and puts into vars
require_once dirname( __FILE__ ) . '/post-process.php';
get_header(); ?>
<div id="page">
<div class="categories">
<h2 style="border: 1px solid #ccc; border-bottom: none; background: url(<?php echo csp_images_url; ?>/sprite.png) left -738px repeat-x;text-align:center; padding-top: 5px; margin-top: 10px;">Categorías</h2>
<ul id="menu">
<?php wp_list_categories('title_li=&orderby=name&exclude='.$category_id.''); ?>
</ul>
<?php get_sidebar('o'); ?>
</div>
<div class="publish-form">
<div class="post-form">
<h2>Envia tu Anuncio</h2>
<div class="box-yellow">
La publicación de avisos es gratuito, sin embargo si usted desea destacar su anuncio o contratar publicidad en lugares estratégicos de la web, por favor <a href="<?php bloginfo('url'); ?>" title="Contacte con Nosotros">póngase en contacto con nosotros</a>, estaremos
dispuestos a su disposición.
<?php
$ok = classy_filter($_GET['ok']);
if ($err != "") { echo "<div id=\"err\" class=\"err\"><a id='closelink' href=\"#\" onClick=\"document.getElementById('err').style.display = 'none';\">X</a>$err</div>"; }
if ($ok == "ok") {
echo "<div class=\"ok\"><strong>" . __('Muchas gracias!, su artículo ha sido enviado satisfactoriamente.') . "</strong><br />";
if ( get_option("post_status") == "publish") {
echo __('Alguien revisará su publicaci&ocute;n en breve. Si usted tiene alguna pregunta, póngase en contacto con el propietario del sitio.') . "<br />";
}
echo "</div>";
}
?>
</div>
<form action="" method="post" enctype="multipart/form-data" id="new_post" name="new_post">
<input type="hidden" name="action" value="post" />
<?php wp_nonce_field('new-post'); ?>
<label for="title" class="post_tags"><?php _e('Título de la Publicación'); ?> <span>*</span></label>
<input type="text" id="title" class="mid" name="post_title" size="100" maxlength="100" value="<?php echo $_POST['post_title'];?>" style="padding: 5px;" /><br /><br />
<label for="cat" class="post_tags">Por favor seleccione una categoría <span>*</span>:</label>
<?php wp_dropdown_categories('show_option_none=Seleccione una Categoria&hide_empty=0&hierarchical=1&class=adfields&exclude='.$category_id.''); ?>
<br /><br />
<label for="post_tags">Suba una imagen<br /><br />
<small>(Las imágenes no deben ser mayores de 1MB, los formatos soportados son: jpg, png, gif y jpeg.)</small></label>
<input type="file" name="imgs[]" class="wwIconified" style="padding: 5px;" /><br />
<br />
<label for="description" class="post_tags"><?php _e('Escriba aquí la descripción de su Aviso Clasificado'); ?> <span>*</span><br /><small>(Mientras mejor se explique, mejores resultados podrá obtener).</small></label><br />
<?php wp_editor(''. $_POST['content'].'', 'content', $settings ); ?>
<div class="clear"></div>
<br />
<label for="post_tags" class="post_tags">Etiquetas <span>*</span> <small class="mini"><?php _e('(las etiquetas ayuda a mejorar la indexación de su aviso, sepárelas con comas)'); ?></small></label>
<input type="text" id="post_tags" class="adfields" name="post_tags" size="60" maxlength="100" value="<?php echo $_POST['post_tags']; ?>" style="padding: 5px;" />
<br /><br />
<label for="price" class="post_tags">Precio <span>*</span></label><br /><br />
<p><small>(Es necesario que inserte el monto con su respectivo símbolo; ejm. S/.10.00, $20.00 USD, etc.)</small></p>
<input type="text" id="price" class="adfields price" name="price" size="50" maxlength="250" value="<?php echo $_POST['price']; ?>" /><br />
<br />
<label for="post_tags" class="post_tags">Dirección/Ubicación <span>*</span></label><br />
<input type="text" id="location" class="adfields location" name="location" size="50" maxlength="250" value="<?php echo $_POST['location']; ?>" /><br />
<br />
<label for="post_tags" class="post_tags">Agregar URL <small><?php _e('(i.e. http://www.misitio.com)'); ?></small></label><br />
<input type="text" id="addURL" class="adfields url" name="addURL" size="50" maxlength="250" value="<?php echo $_POST['addURL']; ?>" /><br />
<label for="post_tags" class="post_tags">Nombre de Contacto <span>*</span></label><br />
<input type="text" id="name" class="adfields name" name="name" size="50" maxlength="250" value="<?php echo $_POST['name']; ?>" /><br />
<label for="post_tags" class="post_tags">Teléfono</label><br />
<input type="text" id="phone" class="adfields phone" name="phone" size="50" maxlength="250" value="<?php echo $_POST['phone']; ?>" /><br />
<label for="post_tags" class="post_tags">Correo Electrónico <span>*</span></label><br />
<input type="text" id="email" class="adfields email" name="email" size="50" maxlength="250" value="<?php echo $_POST['email']; ?>" /><br />
<input id="submit" type="submit" value="Publicar el Aviso" class="submit_btn" />
</form>
<?php // } //if the form is ok don't display the form anymore ?>
</div>
</div>
<div class="clear"></div>
</div>
<?php get_footer(); ?>
-process.php交
这是处理验证的文件,似乎无法正常工作
<?php
set_time_limit(0);
if (isset($_POST['action']) && $_POST['action'] == 'post') {
if ( get_option("permissions") == "no" ) {
if ( !is_user_logged_in() ){
wp_redirect( get_bloginfo( 'url' ) . '/' );
exit;
};
}
check_admin_referer( 'new-post' );
$err = ""; $ok = "";
$user_id = $current_user->user_id;
$post_title = classy_filter($_POST['post_title']);
$post_cat = (int)classy_filter($_POST['cat']);
$post_cat_array = array("$post_cat");
if (isset ($_POST['content'])) {
$content = trim($_POST['content']);
} else {
echo 'Please enter the content';
}
//$title = classy_filter($_POST['title']);
$post_tags = classy_filter($_POST['post_tags']);
$addURL = classy_filter($_POST['addURL']);
$location = classy_filter($_POST['location']);
$price = classy_filter($_POST['price']);
$name = classy_filter($_POST['name']);
$phone = classy_filter($_POST['phone']);
$email = classy_filter($_POST['email']);
$imgs = strip_tags($_POST['imgs']);
if ( $post_cat == "-1") {
$err .= __('Por favor seleccione una categoría') . "<br />";
} else {
global $wpdb;
$cat_ids = (array) $wpdb->get_col("SELECT `term_id` FROM $wpdb->terms");
if ( !in_array($post_cat, $cat_ids) && $post_cat != "-1") {
$err .= __('La categoría Seleccionada no Existe') . "<br />";
}
}
if ($post_title == "" || $post_cat == "" || $post_tags == "" || $price == "" || $location == "" || $name == "") {
$err .= __('Por favor llene los campos marcados como obligatorios *') . "<br />";
}
if ( !check_email($email) ) {
$err .= __('Por favor ingrese un Correo Electrónico Válido') . "<br />";
}
if ( $total != $nr1nr2 ) {
$err .= __('Los datos ingresados en el captcha son incorrectos') . "<br />";
}
if ( $err == "" ) {
//imgs
//1024 bytes = 1kb
//1024000 bytes = 1mb
$image_folder_name = "imgs";
$size_bytes = 1024000;
$size_mb = $size_bytes / 1024000;
$limitedext = array(".gif",".png",".jpg",".jpeg",".bmp");
// http://codex.wordpress.org/Function_Reference/wp_upload_dir
$upload_arr = wp_upload_dir();
$dir_to_make = trailingslashit($upload_arr['basedir']) . $image_folder_name;
// $dir_to_make = "wp-content/uploads/imgs";
$image_baseurl = trailingslashit($upload_arr['baseurl']) . $image_folder_name;
$image_name = substr(sanitize_title(alphanumericAndSpace($post_title)), 0, 20);
$i = rand();
$imgs = "";
$err2 = "";
while(list($key,$value) = each($_FILES['imgs']['name'])) {
if(!empty($value)) {
$filename = strtolower($value);
$filename = str_replace(" ", "-", $filename);
//get image extension
$tipul = strrchr($filename,'.');
$filename = $image_name."-$i".$tipul;
$add = "$dir_to_make/$filename";
$image = "$image_baseurl/$filename";
//$add = "$filename";
//Make sure that file size is correct
$file_size = $_FILES['imgs']['size'][$key]; //getting the right size that coresponds with the image uploaded
if ($file_size == "0"){
$err2 .= __('El archivo $value tiene 0 bytes.') . "<br />";
} else {
if ($file_size > $size_bytes){
$err2 .= __('El archivo $value es mayor de 5MB.') . "<br />";
}
}
//check file extension
$ext = strrchr($filename,'.');
if ( (!in_array(strtolower($ext),$limitedext)) ) {
$err2 .= __('El archivo $value no es una imagen válida.') . "<br />";
}
//echo $_FILES['archive']['type'][$key];
if ( $err2 == "" ) {
if (!file_exists($dir_to_make)) { mkdir($dir_to_make, 0777); }
copy($_FILES['imgs']['tmp_name'][$key], $add);
chmod("$add",0777);
//$imgs .= get_option('home')."/".$add.",";
$imgs .= $image . ",";
}
$err2 = "";
$i++;
}//if empty $value
}//end while
$post_code = time();
$post_status = "publish";
$post_id = wp_insert_post( array(
'post_title' => $post_title,
'post_content' => $content,
'post_category' => $post_cat_array,
'post_status' => $post_status,
'tags_input' => $post_tags
) );
add_post_meta($post_id, 'imgs', $imgs, true);
add_post_meta($post_id, 'addURL', $addURL, true);
add_post_meta($post_id, 'location', $location, true);
add_post_meta($post_id, 'price', $price, true);
add_post_meta($post_id, 'name', $name, true);
add_post_meta($post_id, 'phone', $phone, true);
add_post_meta($post_id, 'email', $email, true);
$ok = "ok";
wp_redirect( get_bloginfo( 'url' ) . '/' );
}
exit;
}
?>
请帮助
答案 0 :(得分:0)
尝试更改:
<form action="" method="post" enctype="multipart/form-data" id="new_post" name="new_post">
为:
<form action="post-process.php" method="post" enctype="multipart/form-data" id="new_post" name="new_post">
答案 1 :(得分:0)
你还有一个额外的;在你的第一行
set_time_limit(0);
if (isset($_POST['action']) && $_POST['action'] == 'post') {
if ( get_option("permissions") == "no" ) {
if ( !is_user_logged_in() ){
wp_redirect( get_bloginfo( 'url' ) . '/' );
exit;
}; <----------------------------Get rid of this SemiColon
}
http://phpcodechecker.com/检查您的代码,即使是; 但是我先这样做。