Hi,
I am trying to get a submitted form with errors to keeps it values.
Currently when using the cred form the generated inputs keep their values, which is perfect! But I have a select-input which will be used for tagging, by using selectize.js. The issue here is that when submitting the form which has errors the page reloads displaying the errors and also refilling the form for the inputs defined by the cred_fields but not for the custom select-input. That's normal but not perfect.
I assume that the cred_fields are filled via PHP before they get sent to the browser for rendering. So I wanted to know if there is a way that I can get my select-input modified before rendering? Like a hook maybe?
Thanks a lot for the help!
You can see a list of API functions here:
https://toolset.com/documentation/user-guides/cred-api/
We also have a validation Filter
https://toolset.com/documentation/user-guides/cred-api/#cfv
But those functions act as filters and actions to do things with your information on Form Submit. I'm not sure those can help with your Custom Code you use.
I suspect rather it's an issue with your Select Field and how it's populated, something we can't help with as it's not part of CRED or Toolset.
https://toolset.com/toolset-support-policy/
Let me know if that list of CRED API helps you.
Unfortunately the hook I need would be one that gets called before the form gets sent to be rendered. The current API functions only allows manipulation of the data that had been sent/submitted to the server.
I also noticed that when the form reloads because of an error that the selected files are not refilled. Even if the files inputs are generated via CRED.
I understand that currently there's no way to handle custom inputs which are not generated by CRED but is there at least a way to have the file inputs filled?
All Hooks apply after the form is submitted, as we need something to work with.
It's not possible to do on the fly PHP actions.
The first hook is the validation hook, then the cred_before_save_data, then cred_save_data, after cred_submit_complete and so on.
So, with the cred_before_save_data you can do things before they get saved into the DDBB.
Regarding the Fields unset on error trigger, this is solved in the next CRED release.
Do you need more help with the issue on this thread?
Hi,
if I understand correct then I can modify the data with cred_before_save_data which will also be showed changed when the form gets displayed again with an error? E.g
1. user submits form
2. some input values (current date format: dd/mm/yyyy) gets changed (new date format: dd.mm.yyyy) with the cred_before_save_data hook
3. in php an error will be set because some data (email format) are wrong
4. the form gets rendered in the browser with the changed date format (new date format: dd.mm.yyyy) and the error that the email format is wrong
Is this correct?
cred_before_save_data performs your actions custom action right before saving or processing any data but AFTER validation.
The issue with the things that are not selected, or values lost, on validation, when you submit the form, is a BUG, as I elaborated above, and will be addressed in the upcoming CRED release.
The validation is the first thing triggered and it will not update anything to the Database at this moment.
If you want to change the Forms value you need to address $POST (form data)
This is not included in the CRED API.
I will wait for the update.
And ok, I was hoping to find another solution than with the $_POST var.
Thanks anyway!
@Beda
i look forward to this update too. currently have users trying to submit posts through cred, and they all have trouble as when a single mistake in url or link will reset many fields, and some users either dont notice or simply give up. make me not use the whole CRED and forms for my website because of this. looking for workaround now.
urgently needs an update or workaround, at least to allow display error message on the fly before submitting the form or not resetting all the fields when form submitted with error.
fingers crossed