Welcome Guest, Not a member yet? Register   Sign In
Do not save password if empty!
#1

[eluser]Wazzu[/eluser]
Hi guys!

I have a simple form so users can edit their own profile:
It shows a form like this:

- username (readonly)
- name
- address
- password

But when an user changes *only* the address and submits form, an empty password is saved on the database cause $this->input->post('password') is empty.

I make use of datamapper and save it this way:
Code:
$u = new User($id);
$u->name = $this->input->post('name');
$u->address = $this->input->post('address');
$u->password = $this->input->post('password');
$u->save()

I tried to unset $u->password but it saves it like a NULL field :-(
How am I supposed to make this so-common task? I feel so stupid...
#2

[eluser]xeroblast[/eluser]
try it with like this:

Quote:$u = new User($id);
$u->name = $this->input->post('name');
$u->address = $this->input->post('address');
if ($this->input->post('password'))
$u->password = $this->input->post('password');
$u->update();
#3

[eluser]Peng Kong[/eluser]
maybe that's why twitter put change of password on a different page by itself which i think is a pretty good idea
#4

[eluser]Maglok[/eluser]
Technical limitations are really not limiting that. From a useability standpoint it just makes sense though. Much easier.

Xeroblast's example should work. Don't forget to add {}s to the IF if you copy paste that. Wink
#5

[eluser]Wazzu[/eluser]
Thanks all for your answers, I haven't tried it yet.

[quote author="Peng Kong" date="1266599682"]maybe that's why twitter put change of password on a different page by itself which i think is a pretty good idea[/quote]

For example, Joomla makes it all from the same form, and that's easier.
In my application, login data includes login, password, email and "is-enabled" fields, so even if I use a different form for login data, I must let the user enable or disable the account without changing password and vice-versa.

Thanks again, gonnna thy with that 'if' (so simple it can't fail!) and let you know.
Cheers
#6

[eluser]Wazzu[/eluser]
[quote author="xeroblast" date="1266578607"]try it with like this:

Code:
$u = new User($id);
$u->name = $this->input->post('name');
$u->address = $this->input->post('address');
if ($this->input->post('password'))
  $u->password = $this->input->post('password');
$u->update();
[/quote]
Worked! And I feel a bit stupid, hehe...




Theme © iAndrew 2016 - Forum software by © MyBB