7. Thêm Form Title (ok)
C:\xampp\htdocs\test\wp-content\plugins\plugin-name\includes\class-wpf-form_ct.php
<?php
class WPF_Form_CT {
protected $plugin_name;
protected $version;
protected $themplate_id = false;
public function __construct($plugin_name, $version, $themplate_id = false) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->themplate_id = $themplate_id;
}
public function form() {
$sort_cmb = array_merge(WPF_Utils_CT::get_wc_attributes(), WPF_Utils_CT::get_default_fields());
$languages = array(
'en' => array(
'name' => '',
'selected' => true,
),
);
natcasesort($sort_cmb);
$layout = $data = array();
$this->add_fields($data);
?>
<input type="hidden" value="" name="layout" id="wpf_layout" />
<input type="hidden" value="<?php echo $this->themplate_id ?>" id="wpf_themplate_id" name="themplate_id" />
<?php
}
private function add_fields($data = array()) {
$layouts = array(
'vertical' => __('Vertical Layout', 'wpf'),
'horizontal' => __('Horizontal Layout', 'wpf')
);
?>
<div class="wpf_lightbox_row">
<div class="wpf_lightbox_label"><label for="wpf_name"><?php _e('Form Title', 'wpf'); ?></label></div>
<div class="wpf_lightbox_input">
<input id="wpf_name" class="wpf_towidth" type="text" value="<?php echo !empty($data['name']) ? $data['name'] : '' ?>" name="name" />
</div>
</div>
<?php
}
}
?>
C:\xampp\htdocs\test\wp-content\plugins\plugin-name\admin\js\wpf-admin_ct.js
(function($) {
$(document).ready(function() {
$('body').delegate('a.wpf_lightbox', 'click', function(e) {
e.preventDefault();
var $self = $(this);
$.ajax({
url: this,
success: function(data) {
if (data) {
openLightBox(e, $self.attr('title'), data, $self.data('class'), $self.data('top'));
}
}
});
});
var getDocHeight = function () {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
};
var openLightBox = function (e, title, content, $class, $top) {
e.preventDefault();
var $uniqid = 'wpf_' + Math.random().toString(36).substr(2, 9);
var $lightbox = '<div id="' + $uniqid + '" class="wpf_admin_lightbox wpf_interface">' +
'<div class="wpf_lightbox_title">' + title + '</div>' +
'<a href="#" class="wpf_close_lightbox">×</a>' +
'<div id="wpf_lightbox_container">' +
'<div class="wpf_lightbox_inner">' + content + '</div>' +
'</div>' +
'</div>' +
'<div class="wpf_overlay"></div>';
$('body').append($lightbox);
if(!$top){
$top = 100;
}
if($class){
$('#' + $uniqid).addClass($class);
}
$.event.trigger("WPF.openlightbox",[e,$uniqid]);
$('#' + $uniqid).nextAll('.wpf_overlay').show();
$('#' + $uniqid).show().css('top', getDocHeight()).animate({
top: $top
}, 800);
}
});
})(jQuery);
PreviousCách tạo action, nonce,check_ajax_referer trên đường dẫn (ok)Next8. Lấy được kết quả form nhập vào (ok)
Last updated
Was this helpful?