我在前端形式中使用带有ajax的wordpress,我需要支持处理和上传特色图像.我的问题是关于特色图像.我的HTML是这样的:
<form id="msform" action="#" method="post" enctype="multipart/form-data">
//inputs of various nature
<input type="file" name="main_image" id="main_image" multiple="false" value="" accept=".png, .jpg, .jpeg, .gif"/>
<input type="submit" class="submit" value="Publish"/>
</form>
Run Code Online (Sandbox Code Playgroud)
我通过这个jquery将数据发送到php函数(遵循Wordpress方法):
function apfaddpost() {
var formData = $('#msform').serialize();
formData.append('main_image', $('#main_image')[0].files[0]); //here should be the problem
jQuery.ajax({
type: 'POST',
url: apfajax.ajaxurl,
data: formData + '&action=apf_addpost', //here I send data to the php function calling the specific action
processData: false,
contentType: false
success: function(data, textStatus, XMLHttpRequest) {
var id = '#apf-response';
jQuery(id).html('');
jQuery(id).append(data);
resetvalues();
},
error: function(MLHttpRequest, …Run Code Online (Sandbox Code Playgroud) 我正在将一个外部脚本与我的wordpress主题集成,我在我的一个文件中收到此错误:
PHP致命错误:调用未定义的函数get_bloginfo()
这个脚本位于
主题/ mytheme的/的MyScript
所有文件包含如下:
include(WP_CONTENT_DIR."/themes/mytheme/myscript/myfile.php");
Run Code Online (Sandbox Code Playgroud)
我该怎么解决?
我正在使用带有validator.js的bootstrap创建一个表单.表单工作正常但我想滚动到第一个错误,如果有一些.我是jquery/js的新手,我现在不知道如何实现这个目标.
我尝试过这样的事情:
HTML
<form id="repost-form" method="post" enctype="multipart/form-data" role="form">
<div class="col-sm-6 form-group">
<p><?php echo __('Your project title', 'ProjectTheme'); ?></p>
<p><input type="text" size="50" class="form-control " name="project_title" value="<?php echo (empty($_POST['project_title']) ? ($post->post_title == "draft project" ? "" : $post->post_title) : $_POST['project_title']); ?>" data-error="<?php echo __('Insert the project title','ProjectTheme'); ?>" required></p>
<div class="help-block with-errors"></div>
</div>
<input class="submit_green" type="submit" name="project_submit1" value="<?php _e("Submit", 'ProjectTheme'); ?> >>" />
</form>
Run Code Online (Sandbox Code Playgroud)
JS
$('#repost-form').validator().on('project_submit1', function (e) {
if (e.isDefaultPrevented()) {
$('html, body').animate({ scrollTop: $(".with-errors:first").offset().top - 50 }, 500);
$(".with-errors:first").focus();
} …Run Code Online (Sandbox Code Playgroud) javascript jquery requiredfieldvalidator scrollto twitter-bootstrap