Created
April 28, 2022 17:46
-
-
Save patrickfreitasdev/994f657889934e2c78e1038ea75a9058 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; } | |
| add_action( 'plugins_loaded', 'wpmudev_forminator_add_custom_number_to_redirect_url_func', 100 ); | |
| function wpmudev_forminator_add_custom_number_to_redirect_url_func() { | |
| if ( class_exists( 'Forminator' ) ) { | |
| class WPMUDEV_Forminator_Add_Entry_ID_To_Redirect_URL{ | |
| private $form_id = 1639;//enter form_id here | |
| private $redirect_url = 'https://yoursite.com/';//enter your redirect url here, it must be matches with the link you added on the form | |
| private $total_length = ''; | |
| public function __construct(){ | |
| add_action( 'forminator_custom_form_submit_before_set_fields', array( $this, 'calculate_length' ), 10, 2 ); | |
| add_filter( 'forminator_replace_form_data', array( $this, 'add_length_to_redirect_url'), 20, 1 ); | |
| } | |
| public function calculate_length( $entry, $form_id ){ | |
| if( $this->form_id == $form_id ){ | |
| $first_field = $_POST['text-1']; | |
| $second_field = $_POST['text-2']; | |
| $this->total_length = strlen( $first_field) + strlen( $second_field ); | |
| } | |
| } | |
| public function add_length_to_redirect_url( $content ){ | |
| if( $this->total_length && $this->redirect_url === $content ){ | |
| $content = add_query_arg('total_length', $this->total_length, $content); | |
| } | |
| return $content; | |
| } | |
| } | |
| $run = new WPMUDEV_Forminator_Add_Entry_ID_To_Redirect_URL; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Patrick boa tarde, meu nome è Lorenzo, foi è que te pedi em worpress.org sobre este tema. Acho que meu post ficou perdido la, nao conseguimos implementa-lo mais ainda que funcionase redirecionando para uma pagina, nao sei como resolver se preciso redirecionar para uma das 3 paginas, me baseando no suma do lenght.
So te copiando aqui para resumir o que estoui tentando fazer:
I have page https://www.meurelacionamento.tk/forminator/ where user will insert the 2 strings
Once he submits he will redirected to one of the 3 pages according to the sum of the len of 2 strings
https://www.meurelacionamento.tk/forminatorlp1/ if sum <=4
https://www.meurelacionamento.tk/forminatorlp2/ if sum <4<8
https://www.meurelacionamento.tk/forminatorlp3/ if sum >=8
And the result of the sum should be displayed under the text that says
“And the sum is here below displayed”