⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Add view 2 password fields, one is saved.



frxie

frxie
  • profile picture
  • Member

Posted 01 July 2012 - 23:19 PM

Hi guys!

I´m new at CodeIgniter. And i found this GREAT "addon" and of course i had to play around with it. Really flexible and great (should be in CodeIgniter as default).

But i come across a little problem. I´m a PHP coder so i know how to solve it the timeconsuming way (extending class and such). But maybe i don´t have to do that.

Here is the problem. Let´s say i have a db table that looks like this:
id, username, md5password

I set up Crud and the add view would look like this:

Username: Input type text.
Password Input type password.

But what if i would want 2 password fields? But only save one of them to the table. Like this:
Username: input type text.
Password: input type password
Verify Password: Input type password.

With the callback callback_before_insert i know i can hook in and md5 the password entered. But what i want to do is compare the 2 passwords entered. If correct save to table (Password input 1). If not correct do not save anything and display a message for the user.

Is this possible using the Crud functions or do i need to extend the class and write it myself?

One solution would be to extend my db table with another password field and then save '' (emty string) in it. But that doesn´t seem like good db managment.

xxaxxo

xxaxxo
  • profile picture
  • Member

Posted 02 July 2012 - 05:36 AM

Sorry for the question but , why are you using groceryCRUD for such a simple task , it's like trying to do a small precise cut with a sword.
And to not be a full a*hole i'll answer your question, groceryCRUD can use the CI form validation rules
so just add a rule ... matches[password] to the verify pass field and you will have it.
for more info :
http://www.grocerycr...et_rules

http://codeigniter.c...validationrules

frxie

frxie
  • profile picture
  • Member

Posted 02 July 2012 - 06:17 AM

Thanx for your answer. What do you mean such a simple task? You mean that it´s a small table without no relations? Well, i´m new to CodeIgniter. And i see no reason to not use groceryCRUD for this task. It´s so easy. And it´s a problem i´m trying to solve to see the possibillities in groceryCRUD.

Thanks for the tip with validation. But how do i add a field <input type="password"> that is not located in the table and should not be saved in a table.

[quote name='xxaxxo' timestamp='1341207375' post='2529']
Sorry for the question but , why are you using groceryCRUD for such a simple task , it's like trying to do a small precise cut with a sword.
And to not be a full a*hole i'll answer your question, groceryCRUD can use the CI form validation rules
so just add a rule ... matches[password] to the verify pass field and you will have it.
for more info :
http://www.grocerycr...et_rules

http://codeigniter.c...validationrules
[/quote]

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 02 July 2012 - 06:29 AM

Hello [member='frxie']

I have an example of how to use password fields at: http://www.grocerycr...#password-field

In your case is really easy you can do something like this:


$crud->change_field_type('password', 'password');
$crud->change_field_type('verify_password', 'password');

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 02 July 2012 - 06:33 AM

And as for the password verification [member='xxaxxo'] meant to do something like this:


$crud->set_rules('verify_password', 'Verify Password', 'required|matches[password]');

xxaxxo

xxaxxo
  • profile picture
  • Member

Posted 02 July 2012 - 07:57 AM

yes also i meant that a simple login form and a validation function in your controller (without using groceryCRUD) will benefit you more than trying to do it with it. IF you want to learn it you should try to do more complex stuff like a cms or a full backend for some of your sites. But that's only my opinion ;)

frxie

frxie
  • profile picture
  • Member

Posted 02 July 2012 - 10:47 AM

Thx guys for helping me out. But i think you guys have misunderstood me. My fault. I´ll try to be more clear in this response:

As xxaxxo mentioned this is a list for adding users to a system that will be a cms. An admin kan add users and set access for what the users can do. But this table is only for adding new users. So the admin will se this form when they add a users:
Name, Username, Password, Verify Password

The data that goes in the table is Name, Username and Password. The Verify Password input is just to check that the admin who enters the user didn´t misspell the Password that will be inserted into the database. There is no corresponding "Verify Password" field in the table that GroceryCRUD populates the form fields from. So my question is:
Can i add a form field without having it in a table?

I also wonder if you can add several users at the same time. Like an add form with multiple fields (like you can see in PHPMyAdmin).

Thanx again guys for taking time to answering me. Once again great component and seems like a very active community!

xxaxxo

xxaxxo
  • profile picture
  • Member

Posted 03 July 2012 - 06:43 AM

As a not so good coder, but a good problem solver my first question is " Why do you need to "hide" the password from the admin and make him verify it when he is the one that inputs it ?" you can just set it as a normal input field
but if you are a pedantic guy that needs to do things the way he first decided (which is not a bad thing) the first thing that comes in mind is try using add_callback and add 2 fields instead of one in your function that makes/changes the field.

I also read my previous responses and i'd like to clarify - in no point in time i was trying to be rude or offencive, so forgive me if you got that impression of me.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 03 July 2012 - 21:45 PM

[member='frxie'] you can add as many extra fields with simply adding the fields. For example:


$crud->fields('username','password','verify_password','fullname');


The verify_password is not at the database but you will not have any problem with this. So you just want now to change it to password field like this:


$crud->change_field_type('verify_password', 'password');


The only problem that you will have is at the insert and update that grocery CRUD will try to add it to the database and the field is not there.
So to prevent this you can simply use a callback_before_insert and callback_before_update for example:


$crud->callback_before_insert(array($this,'unset_verification'));
$crud->callback_before_update(array($this,'unset_verification'));


and to your controller add


function unset_verification($post_array) {
unset($post_array['verify_password']);
return $post_array;
}


OK now that we solve this problem I have to say that my opinion is the same as [member='xxaxxo']'s , sometimes perhaps it is more easy to just create a simple form rather than to customize grocery CRUD to fit at our first need. Of course if you are addicted to grocery CRUD as I am :) you want to use grocery CRUD in every CRUD . For example me, I even create forms with grocery CRUD to send ... emails!!
1. I create a temporary table
2. I add a callback_insert and ...in 5 minutes I have my own form to send e-mail.

Lastly I thing that [member='xxaxxo'] you are great coder. For me a Perfect web-developer is a web-developer that can find the best solution fast and combine technologies (such as PHP, Javascript, mySQL) together without any problem and give to the customer a great tool.

I know many "good coders" with perfect knowledge of OO programing but the CRUD that they created was like this (not telling names :P ) [attachment=212:2012-07-03_224307.png] [attachment=213:2012-07-03_224336.png] [attachment=214:2012-07-03_224420.png]

kenshicu

kenshicu
  • profile picture
  • Member

Posted 10 February 2014 - 21:55 PM

hello to all
I had fact something working in GC1.3.3 thus,
when migrating it to GC1.4.1, when I give to click in the button ¨save and go back¨, he does not do anything, does not work.

that he could be?

 

sorry my bad english...