duanbai1370 2013-05-07 13:59
浏览 78
已采纳

在wordpress中提交按钮后设置cookie

I am not even sure if it is cookies I need here, perhaps there is a better method.

I currently have a page with links for downloads. To get to this page the user will have to submit their email address. I am using the plugin Contact Form 7 for the email entry. I then plan on redirecting this to the page. The plugin allows me to add IDs to the submit button.

Should I be setting a cookie here using JavaScript? I won't be able to put JavaScript into the form, but I can have the form on my own page template.

Heres the outputted html, Im reluctant to go and try and change this as its a plugin..

<form action="/downloads/#wpcf7-f127-p124-o1" method="post" class="wpcf7-form" novalidate="novalidate">

<div style="display: none;">

<input type="hidden" name="_wpcf7" value="127" />
<input type="hidden" name="_wpcf7_version" value="3.4" />
<input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f127-p124-o1" />
<input type="hidden" name="_wpnonce" value="211b6bff7f" />

</div>

<p>Your Name (required)<br />

<span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" /></span> </p>

<p>Your Email (required)<br />

<span class="wpcf7-form-control-wrap your-email"><input type="email" name="your-email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" /></span> </p>

<p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" /></p>

<div class="wpcf7-response-output wpcf7-display-none"></div>

  • 写回答

1条回答 默认 最新

  • dongli7870 2013-05-07 14:05
    关注

    Use a $_SESSION variable to determine whether or not the user has set an email. Cookies can easily be changed or removed by the user. Of course, in this case you wouldn't need to fear the latter, but you get the point. SESSION vars, on the other hand, are not going to be editable by any user of your application.

    Example HTML:

    <form method="post">
        <input type="email" placeholder="Enter email here..." name="email" />
    </form>
    

    Example PHP

    if(isset($_POST['email'])){
        // Set the session val
        $_SESSION['user_email_set'] = true;
    }
    
    // Check if user entered email
    
    if(isset($_SESSION['user_email_set']) && $_SESSION['user_email_set']){
        // Show downloads page
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配