• Resolved ilan76

    (@ilan76)


    Hi,

    I seem to be missing something in getting the form fields.

    When using:

    $url = $_POST[‘url-1’]; and sending this variable to 3rd party API it working ok.

    When using:

    $fields = Forminator_API::get_form_fields($form_id);

    ? ? $url = null;

        foreach ($fields as $field) {

            if ($field[‘element_id’] === ‘url-1’) {

    ? ? ? ? ? ? $url = $field[‘value’];

                break;

            }

    and sending the $url to the same API, I get an error.
    Am Igetting the value fields method correctly?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @ilan76

    Hope you are doing fine!

    The method “Forminator_API::get_form_fields” method will return each field definition as an object, once you detect the field you need to retrieve the data for, you can use the $data array to retrieve the value based on the slug (id of the field). Please see attached code example.

    $form_fields = Forminator_API::get_form_fields( $form_id );
    
        $url = null;
    
        foreach($form_fields as $form_field){
     
    
            if ($form_field->slug === 'url-1') {
    
                $url = $data[$form_field->slug];          
    
                break;
    
            }
        }

    Hope this information helps.

    Kind regards

    Luis

    Thread Starter ilan76

    (@ilan76)

    Hi Luis @wpmudev-support7, thanks for your quick response.

    I tried this code but it still doesn’t work.

    The $url value still gives error, is it type string?

    Where can I see more examples in the Docs for relevant code? couldn’t find this code snippet…

    Thanks

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    H i@ilan76,

    Could you please share the full code which you are trying?

    Where can I see more examples in the Docs for relevant code? couldn’t find this code snippet…

    We only have documentation regarding the methods, please check the following:

    https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/

    If you looking for demo you could browser through our Github:

    https://gist.github.com/wpmudev-sls

    You can find some example usages:

    https://gist.github.com/wpmudev-sls/d6f5bfbf17af7d5edf972e863aa0e01a

    https://gist.github.com/wpmudev-sls/f0eb6e21bde7d5340f8aa904a7ec92e7

    https://gist.github.com/wpmudev-sls/d2ddb3712bcb332b3e9630f600cc6f7d

    Please do note the above example shared isn’t directly related to the query and is only meant to highlight the usage of the mentioned methods.

    Please do let us know if it helps in moving forward.

    Kind Regards,

    Nithin

    Thread Starter ilan76

    (@ilan76)

    Hi Nithin @wpmudevsupport11,

    That is the code:

    $form_fields = Forminator_API::get_form_fields( $form_id );

    $url = null;

    foreach($form_fields as $form_field){

    if ($form_field->slug === ‘url-1’) {

    $url = $data[$form_field->slug];

    break;

    }

    }

    And then sending the $url to other functions/API… the url doesn’t get the value.

    However, when using with POST, it works correctly:

    $url = $_POST[‘url-1’];

    • This reply was modified 1 year, 8 months ago by ilan76.
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ilan76

    Thanks for response!

    I read this entire thread and I think there’s a bit of misunderstanding here (including on our end, for which I apologize).

    The “get_form_fields()” API methiod will not ever give you a “value” of the URL field because it doesn’t get the value. It returns form fields but not submission data.

    What you are trying to do, if I correctly understand, is sending data from the form to external API upon form submission, right? These Forminator API methods will not be of use in such case and instead you need to use plugin hooks for this.

    I am not sure on what hook you are actually triggering your code but one of the ways to get the data from the form safely is to use

    a) get_entry() method if you do know submission ID already (so your code is called at the moment that submission ID is already created and available)

    b) or use this code to get all the fields values

    $submitted_data = Forminator_CForm_Front_Action::$prepared_data;

    where you’ll get full data (just “var_dump” it to error log to see structure first) in submitted_data variable

    c) or go with yet another strategy by modifying this ready-to-use code:

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

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @ilan76 ,

    We haven’t heard from you for several days now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting form fields correctly’ is closed to new replies.