⚠ 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

I have a question about edit/insert table USERS



Võ Hào
  • profile picture
  • Member

Posted 15 May 2013 - 04:37 AM

I have table USERS include fields: id, username, password.

 

Using grocery CRUD, when I ADD RECORD, a form appears:

 

add.png

 

But, I want add a control Confirm password to this form, look like

 

addnew.png

 

Before insert (username, password) to database, it will compare password and confirm password

 

p/s: Confirm password is not field in table USER

 

Who can help me about this problems?


victor
  • profile picture
  • Member

Posted 15 May 2013 - 06:53 AM

you can use function 'fields' and 'callback before insert'

Võ Hào
  • profile picture
  • Member

Posted 16 May 2013 - 04:14 AM



you can use function 'fields' and 'callback before insert'

 

Hi Victor! Thank you very much!

This problem is ok. My code:

 


public function user()

    {
        $crud = new grocery_CRUD();
        $crud->set_theme('datatables');
        $crud->set_table('tbl_user');
        $crud->columns('username','password');
        $crud->fields('username','password','confirmpass')->field_type('password', 'password')->field_type('confirmpass', 'password');
        $crud->set_rules('password','Mật khẩu','required');
        $crud->set_rules('confirmpass','Xác nhận mật khẩu','matches[password]');
        $crud->callback_before_insert(array($this, 'insert_user'));
        $output = $crud->render(); 
        $this->Out($output); 
    }
    function insert_user($post_array){
 
       if($post_array['password']==$post_array['confirmpass'])
        {
            $data = array(
                   'username' => $post_array['username'] ,
                    'password' => $post_array['password']
            );
 
            $this->db->insert('tbl_user', $data); 
           //$this->user();
        }
    }

 

My application was inserted into the database. But it does not appear message when I click button Save in Add Record form

 

mesadd.png

 

Or when I click button Save and go back to list. It not redirect to list User (but inserted into database)


victor
  • profile picture
  • Member

Posted 16 May 2013 - 06:30 AM

which error do you get from browser's console?

victor
  • profile picture
  • Member

Posted 16 May 2013 - 06:43 AM

take a look at the callback function from example!!!
you need return post_array in the end of function. and delete extra data before. unset($post_array['confirmpass']). in your case you don't need to insert data in to database in 'callback before insert' functions. only delete extra data before checking.
there are many topics on this forum about Ion_auth library

Võ Hào
  • profile picture
  • Member

Posted 17 May 2013 - 04:38 AM

take a look at the callback function from example!!!
you need return post_array in the end of function. and delete extra data before. unset($post_array['confirmpass']). in your case you don't need to insert data in to database in 'callback before insert' functions. only delete extra data before checking.
there are many topics on this forum about Ion_auth library

 

Hi Victor! It's OK, it running.

 

I have another question about set_relaton function

 

 

void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] )
 

Example: $crud->set_relation('user_id','users','username',array('status' => '0'));

 

 

// Produces: ....WHERE status = '0'

 

But I want produces: ....WHERE status <> '0', Written set_relation function how?

 


 


 

// In codeigniter

$this->db->where('name !=', $name);
$this->db->where('id <', $id); 
// Produces: WHERE name != 'Joe' AND id < 45

 


davidoster
  • profile picture
  • Member

Posted 17 May 2013 - 06:54 AM

Use this,

 $crud->set_relation('user_id','users','username',array('status != ' => '0'));

 

Reference: http://ellislab.com/codeigniter/user-guide/database/active_record.html#select

function: $this->db->where();


Võ Hào
  • profile picture
  • Member

Posted 18 May 2013 - 07:48 AM

Use this,

 $crud->set_relation('user_id','users','username',array('status != ' => '0'));

 

Reference: http://ellislab.com/codeigniter/user-guide/database/active_record.html#select

function: $this->db->where();

I have table tbl_category: (id, name, parent_id) and table tbl_topic: (id, title, content, cate_id)

I using:

             $crud->set_relation('cate_id','tbl_category','name',array('parent_id!=' => '0' ));

But:

 

 

errordb.png

 

????


davidoster
  • profile picture
  • Member

Posted 18 May 2013 - 22:10 PM

 $crud->set_relation('cate_id','tbl_category','name',array('parent_id != ' => '0' ));


Võ Hào
  • profile picture
  • Member

Posted 19 May 2013 - 08:15 AM

 $crud->set_relation('cate_id','tbl_category','name',array('parent_id != ' => '0' ));

Thanks. beetwen paren_id and != have a space