简体   繁体   English

我如何获取zurb基础滑块数据表单值

[英]how do i get zurb foundation slider data form values

Im making a form here using some Foundation components. 我在这里使用一些Foundation组件制作表单。 Im using the slider: 我正在使用滑块:

// the slider element. starts at 1 ends at 4 allows 1 step at a time
    <div class="slider" data-slider data-start="1" data-initial-start="1" data-step="1" data-end="4">
    <span class="slider-handle"  data-slider-handle role="slider" tabindex="1" aria-controls="select"></span>
    <span class="slider-fill" data-slider-fill></span>
    </div>

// the input box that shows the sliders value
    <input type="number" id="select" name="select" size="2">

Now here is my issue that I need help with, when the form is submitted (POST method) it sends the value of the input (just like it should) but its plain text and Id like to encrypt it so the POST vars values arent obvious. 现在这是我需要解决的问题,提交表单时(POST方法),它发送输入值(就像应该的那样),但是它的纯文本和Id希望对其进行加密,因此POST vars值不明显。

However, since the output of the from value seems to come from a javascript plugin (the slider) I dont know how to capture its value and encrypt it before its sent. 但是,由于from值的输出似乎来自javascript插件(滑块),因此我不知道如何捕获其值并在发送前对其进行加密。

How can I make something like this work: 我该如何进行以下工作:

value=<?php echo my_encrypt("", $key); ?>

where the "" is the value of the slider. 其中“”是滑块的值。

You won't be able to use PHP to encrypt the value, since it's a server-side technology. 您将无法使用PHP加密值,因为它是服务器端技术。 Your encryption will need to be done in JavaScript. 您的加密将需要使用JavaScript进行。

I'll assume you have a good reason for encrypting, but quickly mention this anyways: if you're submitting over HTTPS, there is no need to encrypt the values you send. 我假设您有充分的加密理由,但是无论如何都要迅速提及:如果您通过HTTPS提交,则无需加密发送的值。 HTTPS is doing that already. HTTPS已经这样做了。

If you're not submitting over HTTPS, one approach is to remove the name from your current number input so that it doesn't get submitted with the form, and keep a second hidden input with the encrypted value, like so: 如果您不是通过HTTPS提交,则一种方法是从当前数字输入中删除该名称,以使该名称不会与表单一起提交,并保留第二个具有加密值的隐藏输入,如下所示:

// the input box that shows the sliders value
<input type="number" id="select" size="2">
// the input that will store the encrypted value
<input type="hidden" name="select" value="">

Then, whenever the slider value changes, encrypt the value in the visible number input and store it in the hidden input (I'm assuming since you're using Foundation you can use jQuery): 然后,只要滑块值发生变化,就对可见数输入中的值进行加密并将其存储在隐藏的输入中(我假设由于您使用的是Foundation,因此可以使用jQuery):

$(document).on('changed.zf.slider', '[data-slider]', function(event) {
  var $slider = $(event.currentTarget);
  var $numberInput = $slider.siblings('#select');
  var $hiddenInput = $slider.siblings('[name="select"]');
  var numberInputValue = $numberInput.val();
  var encryptedValue = yourEncryptionFunction(numberInputValue);

  $hiddenInput.val(encryptedValue);
});

When your form is submitted, the encrypted value you've stored in the hidden input will be submitted and the visible number input will be ignored since it has no name attribute. 提交表单后,将保存已存储在隐藏输入中的加密值,而可视数字输入将被忽略,因为它没有名称属性。

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

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