Post Data max word count
-
Hi, is there a way to set a maximum word/character count for the “Post Data” field? The option is available for the text field input but not (that I can see) for the post data/content field.
-
Hi @scrappydoo,
Could you please explain further about which exact field you are referring to in the “Post Data? Is it with Title etc?
What “Post Data” does is create post types and any limitations implemented are part of the post types in WP rather than in Post Data.
If you could explain further about which field you are referring and the maximum count you are looking to add, it would help give us a better idea.
Looking forward to your resposne.
Kind Regards,
Nithin
Hi Nithin,
Sorry I wasn’t clear, it’s the “content” and/or “title” fields where I want to limit the character length to e.g. 200 characters.
Hi @scrappydoo,
I hope this message finds you well.
As mentioned in our previous response, any limitations applied are part of the post types in WordPress. Forminator does not provide an option to limit the character length of the “Title” or “Content” of posts.
To restrict the post title length, you can use the “the_title” filter. Similarly, for the content, you can use the “the_content” filter to limit the post content length.
Unfortunately, providing the exact code falls outside the scope of support we can offer. To get the required custom code, you would need to hire a developer. You can find developers through the WordPress jobs directory at https://jobs.wordpress.net/. If you need further advice, feel free to email [email protected] using the following subject.
Subject: ATTN: WPMU DEV support - wp.orgKind Regards,
Nebu JohnI managed to do it with JavaScript. If the user enters more than “x” amount of characters it gives an error and doesn’t allow the form to submit.
Hi @scrappydoo,
It’s great to hear that you found a solution using JavaScript! Feel free to share the code here so it can benefit other users who might be looking for a similar option.
Since you have found a solution, I will close this topic. If you need any further assistance, please don’t hesitate to open a new topic—we’re always happy to help.
Kind Regards,
Nebu John// Wait for the DOM to load before adding event listeners
document.addEventListener("DOMContentLoaded", function() {
// Get the submit button using its class
var submitButton = document.querySelector('.forminator-button-submit');
// Add a click event listener to the submit button
submitButton.addEventListener('click', function(event) {
// Get the text field by its name (postdata-1-post-title)
var textField = document.querySelector('input[name="postdata-1-post-title"]');
// Get the form element
var form = document.getElementById('forminator-module-2246');
// Check if the text field value is greater than or equal to 400 characters
if (textField.value.length >= 400) {
// Prevent the form from submitting
event.preventDefault();
// Find and remove any existing error message
var existingErrorMessage = form.querySelector('.error-message');
if (existingErrorMessage) {
existingErrorMessage.remove();
}
// Create a new error message element
var errorMessage = document.createElement('div');
errorMessage.classList.add('error-message'); // You can style this class later
errorMessage.style.color = 'red';
errorMessage.textContent = 'Error: The text must be less than 400 characters!';
// Append the error message to the form
form.appendChild(errorMessage);
}
});
});
The topic ‘Post Data max word count’ is closed to new replies.