简体   繁体   English

将 href 链接传递给 php 表单

[英]Passing href link to php form

I've got a small form where I store information regarding some user choices.我有一个小表格,用于存储有关某些用户选择的信息。 I'm not sure though how I can pass href links that are different for each user.我不确定如何传递每个用户不同的 href 链接。

Here is a small example of the code:这是代码的一个小示例:

<form method="post" action="save.php" class="form">
    <fieldset>
        <input type="checkbox" name="checkthing" value="g1">
        <label>Option 1</label>
    </fieldset>
    <fieldset>
        <input type="checkbox" name="checkthing" value="g2">
        <label>Option 2</label>
    </fieldset>
    <fieldset>
        <input type="checkbox" name="checkthing" value="e1">
        <label>Option 3</label>
    </fieldset>
    <fieldset>
        <input type="checkbox" name="checkthing" value="e2">
        <label>Option 4</label>
    </fieldset>

    <a data-column="1" href="link here" style="color: green;">Text</a> <br>
    <a data-column="2" href="link here">Text</a> <br>
    <a data-column="3" href="link here" style="color: green;">Text</a> <br>
    <a data-column="4" href="link here">Text</a> <br>

    <button type="submit" name="save">
      <i class="ft-check"></i> Save
    </button>
</form>

When href got a style, it means that is customized for the user.当 href 得到一个样式时,这意味着它是为用户定制的。 What I want is to store the data-column ID for that user but I am not sure how I can achieve that through PHP.我想要的是存储该用户的数据列 ID,但我不确定如何通过 PHP 实现这一点。

So for the above example I would store the checked checkboxes + data-column 1 + 3.因此,对于上面的示例,我将存储选中的复选框 + 数据列 1 + 3。

You could create a hidden form element with javascript like this, and pull it off when the form is submitted as $_POST['style_ele']您可以像这样使用 javascript 创建一个隐藏的表单元素,并在表单提交为$_POST['style_ele']时将其关闭

$("form.form").find("a").each(function(){
    if($(this).attr("style")!==undefined){
        $("form.form").append("<input type='hidden' name='style_ele[]' value='"+$(this).data('column')+"'/>");
    }
});

But, if you are generating that style attribute from server-side code like php, you could just create additional hidden input along with the a tag但是,如果您从服务器端代码(如 php)生成样式属性,您可以只创建附加隐藏输入以及a标签

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

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