User registration manual approve
-
Hello,
I have created a user registration form and I have set the user approval to be “approved by admin”. In addition, I want to use a code to approve or reject user. Is there anyway to do that?
Regards
Thank you
-
Hello @alwanma27 !
Hope you’re having a good week!
Can you share some additional details on the code you’d like to use in this case to approve the users? Or a workflow to be used, that should work as well.
Warm regards,
PawelHello Pawel,
Thank you for your response. I use this user registration form for my company and In the form i have some field that should be filled ( like the serial number of the user that let me make sure that is one of the company client ) and then this serial number will be send on the form submission to an API and based on the API response i want to accept or reject the user.
Thank you
Have a nice weekendHi @alwanma27
I hope you are doing well.
I believe the best way is to validate it on submit so it doesn’t end up on saving the member submission being an invalid serial.
For this use the forminator_custom_form_submit_errors hook.
A small example:
– Add the serial field, you can map it in the custom keys to keep in the database too https://monosnap.com/file/bgE7UndTIcJpWPlUICYEIBeCkKujlw
Use the bellow hook:
<?php add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) { if( $form_id != 2419 ) { return $submit_errors; } $serial = $_POST['text-2']; // your serial field, update if required. $allowed_keys = '1234'; // Just an example, need to be removed later. $validate = true; // Submit your API here, change the validation field if necessary // ... if( $serial !== '1234' ){ $validate = false; } if( !$validate ){ $submit_errors[]['text-2'] = 'Invalid Serial Key'; } return $submit_errors; },15,3);You will just need to call the API to validate the Key, if it is not valid the hook will prevent the submission and return an error in the serial field.
To use it, we suggest a mu-plugin https://wpmudev.com/blog/wordpress-mu-plugins/
So you know if any submission that is available in WordPress > Forminator > Submissions is good to be approved.
Best Regards
Patrick FreitasHello Patrick,
Thank you for your response i will try it and if i have any questions i will ask here.
Regards
Hello again,
The code has worked but it stop after a while and now it send all submission i don’t know why so if there is another code to try it. Also i have another question can i print the a custom message on the head of the page instead of the error message shown in the figure below:
Thank you
Hi @alwanma27,
Can you please share an export of the form so we can take a closer look at this?
Please find more about how you can export a form here: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export
You should share the export of the form using pastebin.com or Google Drive.
Kind Regards,
Nebu JohnHello,
The export is in the following link: https://pastebin.com/FsGzG1D0
And i have take the same code you shared above:<?php add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) { if( $form_id != 2419 ) { return $submit_errors; } $serial = $_POST['text-2']; // your serial field, update if required. $allowed_keys = '1234'; // Just an example, need to be removed later. $validate = true; // Submit your API here, change the validation field if necessary // ... if( $serial !== '1234' ){ $validate = false; } if( !$validate ){ $submit_errors[]['text-2'] = 'Invalid Serial Key'; } return $submit_errors; },15,3);but when I write anything in serial number it register the user.
Regards
Hi @alwanma27
Thank you for response!
I’m not sure if you shared the code (the custom code, not the form) exactly as you are using it or if you have removed some custom API code but note please:
This code “as is” does not connect to any API and does not do any validation other than checking if serial number is equal to 1234. it’s just “skeleton” code with example of validation.
If you are using it exactly like this, the only case it will return “Invalid Serial Key” is if value of text-2 field is different than 1234; no check in any external API. To make sure, I have just tested it with you form and I can confirm it.
Now, if you need this to actually validate serial with some 3rd-party API, you do need to add entire additional piece of code instead of this part:
// Submit your API here, change the validation field if necessary // ... if( $serial !== '1234' ){ $validate = false; }Your code in this place needs to send
$serialto your API and based on API response it must set$validateto true (if serial is fine) or false (if serial is not fine).If you do already have that, please share a full code instead of this example (just mask/strip any API keys/credentials from it) so we could look into it and test it.
Note please: providing actual custom code to connect and handle any specific 3rd-party API is out of scope of this support.
Kind regards,
AdamHello,
It was an API error so that’s why it stop now it works normally but what about my second question
Also i have another question can i print the a custom message on the head of the page instead of the error message shown in the figure below:
ImageThank you
Hi @alwanma27
Thanks for response!
but what about my second question
I’m sorry, I missed it. Thanks for bringing it up!
You can customize error messages for separate fields directly – if they are set to be required – but there’s currently no setting for entire form.
There’s a filter hook in plugin so you can use a code like this to customize the message:
<?php add_action( 'forminator_custom_form_invalid_form_message', 'my_frmt_custom_error_message', 99, 2); function my_frmt_custom_error_message( $msg, $form_id ) { // if you only want to apply it to certain form(s) // uncommet following 4 lines and add form IDs: //$form_ids = array( 123, 354 ); // list form IDs here //if ( !in_array( $form_id, $form_ids ) ) { // return $msg; //} $msg = "Sorry, form is not correct!"; // put your custom error message here return $msg; }To add the code to the site as a Must Use plugin:
– create an empty file with a .php extension (e.g. “forminator-custom-form-error-message.php”)
– copy and paste code into it
– modify it according to comments in the code
– save the file and upload it (using FTP, cPanel File Manager or similar way) to the “/wp-config/mu-plugins” folder of your site’s WordPress installIt should work out of the box.
Best regards,
AdamHello,
Thank you for your response i will try it and if i have any questions i will ask here.
Regards
Hello,
I am trying to add the serial number and email as entry to another form using Forminator_API::add_form_entries but each time the entry is saved but with blank value for the serial and email. What can i do in this case?
Thank you
Best RegardsHi @alwanma27
Could you please share the entire code where you are using the Forminator_API::add_form_entries can you also try the add form entry instead of entries?
https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/#method-update_form_entry
Unless you are looking to bulk add them?
Best Regards
Patrick FreitasHello,
Please find the code below:
<?php add_filter('forminator_custom_form_submit_errors', function ($submit_errors, $form_id, $field_data_array) { if ($form_id != 120) { return $submit_errors; } $email = $_POST['email-1']; $serial = $_POST['text-2']; $validate = true; // The commented code below is used for communication with API // But i will check the serial without API now because the checking with API //So let's assume that the entered serial is 1234 // $target_url = ; //URL of the Validation API // // Call the API // $response = wp_remote_post( // $target_url, // array( // 'method' => 'POST', // 'timeout' => 45, // 'headers' => array(), // 'body' => json_encode(array( // "Serial" => $serial, // )), // ) // ); if ($serial !== '1234') { $validate = false; } if (!$validate) { $submit_errors[]['text-2'] = 'Invalid Serial Key'; } else { $form_id1 = 76; $entry_meta = array( array( 'name' => 'text2-2', 'value' => $serial ), array( 'name' => 'email-1', 'value' => $email ) ); Forminator_API::add_form_entries($form_id1, $entry_meta); } return $submit_errors; }, 15, 3);In the above code I assume that I have write serial as 1234 and that the validation has done correctly then what happen is that the entry is added to the other form but with blank serial instead of 1234 and blank email. So how can we solve this problem.
Thank You
RegardsHi @alwanma27
Can you please double-check IDs of the fields of that other form?
In your code there’s “text2-2” id which doesn’t look like a legitimate ID in Forminator form so please make sure there’s correct ID used.
Best regards,
Adam
The topic ‘User registration manual approve’ is closed to new replies.