简体   繁体   English

如何从jQuery插件中提取值并设置为PHP变量?

[英]How to pull value from jQuery plugin and set as PHP variable?

I am using a jQuery plugin called Stepy , to allow users to complete a 10-step form. 我正在使用一个名为Stepy的jQuery插件,以允许用户完成10个步骤的表单。

Sample form: http://jsfiddle.net/wvkfn/ 样本表格: http : //jsfiddle.net/wvkfn/

My site is setup so the user can leave the form in the middle of a 'step', in order to complete other tasks, and I'd like to have a variable set, so that when they complete the task, it takes them back to the last step they were on. 我的网站已设置好,以便用户可以将表单保留在“步骤”的中间,以便完成其他任务,并且我想设置一个变量,以便他们完成任务时将其取回到最后一步。

Is there a way to pull the value of the 'current' step from the plugin? 有没有办法从插件中提取“当前”步骤的值? My first thought was that the plugin places a class called current-step on the title, and pull the number value from the title text that has that class set. 我首先想到的是,该插件在标题上放置了一个称为current-step的类,并从已设置该类的标题文本中提取了数字值。

I'd then want to set that as a PHP variable, so I could set the task link to something like http://www.example.com/task.php?step=3 . 然后,我想将其设置为PHP变量,因此可以将任务链接设置为类似http://www.example.com/task.php?step=3的内容

Any ideas on how to go about this? 关于如何解决这个问题的任何想法?

Use the 'select' option stepy offers to register a callback when a tab is selected. 选择选项卡后,stepy会使用“选择”选项注册回调。 In the callback use an asynchronous POST to your server to store the currently selected tab. 在回调中,使用对服务器的异步POST来存储当前选定的选项卡。

Sample: 样品:

$('#custom').stepy({
    ...,
    select: function(index){
        $.ajax({
            url: "saveCurrentStep?userID=1&step=" + index;
        });
    }
});

一种简单的解决方案是为当前步骤存储一个cookie ,或者您可以为每个步骤使用anchors URL例如步骤1 mysite.com/task.php#tsep1并从URL提取值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM