|
Setting minimum characters in text search
Started by: emilyT
in: Toolset Professional Support
Quick solution available
Problem:
Customer would like to set a minimum character limit on the search box - so for example you have to enter at least 10 characters before the search will work.
Solution:
To implement the feature of disabling the submit button until there are more than 10 characters in the search box, please add and customize the following JavaScript code in your CRED form's JS box:
jQuery(document).ready(function($) {
// Reference to the search field and submit button
var $searchField = $('input[name="wpv_post_search"]');
var $submitButton = $('input[name="wpv_filter_submit"]');
// Initially disable the submit button
$submitButton.prop('disabled', true);
// Event handler for keyup on the search field
$searchField.on('keyup', function() {
var minLength = 10;
var currentLength = $(this).val().length;
// Enable or disable the submit button based on the character count
if(currentLength >= minLength) {
$submitButton.prop('disabled', false);
} else {
$submitButton.prop('disabled', true);
}
});
});
In the code above:
- The search field is referenced by its name, wpv_post_search.
- The submit button is referenced by its name, wpv_filter_submit.
- The script initially disables the submit button.
- It enables the button only when the character count in the search field is 10 or more.
|
|
2 |
3 |
10 months, 1 week ago
Mateus Getulio
|
|
converting user_email field from a register form to lowercase
Started by: davidA-16
in: Toolset Professional Support
Quick solution available
Problem:
Tell us what you are trying to do?
ensure a user_email field from a register form is saved as lowercase
Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data
Is there a similar example that we can see?
trying this:
add_action('cred_before_save_data', 'my_before_save_data_action',10,1);
function my_before_save_data_action($form_data)
{
// if a specific form
// 61544 = register form v2
if ($form_data['id']== 61544)
{
if (isset($_POST['user_email']))
{
$lowercaseemail = strtolower($_POST['user_email']);
$_POST['user_email'] = $lowercaseemail;
}
}
}
Solution:
The approach you took is correct, I believe the issue might be with the missing 'wpcf' prefix in the field selection.
Can you please try the following code to see if it achieves what you need?
add_action("cred_before_save_data", "my_before_save_data_action", 10, 1);
function my_before_save_data_action($form_data)
{
// if a specific form
// 61544 = register form v2
if ($form_data["id"] == 61544) {
if (isset($_POST["user_email"])) {
$lowercaseemail = strtolower($_POST["user_email"]);
$_POST["wpcf-user_email"] = $lowercaseemail;
}
}
}
|
|
2 |
2 |
11 months, 1 week ago
Mateus Getulio
|