duanguan3863 2014-07-21 14:30
浏览 17

表单完成后设置会话

I am adding in a form with just 2 radio buttons using Perch CMS and trying to stop it from having the option of resubmitting the form after it has been submitted once during a session by finding the success code of <!--@@^^res@@^^-->

I have the session start above all other code and also above my but cannot get it to work properly.

My code is as follows which in my head says if the session is equal to submitted then the success code is there and so will not show the content however if there is not session set then the success code is not there and therefore requires the content to be displayed. Once the form is submitted and the success code is output, a session of submitted is then created...

<?php if (isset($_SESSION['survey']) == 'submitted')
echo (strpos($content,'<!--@@^^res@@^^-->')!=false);
 else {
        $content = perch_content('Survey',true);
    echo str_replace('<!--@@^^res@@^^-->','',$content);

    if (strpos($content,'<!--@@^^res@@^^-->')!=true) {
        $_SESSION['survey'] = 'submitted'; 
    };
 };
    ?>

I noticed that this works upon load as in I get the form there but when I change page it disappears as well as after filling out the form.

tried Googling this but cannot get my head round where I am going wrong, any help is greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dongyi1215 2014-07-22 09:33
    关注

    Thanks to the help of CBroe advising me that strpos can never return true I have done a bit more messing around and reading up on strpos and found the following code works...

    <?php if (isset($_SESSION['survey']) == 'submitted')
    echo (strpos($content,'<!--@@^^res@@^^-->')!=true);
     else {
            $content = perch_content('Survey',true);
        echo str_replace('<!--@@^^res@@^^-->','',$content);
    
        if (strpos($content,'<!--@@^^res@@^^-->')!==false) {
            $_SESSION['survey'] = 'submitted'; 
        };
     };
        ?>
    

    All left to do now is to stop 1 being displayed in the area whilst the session is active.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)