Omit form field from database INSERT

about a month ago

Bill Lions
Member | 19
+
0
-

I have a form which submits some user registration details.
username/password and, a passwordVerify field.
The database, of course, has no passwordVerify field, and so I get this error.

Nette\Database\DriverException #42703
SQLSTATE[42703]: Undefined column: 7 ERROR:  column "passwordVerify" of relation "users" does not exist
LINE 1: INSERT INTO "users" ("username", "password", "passwordVerify..

How do I omit the passwordVerify field from the INSERT?

about a month ago

manwe
Member | 39
+
+2
-

How do you insert the data?

You most definitely should not do something like

<?php
$form->onSuccess[] = function($form, $values){
    $this->database->table(...)->insert($values);
});
?>

As it begs for some problems to be made.

Create array that only contain values you actually want to insert to database.

like

<?php
$form->onSuccess[] = function($form, $values){
    // do some verification
    $wantedValues = ['username' => $values['username'], 'password' => $values['password'];
    $this->database->table(...)->insert($wantedValues);
});
?>

(im not sure im getting the Nette\Database syntax right as Im not using it, but you get the gist)

Last edited by manwe (2019-03-20 11:07)

about a month ago

CZechBoY
Member | 3334
+
+2
-

You can use $passwordVerify->setOmitted() and the input value is not send to $values.