• Resolved hollosipeter

    (@hollosipeter)


    Hello! There is an external PHP system. I would like to achieve that after pressing the “SUBMIT” button of the Forminator, after the validations have been completed, send the data to the external system in a JSON message (not only the normal mandatory fields are validated, other codes are also running in the background, so I want that data sending after Forminator form gets “success” status, so after submitting the form.
    However, I see that the sending doesn’t even start: I also tried an AJAX call. Could you help me with the correct action?
    I am attaching the IMPORT file of the external system and the EXPORT mu-plugin file uploaded to WordPress.
    The type of the form is normal, so it is not user registration type.

    PASTEBIN – 3rd party system: IMPORT file:
    https://pastebin.com/cGQPuRMB

    PASTEBIN – WordPress system: EXPORT file (mu-plugin)
    https://pastebin.com/iVCQBw8S

    Thanks:
    Peter

    • This topic was modified 1 year, 2 months ago by hollosipeter.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @hollosipeter,

    Please do note that such setups are highly custom and troubleshooting the code is outside our scope.

    However, there are a couple of aspects which we could pinpoint. I could see you are using an action called “forminator_custom_form_after_handle_submit”, there isn’t any such action in the plugin.

    The following action would be a better approach:
    forminator_form_after_handle_submit

    The above hook will only work with Page Reload “Method” once enabled under Behaviour Tab when you edit the form.

    A better approach would be to use the following snippet which sends JSON:
    https://gist.github.com/wpmudev-sls/4b2a0b9063156afa302349916e019d3a

    The following line in the above snippet, ie:

    $data[$value['name']] = $value['value'];

    Can be replaced as follows:

    if ( $value['name'] == 'email-1' ) {
        $data['emailcim'] = $value['value'];
    } else if ( $value['name'] == 'date-1' ) {
        $data['szulinap'] = $value['value'];
    } else if ( $value['name'] == 'phone-1' ) {
        $data['telefon'] = $value['value'];
    } else if ( $value['name'] == 'name-1-first-name' ) {
        $data['keresztnev'] = $value['value'];
    } else if ( $value['name'] == 'name-1-last-name' ) {
        $data['vezeteknev'] = $value['value'];
    }
    

    The Your_API_URL in the above snippet would be the full URL which you have added in the code form action ie to accessctrl_import.php

    Could you please check and see whether the above snippet helps? The snippet can be implemented as a mu-plugins.

    I hope the above helps in moving forward.

    Kind Regards,

    Nithin

    Thread Starter hollosipeter

    (@hollosipeter)

    Hello Nithin!

    Thank you, I tried. It is no json sent if I’m checking the console.
    BTW the 3rd party system needs a form method, with name=action, value=user & name=data value=$json_data

    so kinda this – but if I combine this with your CURL call code, “error”. But if I’m using your code 100% just changing the API, and module_id to my form_id, on the console I didn’t see any message sent ??

    Do you have some idea maybe? You already see what the import code needs but I want that forminator submit gets the reaction and send the json.

    Thank you,
    Peter

    $json_data = esc_attr($jsonEncodedData);
    
    // HTML ?rlap létrehozása
    $form = '<form method="POST" action="https://accessctrl.bachatasensual.hu/accessctrl_import.php">
    <input type="hidden" name="action" value="user">
    <input type="hidden" name="data" value="' . $json_data . '">
    <input type="submit" value="Submit">
    </form>';
    
    echo $form;
    Thread Starter hollosipeter

    (@hollosipeter)

    Hello!

    Now I can receive JSON datas, but your solution not gives me the first name and the last name. Only the other fields receiving to the 3rd party system.

    So what should I change in this?
    Thank you

    if ( $value['name'] == 'email-1' ) {
        $data['emailcim'] = $value['value'];
    } else if ( $value['name'] == 'date-1' ) {
        $data['szulinap'] = $value['value'];
    } else if ( $value['name'] == 'phone-1' ) {
        $data['telefon'] = $value['value'];
    } else if ( $value['name'] == 'name-1-first-name' ) {
        $data['keresztnev'] = $value['value'];
    } else if ( $value['name'] == 'name-1-last-name' ) {
        $data['vezeteknev'] = $value['value'];
    }
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @hollosipeter

    Thank you for response!

    Could you share export of your form so we could test and check it closer?

    To export the form:
    – go to the “Forminator -> Forms” page
    – click on a little “gear” icon next to the form in question and select “Export” option
    – copy export code from there and put it at https://pastebin.com
    – share link to that paste in response below.

    We’d then be able to better test it to see what’s happening.

    Meanwhile, you may also check this code as alternative:

    https://gist.github.com/adczk/a314ad50036ffd449147d28f2e876e2b

    It’s a bit different solution but pretty universal so may be worth testing too.

    Best regards,
    Adam

    Thread Starter hollosipeter

    (@hollosipeter)

    Hello Adam!

    Thank you for your response.

    I have seen many times that if the last name and first name are multiple values in the forminator, then name-1-last-name and name-1-first name are useless, nothing recognizes them when sending data. I have now created a name-2, both fields are SINGLE, so when sending JSON, the JSON last name and first name go separately.
    Since the form has already been modified and is live, I cannot export it, but it can be treated as a general error if you test it, if it has multiple names, it does not like to send it when sending data.
    Thanks!

    Best regards:
    Peter

    Plugin Support Laura – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @hollosipeter,

    Hope this message finds you well and thanks for the update.

    As Adam explained we really need to test the form and code in order to escalate to our Developers, could you please clone the form, remove all the sensitive data or other data you consider important, and share the cloned form export file? And please attach the last code (mu-plugin).

    Thanks for your collaboration on this.

    Best regards,
    Laura

    Thread Starter hollosipeter

    (@hollosipeter)

    Hi Laura!

    Now I have a working code because I set the last name and first name in separate forminator name fields. I export the form, but it already has name-1 and name-2 fields, delete name-2 and change name-1 to name-1-last-name and name-1-first-name form , then check, with the code, it does not send export. This is also true if, for example, I want to fill out a usermeta table with the forminator even on a contact form, the format name-1-first-name and name-1-last-name cannot be added, it is not allowed, only separate name-1, name-2.

    Code:
    https://pastebin.com/L6MiDBFG

    Form:
    https://pastebin.com/BhrNHvaW

    Thanks:
    Peter

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @hollosipeter

    Thank you, it’s clear now.

    The structure of the name field data (and that also applies to other “combined” fields like e.g. “address” type field) is a bit different and the data is stored in “subfields” that are reflected in data array as additional “sub-array” of the “value”.

    So basically dataq structure for such name field would be like this:

    [name] => name-1
                [value] => Array
                    (
                        [prefix] => Mr
                        [first-name] => John
                        [middle-name] => Test
                        [last-name] => Doe
                    )

    Therefore you need to modify your code a bit and this block

    if ( isset( $value['name'] ) ) {
    if ( $value['name'] == 'email-1' ) {
        $data['emailcim'] = $value['value'];
    } else if ( $value['name'] == 'date-1' ) {
        $data['szulinap'] = $value['value'];
    } else if ( $value['name'] == 'phone-1' ) {
        $data['telefon'] = $value['value'];
    } else if ( $value['name'] == 'name-1-last-name' ) {
        $data['vezeteknev'] = $value['value'];
    } else if ( $value['name'] == 'name-1-first-name' ) {
        $data['keresztnev'] = $value['value'];
    } else if ( $value['name'] == 'radio-1' ) {
        $data['danceclass'] = $value['value'];
    } else if ( $value['name'] == 'radio-5' ) {
        $data['neme'] = $value['value'];
    }
    }

    would become like this:

    if ( isset( $value['name'] ) ) {
    if ( $value['name'] == 'email-1' ) {
        $data['emailcim'] = $value['value'];
    } else if ( $value['name'] == 'date-1' ) {
        $data['szulinap'] = $value['value'];
    } else if ( $value['name'] == 'phone-1' ) {
        $data['telefon'] = $value['value'];
    } else if ( $value['name'] == ['name-1'] {
    	$data['vezeteknev'] = $value['value']['last-name'];	
    	$data['keresztnev'] = $value['value']['first-name'];							
    } else if ( $value['name'] == 'radio-1' ) {
        $data['danceclass'] = $value['value'];
    } else if ( $value['name'] == 'radio-5' ) {
        $data['neme'] = $value['value'];
    }
    }

    Best regards,
    Adam

    Thread Starter hollosipeter

    (@hollosipeter)

    Hi Adam!
    I see, so this is sub-arrays. I will use this way. Super, thank you so much for your help! ??

    Regards,
    Peter

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Forminator submit – JSON DATA send’ is closed to new replies.