• Resolved llosita

    (@llosita)


    Hi!

    I want to save the submissions to a custom post type. Each input value being saved in a different custom field. I found this approach:

    add_filter('forminator_custom_form_submit_field_data', 'custom_form_submit', 11, 2);
    function custom_form_submit($field_data_array, $form_id){
       //Todo: some code
       return $field_data_array;
    }

    But with this solution, if you leave any input field empty it’s not counted in the array, so the next items $field_data_array[7]['value'], true);, 8, 9… will not match the desired custom fields anymore.
    Is there a way to pass all the fields to the array, even if they are left empty? Or is there any other approach (maybe getting each input field by ID?)?

    Thank you!

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @llosita,

    I hope you are keeping well.

    I have pinged the Forminator developers regarding your query and will update you here once we have feedback on this as soon as possible.

    Kind Regards,
    Nebu John

    Thread Starter llosita

    (@llosita)

    Thank you, I am very interested in finding a solution to this issue and I look forward to hearing from you soon.

    Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @llosita

    I think you can use a different filter. Here’s an example:

    add_filter('forminator_custom_form_pseudo_submitted_data', 'custom_form_submit', 11, 3);
    function custom_form_submit( $pseudo_submitted_data, $custom_form, $submitted_data ){
    error_log( print_r( $submitted_data, true ) );
    return $pseudo_submitted_data;
    }

    The “error_log()” line will print out content of $submitted_data to “debug.log” file (if you do have WordPress debugging enabled with DEBUG_LOG set to true) so you’ll see how the data is hyandled.

    You can remove that line in your “real” code as I’ve put it there only for help/debugging purpose.

    Note please: you do need to return the $pseudo_submitted_data but the actual submitted data that you are looking for (so from which you can take submission data and save it in your custom fields) is in $submitted_data.

    Best regards,
    Adam

    Thread Starter llosita

    (@llosita)

    It works fine, except that the function is executed four times!
    So the problem is I get the post inserted four times too. https://pasteboard.co/hpSmMCnaBi1Q.png
    Any idea why this happens or how to solve it?

    Thank you very much

    Plugin Support Imran – WPMU DEV Support

    (@wpmudev-support9)

    Hello @llosita !

    I hope you’re doing well!

    Since the data contains also the forminator_nonce which will be different for each form’s submission, you can use that to check whether that data was already saved and bail out.

    So the process would look like this:

    – iuery posts by forminator_nonce meta field: https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

    – if no posts found – create a new one and add the current forminator_nonce as post meta

    – if post with this forminator_nonce already exists – skip creating a new one and bail out

    Kind regards,
    Pawel

    Thread Starter llosita

    (@llosita)

    Hello Pawel, that’s it, it works and could achieve what I needed, thank you!!

    Telma

    Thread Starter llosita

    (@llosita)

    Hello Pawel @wpmudev-support9, I noticed that the forminator_nonce does not change in each submission. But according to what you said, it should, right? Look at this logs, each submission was form different user in different country:

    [31-Jan-2022 11:49:04 UTC] nonce d561d050e9
    [31-Jan-2022 11:49:05 UTC] new_post 29405

    [31-Jan-2022 12:11:44 UTC] nonce d561d050e9
    [31-Jan-2022 12:11:44 UTC] already_found_post

    [31-Jan-2022 18:48:31 UTC] nonce 174496471f
    [31-Jan-2022 18:48:32 UTC] new_post 29435

    [31-Jan-2022 20:07:39 UTC] nonce 174496471f
    [31-Jan-2022 20:07:39 UTC] already_found_post 174496471f

    [31-Jan-2022 21:01:08 UTC] nonce 174496471f
    [31-Jan-2022 21:01:08 UTC] already_found_post 174496471f

    Anything we can do about it? I need an effective way to pass the new submissions to my custom post type. Thank you!

    Hi @llosita

    Could you export your form, share your custom filter code and your custom fields names so that we could take a closer look at this?

    You can save the generated TXT file in Google Drive or Dropbox and then share with us the URLs so we may look into this.
    Also, share in Google Drive or Dropbox your PHP file which code.

    Kind Regards,
    Kris

    Thread Starter llosita

    (@llosita)

    Hi @wpmudevsupport13 here you have
    https://drive.google.com/drive/folders/1cd400ZXd2E97LM6GvJwFm5HXSaQosoBX?usp=sharing
    Let me know if you need anything else for the check

    (we have 3 forms, 1 for each language, but the error -using the same nonce for more than 1 submission?- happens also on subsequent submissions of the same form/language).

    Thank you for taking a look!

    Hi @llosita

    Thank you for the additional data. I pinged our SLS Team so that they can dig into this issue further for you. We will post an update here as soon as more information is available.

    Please keep in mind that our SLS Team deals with more complicated issues, so it may take a little longer for them to reply here.

    Kind Regards,
    Kris

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @llosita

    Could you please try this code that our SLS team shared?

    https://gist.github.com/patrickfreitasdev/951cd0c5546cec786451f524a87ac71c

    Please, test it first in a Staging/Dev website before of Live Website.

    Best Regards
    Patrick Freitas

    Thread Starter llosita

    (@llosita)

    Hello. It works but now it is passing every submission, even the ones with validation errors. How can I check if there are any errors and only insert the post if no validation errors were found? Thank you very much!

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @llosita

    We pinged our developer to verify your question.

    We will keep you posted.

    Best Regards
    Patrick Freitas

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @llosita

    Could you please describe a bit more about this?

    “Hello. It works but now it is passing every submission, even the ones with validation errors.”

    Are you adding the fields as required but it is bypassing?

    For example, our developer found that in the custom field(ACF) they have a profile as a required field but in the Forminator form, that field is not required.

    Best Regards
    Patrick Freitas

    Thread Starter llosita

    (@llosita)

    Hi, it was when the user used a previously used email that the validation failed, because I am using this filter “limit the submission by email” https://gist.github.com/wpmudev-sls/a516633a168dd4d5c9bc9cdab2e4cc9d !
    So now I’m checking if the email is already found in the existing posts (similar to what I did with the ‘nonce’) and works good. Thanks!!

    I have other question, please. I am able to pass all the fields, like:

    add_post_meta($the_post_id, 'text-3', $submitted_data['text-3'], true);
    add_post_meta($the_post_id, 'date-1', $submitted_data['date-1-day'] . '/' . $submitted_data['date-1-month'] . '/' . $submitted_data['date-1-year'], true);

    But I have no success in trying to pass the upload fields (I would like to pass the file URL).
    error_log( print_r( $submitted_data['upload-1'], true ) );
    error_log( print_r( 'upload url ' . $submitted_data['upload-1']['value']['file']['file_url'], true ) );
    (This returns nothing, “undefined index” or “trying to access array offset on value of type null”). Any ideas? Thank you very much

Viewing 15 replies - 1 through 15 (of 20 total)

The topic ‘Get the values of specific fields, not just as $field_data_array[0]?’ is closed to new replies.