Setting values on the server Site

Setting values on the server Site

INTONEINTONE Posts: 153Questions: 58Answers: 6

From searching the forum it is my understanding that values can be passed to server side using the following code:

        if(isset($_POST['action']) && ($_POST['action'] === 'create' || $_POST['action'] === 'edit')){

            $salt =  make_salt();
            $password = make_random_password();
            $a = array('cost' => 12, 'salt' => $salt);

            $hash = password_hash($password, PASSWORD_BCRYPT, $a);

            if($data['row']['users']['create_reset_password'] == 'YES'){

               $data['row']['users']['salt']   = $salt;
               $data['row']['users']['hash'] = $hash;

            }

        }

I have used to print_r to prove that $data['row'] has values. When I check the database I am not seeing any vales. What am I doing wrong?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I'm a little confused I'm afraid - if you want to pass extra values from the client-side, as your first line suggests, you would use ajax.data.

    If you want to format the sent data, which the code looks like, then you could use the setFormater() method for the PHP classes.

    Alternatively, the code you have above looks like it would probably work - as long as it is run before the process() method of course, but without being able to see the full code, I'm not certain.

    Allan

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    Ok. Here is the full code:

            // DataTables PHP library
            include( "lib/DataTables.php" );
    
            // Alias Editor classes so they are easy to use
            use
                DataTables\Editor,
                DataTables\Editor\Field,
                DataTables\Editor\Format,
                DataTables\Editor\Join,
                DataTables\Editor\Validate;
    
    
    
            if($session->getVar('email') == -1){
                    return;
                } else {
    
    
            // Build our Editor instance and process the data coming from _POST
            $data = Editor::inst( $db, 'users','user_id' )
                   ->fields(
                    Field::inst( 'users.email' )
                        ->validator( 'Validate::email_required' ),
                    Field::inst( 'users.first_name' )
                        ->validator( 'Validate::required' ),
                    Field::inst( 'users.last_name' )
                        ->validator( 'Validate::required' ),
                    Field::inst( 'users.contact_number_1' ),
                    Field::inst( 'users.contact_number_2' ),
                    Field::inst( 'users.active' ),
                    Field::inst( 'users.company_branches_id' )->validator( 'Validate::required' ),
                    Field::inst( 'company_branches.company_name' ),
                    Field::inst( 'users.date_time_created' )->validator( 'Validate::notEmpty' ),
                    Field::inst( 'users.created_by_user_id' ),
                    Field::inst( 'users.last_updated_by_user_id'),
                    Field::inst( 'users.date_time_last_updated' ),
                    Field::inst( 'users.create_reset_password' )
                      } )
    
    
                )->leftJoin( 'company_branches', 'company_branches.company_branches_id', '=', 'users.company_branches_id',array( 'company_id'=>$session->getVar('company_id')) )
                 ->process($_POST)
                 ->data();
    
    
    
    
            if ( ! isset($_POST['action']) ) {
    
                // Get a list of companies for the `select` list
                $data['company_branches'] = $db->selectDistinct( 'company_branches', 'company_branches_id as value, company_name as label',array( 'company_id'=>$session->getVar('company_id')) )
                                               ->fetchAll();
    
            } else if(isset($_POST['action']) && ($_POST['action'] === 'create' || $_POST['action'] === 'edit')){
    
                $salt =  generateRandomString();
                $password = "leoten20";
    
                $a = array('cost' => 12, 'salt' => $salt);
    
                $hash = password_hash($password, PASSWORD_BCRYPT, $a);
    
                if($data['row']['users']['create_reset_password'] == 'YES'){
    
                   $data['row']['users']['salt'] = $salt;
                   $data['row']['users']['hash'] = $hash;
    
                  //$sql = $db->sql( "UPDATE users SET `salt` = '".$data['row']['users']['salt']."', `hash` = '".$data['row']['users']['hash']."' WHERE `email` = '".$data['row']['users']['email']."' ");
                }
    
            }
    
            echo json_encode( $data );
    
            }
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    You need to modify the data before you call the process() method. Otherwise it is processing the unmodified data!

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6
This discussion has been closed.