Jump to content

Recommended Posts

Posted

Hello!

I have a Question regarding the procesInputDone hook.

After Submitting a certain form, i want to get all the Fields of that form and turn them into a Json File. My first idea was to approach the Code like this:

$wire->addHookAfter('FormBuilderProcessor::processInputDone', function(HookEvent $event) {

        $form = $event->arguments(0); 

        if ($form->isSubmitted()) {
                                                             
            $formValues = $form->getAll();
            $formData = [];

            foreach ($form->getAll() as $field) {
                $fieldName = $field->name;
                $formData[$fieldName] = $form->getChildByName($fieldName)->value;
            }

            if (!empty($formData)) {
                $jsonData = json_encode($formData);                                                        
                $jsonFileName = uniqid() . '.json';
                $jsonFilePath = wire('config')->paths->assets . 'json/' . $jsonFileName;
                file_put_contents($jsonFilePath, $jsonData);      
            }   
        }
...

The only problem with this is, that a Pagebreak in the Form results in the JSON file only having the last page entries.

My only question is how to avoid this issue or is there a better approach to getting a json file ready of the form submit in a hook?

Posted

Since this is FormBuilder, you should move this to the paid FormBuilder forum. If you have an active license, you can post there and should get support.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...