0

We have a special date field that we set upon user creation when our custom user form is submitted. The user does not have to set this field themselves.

We have a separate form, which is a user edit form. We build this form using a form_alter() hook that looks for the default user register form.

For some reason, even though this special date field is hidden on this form, validation runs against it as if the form has been submitted with a blank value, and we get the error (on the frontend of the form)

There are errors in verification code created on value #1: The dates are invalid.

I found a way that "works" to get around this,

$form["field_special_field_created_"]['und'][0]['#element_validate'] = '';

But I think that this is pretty ugly. Why only this field? why can't this field retain its original value?

Since this special field date needs to stay the same, I need to find a way to make it work like the other fields do.

3
  • Does your form_alter hook add the hidden field to the form? If so, please add that code to your question. What happens if the field is a type other than hidden? Commented Jan 18, 2020 at 7:23
  • It does not, the field is there because its a field on the user object. The other fields (non-date fields) are not causing me any problems, they retain their previous value, Commented Jan 19, 2020 at 21:26
  • You're not giving us much to work with. Without specific details (code) it's hard to give a specific answer. Generally speaking, there has to be something that gets the existing value for that field from the database. There has to be something that assigns the value from the database to the #default_value of the field, and in the right format for that field. When submitted, the value needs to be in the right format for it to pass validation. If one or more of those things are missing or incorrect then that could explain your problem. Commented Jan 20, 2020 at 4:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.