ajaxform() & sortable('serialize') 和 codeigniter .. 提交表单字段和列表元素

发布于 2024-12-21 22:26:59 字数 1798 浏览 3 评论 0原文

我有一个表单和一个 sortable() 列表,用户可以从预先填充的列表中拖动到空的 UL 中。用户可以将他们想要的 LI 拖到这个空的 UL 中。还有一个带有一些文本框的表单,用户可以填写并单击提交。

我可以让 ajaxform 提交表单数据并将其显示在 flashdata 会话中,但我无法让它显示 allowed_fields 数据。 (这是可排序的列表)。我知道它对其进行序列化,因为运行 alert(serializedList); 返回元素的序列化列表。

这是生成可排序列表的 JS:

/**
 * sortable ul items
 * 
 * this is used for the add levels page to associate allowed_fields 
 * to a level.
 */
$('.block-list').sortable({
    connectWith: '.block-list',
    placeholder: 'placeholder'
});

这是处理 ajaxSubmit 的 JS:

/**
 * showResponse(data)
 * show the response if the form submission is successful
 * @param  {object} data object of message or success
 * @return {null}
 */
function showResponse(data){
    alert(serializedList);
    if (data.errorStatus == 1){
        $.jGrowl(data.message, { theme: 'error' });
    }else{

        $.jGrowl(data.message, { theme: 'success' });
    }
}//end showResponse()

/** @type {Object} setup the options for the ajax submit forms. */
var submitOptions = {
    success: showResponse,
    beforeSubmit: function(){ serializedList = $("#allowed-fields-list").sortable('serialize');  },
    dataType: 'json',
    resetForm: true ,
    data: { allowed_fields: serializedList }
};      
$("#addlevel-form").ajaxForm(submitOptions);

这是处理表单数据的代码点火器函数。 .

public function addlevelprocess(){
    $message = array(
        'message' => 'Successfully Added The Level To The Database! WHOA!:'.$this->input->post(),
        'errorStatus' => 0
    );
    $this->session->set_flashdata('post', $this->input->post());
    echo json_encode($message);
}

我怎样才能让ajaxform发送表单字段数据和sortables()数据。

i have a form and a sortable() list where a user can drag from a pre populated list, into an empty UL. The user would drag the LIs that they want into to this empty UL.. There is also a form with a few text boxes that the user fills out and clicks submit.

I can get the ajaxform to submit the form data and display it in a flashdata session, but i cant get it to show the allowed_fields data. (which is the sortable list). I know its serializing it because running alert(serializedList); returns the serialized list of elements.

This is the JS to generate the sortable lists:

/**
 * sortable ul items
 * 
 * this is used for the add levels page to associate allowed_fields 
 * to a level.
 */
$('.block-list').sortable({
    connectWith: '.block-list',
    placeholder: 'placeholder'
});

This is the JS to process the ajaxSubmit:

/**
 * showResponse(data)
 * show the response if the form submission is successful
 * @param  {object} data object of message or success
 * @return {null}
 */
function showResponse(data){
    alert(serializedList);
    if (data.errorStatus == 1){
        $.jGrowl(data.message, { theme: 'error' });
    }else{

        $.jGrowl(data.message, { theme: 'success' });
    }
}//end showResponse()

/** @type {Object} setup the options for the ajax submit forms. */
var submitOptions = {
    success: showResponse,
    beforeSubmit: function(){ serializedList = $("#allowed-fields-list").sortable('serialize');  },
    dataType: 'json',
    resetForm: true ,
    data: { allowed_fields: serializedList }
};      
$("#addlevel-form").ajaxForm(submitOptions);

and this is the code igniter function that will handle the form data..

public function addlevelprocess(){
    $message = array(
        'message' => 'Successfully Added The Level To The Database! WHOA!:'.$this->input->post(),
        'errorStatus' => 0
    );
    $this->session->set_flashdata('post', $this->input->post());
    echo json_encode($message);
}

how can i get ajaxform to send both form field data and the sortables() data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经暖 2024-12-28 22:26:59

我最终使用 ajaxSubmit() 并通过数据传递序列化表单信息:

$('#addlevel-form').submit(function() {
    /** @type {serialized} serialized array of field IDs for allowed fields */
    var allowedFields = $('#allowed-fields-list').sortable('serialize');
    var formInfo = $('#addlevel-form').formSerialize();
    /** @type {Object} setup the options for the ajax submit forms. */
    var submitOptions = {
        url: '/admin/levels/addlevelprocess.html',
        dataType: 'json',
        success: showResponse,
        data: { allowed_fields: allowedFields, levelInfo: formInfo }
    };      
    $(this).ajaxSubmit(submitOptions);
    return false;
});

i ended up using ajaxSubmit() and passing the serialized form information via data:

$('#addlevel-form').submit(function() {
    /** @type {serialized} serialized array of field IDs for allowed fields */
    var allowedFields = $('#allowed-fields-list').sortable('serialize');
    var formInfo = $('#addlevel-form').formSerialize();
    /** @type {Object} setup the options for the ajax submit forms. */
    var submitOptions = {
        url: '/admin/levels/addlevelprocess.html',
        dataType: 'json',
        success: showResponse,
        data: { allowed_fields: allowedFields, levelInfo: formInfo }
    };      
    $(this).ajaxSubmit(submitOptions);
    return false;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文