formtools / module-form_builder

The Form Builder module.
https://docs.formtools.org/modules/form_builder/
15 stars 21 forks source link

Online Forms not progressing to next page on clicking continue #15

Closed Ne0-d3gen closed 6 years ago

Ne0-d3gen commented 6 years ago

Hey @benkeen. I have just encountered a problem with online forms using formbuilder module. Not sure which update has introduced this problem because I haven't tested for a while and initially, a few months ago, my online forms were working perfectly.

Now I create an online form including a review page and thank you page. These pages are all rendering fine in the formbuilder preview window.

When I go to my form online and complete all the required fields then click on the continue button, I expect that the review page should appear however instead, the original form page is reloaded with all fields reset to blank.

The address in my browser bar has updated from myform.php to myform.php?page=2 but page is still displaying the original form i.e. page 1. There are no errors on my form or any errors in my console.

Any idea why this has started happening?

Ne0-d3gen commented 6 years ago

@benkeen, something is not right with this. I have found out that by using the publication settings to change the file name makes the online form work correctly again. You can then change the file name back to the original using publication settings and again, it is now working. Unfortunately, I have a large number of forms and don't want to have to change and then revert back to original file name for all of them to work.

Any suggestions?

benkeen commented 6 years ago

Hmm... there was an issue that required renaming the file to a different filename, then back again. But I thought it was only in a particularly unlikely scenario so I wasn't worried about it.

Could you try looking at the source .php for a form that's broken, renaming it via the UI, then renaming it back & compare it with the original source? I'm curious to know what exactly changed.

Approximately how many forms do you have?

benkeen commented 6 years ago

Actually, give me an hour or two and I'll see what I can come up with as a workaround. This was my mistake - it'll only affect users from the earlier alpha/beta, but I should write a patch.

benkeen commented 6 years ago

Hey @tomheaps, try this.

Create a file called regenerate.php and place it in the Form Tools root, and give it this content:

<?php

require_once("global/library.php");

use FormTools\Core;
use FormTools\Modules;
use FormTools\Modules\FormBuilder\Forms;

Core::init();
$db = Core::$db;

$module = Modules::instantiateModule("form_builder");

$db->query("
    SELECT *
    FROM {PREFIX}module_form_builder_forms
");
$db->execute();

foreach ($db->fetchAll() as $published_form) {
    if (empty($published_form["publish_date"])) {
        continue;
    }

    $folder_path = $published_form["folder_path"];
    $filename = $published_form["filename"];
    $file_plus_path = "$folder_path/$filename";
    $published_form_id = $published_form["published_form_id"];

    if (!file_exists($file_plus_path)) {
        continue;
    }

    $content = Forms::getGeneratedFormContent($published_form_id, $filename);
    unlink($file_plus_path);
    if ($fh = fopen($file_plus_path, 'w')) {
        fwrite($fh, $content);
        fclose($fh);
    }
}

That just examines your published form table, pull out the "live" forms (the ones with an actual form that's been created) and regenerate them. Just open it up in your web browser and it should recreate all your forms with the correct content.

Hope this helps, and sorry for the fuss!

Ne0-d3gen commented 6 years ago

Thank you so much @benkeen - this has done the trick perfectly and saved me loads of time - I have over 100 online forms that I would have needed to rename and rename again!

Is this problem likely to recur or was it just the consequence of a specific upgrade?

benkeen commented 6 years ago

Oops, sorry for not getting back to you sooner. It's a one-off issue - it won't occur again. Glad it came in handy!