Manipulate Value While Inputing Data
PHPMaker Tutorial Series
Hi All, welcome to PHPMaker tutorial series !
Sometimes we need to change or manipulate value of input or update field while adding the data to database. For example, when add new user, we want the default username is <nrp> and the password is <nrp>_pass. We can not use autofill feature from lookUp table because master table only contain name and nrp(id user), so we have to modify the nrp in row_inserting() function to become the default password. Let’s start it !
- Take a look at The Master Table
we have master table called master_users. This table will become the reference while adding new user using lookup features.
- Take a look at the input form
Here’s the input form. We will make automatic password using default format while adding new user.
2. Open the code server and find row_inserting() function
Define the variable. $rsold means the old value of field and $rsnew means the new value of field. Old value for password field is null and new value is text we want to add. Because the new value of password is concatenated nrp and “_pass” so we write :
$rsnew['password']=$rsnew['nrp']."_pass";
3. Generate it and try it out
It’s Done! pretty simple right