Hello everyone! I generated a PIN number and i want to insert it in my database, but there is something wrong when I click the button to generate it executes and goes to another page.
this is my ts :
// Define FormBuilder /model properties
public form : FormGroup;
public AdminUsername : any;
public PatientUsername : any;
public AccountPassword : any;
public VPassword : any;
public APIN : any;
disableButton;
// Flag to be used for checking whether we are adding/editing an entry
public isEdited : boolean = false;
// Property to store the recordID for when an existing entry is being edited
public AccountID : any = null;
private baseURI : string = "http://localhost:10080/ionic/";
// Initialise module classes
constructor(public navCtrl : NavController,
public http : Http,
public NP : NavParams,
public fb : FormBuilder,
public toastCtrl : ToastController,
private alertCtrl :AlertController,
public myHandler : MyHandlerProvider)
{
// Create form builder validation rules
this.form = fb.group({
"a_username" : ["", Validators.required],
"p_username" : ["", Validators.required],
"password" : ["", Validators.required],
"PIN" : ["", Validators.required],
"vpassword" : ["", Validators.required]
});
}
// Determine whether we adding or editing a record
// based on any supplied navigation parameters
ionViewWillEnter()
{
this.resetFields();
if(this.NP.get("account"))
{
this.isEdited = true;
this.selectEntry(this.NP.get("account"));
//this.pageTitle = 'Amend entry';
}
else
{
this.isEdited = false;
// this.pageTitle = 'Create entry';
}
}
showAlert(message)
{
let alert=this.alertCtrl.create({
title:'Alert!',
subTitle:message,
buttons:['OK']
});
alert.present();
}
private getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
generate() {
this.APIN = this.getRandomInt(1000, 9999);
this.disableButton = true;
}
// Assign the navigation retrieved data to properties
// used as models on the page's HTML form
selectEntry(item)
{
this.AdminUsername = item.a_username;
this.PatientUsername = item.p_username;
this.AccountPassword = item.password;
this.VPassword = item.vpassword;
this.APIN = item.PIN;
this.AccountID = item.acc_id;
}
createEntry(a_username, p_username, password, vpassword, PIN)
{
let body : string = "key=create&a_username=" + a_username + "&p_username=" + p_username + "&password=" + password
+ "&vpassword=" + vpassword + "&PIN" + PIN,
type : string = "application/x-www-form-urlencoded; charset=UTF-8",
headers : any = new Headers({ 'Content-Type': type}),
options : any = new RequestOptions({ headers: headers }),
url : any = this.baseURI + "users.php";
this.http.post(url, body, options)
.subscribe((data) =>
{
// If the request was successful notify the user
if(data.status === 200)
{
//this.hideForm = true;
this.sendNotification(`Congratulations the account was successfully created`);
}
// Otherwise let 'em know anyway
else
{
this.sendNotification('Something went wrong!');
}
});
}
// Handle data submitted from the page's HTML form
// Determine whether we are adding a new record or amending an
// existing record
saveEntry()
{
let a_username : string = this.form.controls["a_username"].value,
p_username : string = this.form.controls["p_username"].value,
password : string = this.form.controls["password"].value,
PIN : string = this.form.controls["PIN"].value,
vpassword : string = this.form.controls["vpassword"].value;
if(password != vpassword){
this.showAlert("password are not equal");
}
else{
this.createEntry(a_username, p_username, password, vpassword, PIN);
console.log("passed by else ")
this.navCtrl.push(PInfoPage);
}
}
resetFields() : void
{
this.AdminUsername = "";
this.PatientUsername = "";
this.AccountPassword = "";
this.VPassword = "";
this.APIN = "";
}
// Manage notifying the user of the outcome
// of remote operations
sendNotification(message) : void
{
let notification = this.toastCtrl.create({
message : message,
duration : 3000
});
notification.present();
}
showPage(msg)
{
this.myHandler.setPatientValue(msg);
}
}
HTML:
<div class="div-button">
<button ion-button block outline large (click)="generate()" [disabled]="disableButton" formControlName="PIN"
[(ngModel)]="APIN" ngDefaultControl>PIN: {{PIN}}</button>
<p>Use PIN to enter Admin Mode</p>