我在wordpress模板页面上有以下表单。每次提交表单时,我都会收到一个404错误,但我没有在表单中使用任何保留的workpress参数名称。
<?php
/**
* Template Name: Registration Template
*/
if(isset($_POST['form-submitted']))
{
if(trim($_POST['runner']) === '') {
$runnerError = 'Please enter runner runner.';
$hasError = true;
} else {
$runner = trim($_POST['runner']);
}
if(trim($_POST['racenumber']) === '') {
$numberError = 'Please enter a race number.';
$hasError = true;
} else {
$racenumber = trim($_POST['racenumber']);
}
$race = trim($_POST['race']);
error_log($race.' '.$runner.' '.$racenumber);
$registrationSubmitted = true;
}
get_header();
echo "<pre>GET "; print_r($_GET); echo "</pre>";
echo "<pre>POST "; print_r($_POST); echo "</pre>";
?>
<div id="container">
<?php
if(isset($registrationSubmitted) && $registrationSubmitted == true)
{
echo '<div class="thanks"><p>The runner has been registered.</p></div>';
}
else
{
$races = // magic array
$selectRaces = '<select name="race" id="race">';
foreach($races as $racez)
{
$selectRaces .= sprintf('<option value=%d>%s</option>',$race->id,$race->name);
}
$selectRaces .= '</select>';
echo apply_filters('the_content','
<form action="'.get_permalink().'" id="form" method="POST">
[one_half last="no"]
<b>Race Details</b><br/>
RaceNumber<input type="text" name="racenumber" id="racenumber"/><br/>
Race'.$selectRaces.'<br/>
[/one_half]
[one_half last="yes"]
<b>Runner Details</b><br/>
ID<input type="text" name="runner" id="runner"/><br/>
Firstname<input type="text" name="first" id="first"/><br/>
Surname<input type="text" name="last" id="last"/><br/>
Gender<input type="text" name="gender" id="gender"/><br/>
DOB<input type="text" name="dob" id="dob"/><br/>
Standard<input type="text" name="standard" id="standard"/><br/>
Company<input type="text" name="company" id="company"/><br/>
[/one_half]
<input type="submit" value="Register Runner"/>
<input type="hidden" name="form-submitted" id="bhaa-submitted" value="true" />
</form>');
}
echo '</div>';
?>
<?php get_footer(); ?>我已经定制了我的404页面来转储$_POST值,所以我确信参数值正在被提交。
[racenumber] => 5
[race] => 2596
[runner] => 5
[first] =>
[last] =>
[gender] =>
[dob] =>
[standard] =>
[company] =>
[form-submitted] => true谁能解释一下我‘isset($_POST’‘form submitted’)‘中的逻辑没有被执行?
生成的html
<form action="http://localhost/registration/" id="form" method="POST">
<div class="one_half">
<b>Race Details</b><br><br>
RaceNumber<input name="number" id="number" type="text"><br><br>
Race<br>
<select name="race" id="race">
<option value="2596" id="2596">4-Mile-M</option>
<option value="2595" id="2595">2-Mile-W</option>
</select>编辑
我更改了代码,将select下拉列表的值设置为使用递增的int值,而不是使用sprintf将字符串值映射到int值。当第一个元素被选中时,表单提交,如果第二个选项被选中,我得到一个404!
$races = // magic array
$selectRaces = '<select name="race" id="race">';
$i=0;
foreach($races as $racez)
{
$selectRaces .= sprintf('<option value=%d>%s</option>',$i++,$race->name);
}发布于 2015-04-27 00:52:26
您不能在POST表单中使用此变量
_ajax_nonce _page _per_page _signup_form _total _url _wp_http_referer _wp_original_http_referer _wp_unfiltered_html_comment _wpnonce _wpnonce-_ajax_nonce-header-upload
aa操作action2 active_post_lock add_new add_new_users add_new_users admin_bar_front admin_color admin_email admin_password admin_password2 ajax对齐所有博客所有用户alt approve_parent approved attachments attachment_id attachments auth_cookie author author_name autocomplete_type auto_draft自动添加页面自动保存
background-attachment -color background-position-x background-repeat banned_email_domains blog_name blog_public blog_upload_space blog bulk_edit
C calendar cat category_base category_name目录列出更改更改字符集复选框选中clear-recent-list closed comment comment_approved comment_author comment_author_email comment_author_url comment_content comment_date comment_ID comment_parent comment_post_ID comment_shortcuts comment_status comments_listing comments_popup confirmdelete connection_type content context cpage create-new-attachment createuser customize_messenger_channel自定义自定义链接-选项卡
date date_format date_format_custom day default- delete_all delete_all2 delete_comments delete_option delete_tags delete_widget display_name书签删除建议删除删除date删除帖子描述分离解除display_name do
edit_date电子邮件错误精确摘录
features fetch fheight文件宽度过滤器find_detached first_comment first_comment_author first_comment_url first_name first_page first_post found_post_id fwidth
global_terms_enabled全局gmt_offset guid
height hh hidden hidden_aa hidden_jj hidden_mm hidden_mn hidden_hh历史主机名小时html-upload
id id_base illegal_names insert-图库插入临时按钮登录项目-对象项目-类型
jj json json_data
钥匙
last_name limited_email_domains link_id link_image link_name link_rss link_url link_visible链接检查区域设置锁定日志logged_in_cookie
M media media_type menu menu_items menu-item-attr-title menu-item-classes menu-item-db-id menu-item-description menu-item-object-id menu-item-object -id menu-item-parent-id menu-item-position menu-item-target menu-item-title menu-item-type menu-item-url menu-item-xfn menu-locations menu-name message metakeyinput metakeyselect metavalue mn mm mn mode monthnum more move multi_number
名称nav-menu-locations新new_role new_slug new_title newcat newcomment_author newcomment_author_email newcomment_author_url新内容新用户昵称no_placeholder noapi noconfirmation noredir编号
offset oitar选项option_page orderby
P pb page page_columns page_id page_options paged pagegen_timestamp pagename parent_id pass1 pass2 password permalink_structure photo_description photo_src plugin ping_status plugin plugin_status pointer position post post_category post_data post_format post_id post_ID post_mime_type post_password postid post preview ps publish pwd
查询
reassign_user重认证重定向注册注册引用的redirect_to引用通知rememberme background removeheader removewidget reset-background resetheader rich_editing robots角色
S same save savewidget savewidgets屏幕滚动到搜索第二部分选择选择发送send_password句子短show_sticky侧边栏signup_for signup_form_id site_id site_name站点名称大小跳过裁剪垃圾邮件垃圾邮件src ss阶段启动静态状态粘滞subdomain_install提交子帖子subpost_id super_admin
tab tag tag_ID tag-name tag_base tags_input tax tax_input tag-name目标分类tb术语文本颜色-widget-id主题theme_status thumb timezone_string time_format time_format_custom title thumbnail_id垃圾桶类型
username update_home_url username users upload_filetypes upload_space_check_disabled use_ssl user user_id user_login user_name username users
验证-删除版本可见性
W weblog_title welcome_email welcome_user_email widget_id widget_number小部件-id小部件-最近评论小部件-不带备注的rss宽度wp_customize wp_http_referer wp_screen_options wp-预览WPLANG
x1
y1年
https://stackoverflow.com/questions/15685020
复制相似问题