Reputation: 165
I have a a page where users create and account and edit password if the account already exists. I'm using php - codeigniter
When users update passwords, the input field currently allows them to change their username as well as their password. I'm trying to make it so that users can only update passwords and not usernames but I have had trouble doing so.
This is my code
<input required type="text"
placeholder="page name"
value="<?= $form_value['name'] ?>" name="name" id="name">
I am trying to make it so that the username is printed but it is not updated.
The only thing I can think of is making the input type hidden (as shown in the below code), but then users can minipulate it and change it in the inspect element option of the browser and update their users.
<input required type="hidden" placeholder="page name" value="<?= $form_value['name'] ?>" name="name" id="name">
I am not sure what to do, Thanks in advance
Upvotes: 2
Views: 3864
Reputation: 509
Just echo the plain username without input field (if user is logged in) & empty input field (for new user registration), while update take the user_id from session & update the respective password of the logged in user.
Upvotes: 0
Reputation: 479
I assume you're using a database to store this information. If that is the case - just don't update the username field when you are updating the password. There are many cases where the user could go into inspect element and change things, but all that matters is what you're doing on the back-end.
Upvotes: 1
Reputation: 6006
use should echo your php variable to get its value inside your html input element
<input required type="text" placeholder="page name" value="<?= echo $form_value['name']; ?>" name="name" id="name">
in the above syntax you are using php shorthand syntax, so you should enable it first. you can use like this also without short tags
<input required type="text" placeholder="page name" value="<?php echo $form_value['name']; ?>" name="name" id="name">
Upvotes: 2