• Resolved jdbertron

    (@jdbertron)


    Hi,

    My site is using Forminator.
    I need to calculate the hash of another field {text-1} as a new field that will be saved. I looked into calculation fields, but they only accept numerical values, and won’t have the hash256 I need.
    I tried creating my own Forminator Add-On, adding a filter (inspired from this post https://wordpress.org/support/topic/how-to-get-wordpress-post-id-from-forminator-form-not-page-id/) to override the value of my new field {calculation-1} with the correct php calculation, but it’s not working.
    See code below.

    Is there a document that explains the flow of forminator ?

    add_filter( 
    	'forminator_bqeth_form_override_hash', 
    	function( $submit_errors, $form_id, $field_data_array ) {
    		$text1 = '';
    		var_dump($field_data_array);
    		foreach( $field_data_array as $field ) {
    			if ( ! isset( $field[ 'name' ] ) ||  ! isset( $field[ 'value' ] )|| $isbn_field !== $field[ 'name' ] ) {
    				continue;
    			}
    			if ( isset( $field[ 'name' ] ) && $field['name'] == 'text-1') {
    				$text1 = $field['value'];
    			}
    		}
    		foreach( $field_data_array as $field ) {
    			if ( ! isset( $field[ 'name' ] ) ||  ! isset( $field[ 'value' ] )|| $isbn_field !== $field[ 'name' ] ) {
    				continue;
    			}
    			if ( isset( $field[ 'name' ] ) && $field['name'] == 'calculation-1') {
    				$field['value'] = hash('sha256', $text1, true);
    			}
    		}
    		return $submit_errors;
    	}, 
    	20, 3 
    );

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter jdbertron

    (@jdbertron)

    BTW, I’m also looking at this, trying to make sense of how this works.
    https://github.com/pentatonicfunk/forminator-addon-yafa-plugin

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @jdbertron

    I hope you are doing well.

    That shared addon is from 5 years ago, I checked this but some functions are no longer in the plugin so installing it would probably cause a fatal error or won’t work.

    The filter found in the other thread forminator_custom_form_submit_errors is used to validate the submission, but I am afraid we can’t create a new filter in that easy way, the plugin developers need to implement specific hooks to be used.

    But if the hash is created after submission you can use this code https://gist.github.com/wpmudev-sls/e3e4655e9ad74686051393a1d0ed5ffa to get started, it replaces the hidden-X field with a unique key which is quite similar what you are looking for.

    Best Regards
    Patrick Freitas

    Thread Starter jdbertron

    (@jdbertron)

    Thank you very much !
    This will work perfectly.

    Thread Starter jdbertron

    (@jdbertron)

    Ok, that worked, but now, what I really wanted was to use this hidden-1 field in the redirect behavior, but it looks like that value gets replaced before I have a chance to calculate it. Is there another hook I can use that would give me a chance to calculate the value and save it before the redirect replacement ?

    Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @jdbertron

    Thank you for response and additional information.

    I asked our developers if it would be possible to modify this code somehow to make it work for redirects.

    I’d rather not make promises at this point as it’s a custom code and requires custom changes (development) but if it’s doable without any complex changes or changes in plugin – we’ll share updated code.

    We’ll let you know here soon but I’d appreciate some patience.

    Best regards,
    Adam

    Thread Starter jdbertron

    (@jdbertron)

    Well, I got it working. I had to learn how forminator works.
    It turns out one of the payment filters allows that early substitution.
    For anyone looking for something similar:
    https://github.com/BqETH/forminator-bqeth-hash

    Thanks for you help !

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Forminator: how to create hidden hash field’ is closed to new replies.