This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 4

Not setting Session cookie when embedded with PHP


  1. slcmarcomm
    Member

    I've embedded my form using the PHP embedder, which is what I want to do so that people without JS can use the form.

    However, it seems that it's not setting the Session cookie at all. This means that when I submit the form, it still shows me the form, instead of showing me the "Thank you" text, even though the URL has "done=1".

    Is there something I need to configure on the server for this? Or something else that needs to be done? Here's the PHP info: https://www.dropbox.com/s/gly0nyhlsi99zkx/Screenshot%202015-05-20%2009.46.05.png?dl=0

    Posted 8 years ago #
  2. Steve1951
    Member

    Make sure the first line of your PHP script contains

    <?php session_start(); ?>

    Posted 8 years ago #
  3. slcmarcomm
    Member

    I discovered it's happening because session_start() will only send cookies if there's nothing output before it on the page (and headers need to be sent before content). But since the form is included on a page that has already printed a lot of HTML, the cookies were unable to be set, and so the $_SESSION['mf_form_completed'] remained empty.

    To fix this, I edited the view-functions.php to add a <script>Cookies.set("PHPSESSID","{$session_id}",{ expires: 1, path: "/" });</script> to the page and had previously included the Cookies plugin: https://github.com/js-cookie/js-cookie

    Posted 8 years ago #

RSS feed for this topic

Reply