Make fields disabled in Profile page
-
Hi!
I have a registration page for members, and after that members can edit their data from a profile page.
I’d like to make a birthdate field so that a user can not edit it once they have given their birthdate in a registration page. So I’d need to add “disabled” attribute to the end of the field.
I managed to get it done by using register_form_rows filter. This removes end tag “/>” from the end and replaces it with “disabled />”.
add_filter( 'wpmem_register_form_rows', 'my_register_form_rows_filter', 10, 2 ); function my_register_form_rows_filter( $rows, $toggle ) { if( $toggle == "edit" ) { $rows["birthdate"]["field"] = substr_replace($rows["birthdate"]["field"],'disabled />',-2,2); } return $rows; }And now when I enter a profile page, everything works as it should. Birthdate field is visible, and it is showing the users birthdate, and it is disabled (user can’t edit the field).
The problem is that when I now press “Save” button at the end of form, the page reloads and gives error “Birthdate field is required”, and this time birthdate field is showing empty.
Why I’m receiving this error? Is there any better way to prevent user from changing fields data in the profile page? As far as I can think, this is a good solution for this, but somehow this breaks the form validation process or something.
The topic ‘Make fields disabled in Profile page’ is closed to new replies.