Add view 2 password fields, one is saved.
- Single Page
Posted 01 July 2012 - 23:19 PM
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.
Posted 02 July 2012 - 05:36 AM
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
Posted 02 July 2012 - 06:17 AM
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]
Posted 02 July 2012 - 06:29 AM
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');
Posted 02 July 2012 - 06:33 AM
$crud->set_rules('verify_password', 'Verify Password', 'required|matches[password]');
Posted 02 July 2012 - 07:57 AM
Posted 02 July 2012 - 10:47 AM
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!
Posted 03 July 2012 - 06:43 AM
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.
Posted 03 July 2012 - 21:45 PM
$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 ) [attachment=212:2012-07-03_224307.png] [attachment=213:2012-07-03_224336.png] [attachment=214:2012-07-03_224420.png]
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...