I’m trying to add a new row (similar to the Contact Manager add row) from a popup window.
There are 3 fields in the popup form: firstName, lastName, notes.
There are 6 columns in the table: id, firstName, lastName, gender, birthDate, notes.
If I only put values in the popup form fields firstName, lastName, and leave notes empty, the record gets inserted into the table like this:
“70”, “firstNameTest”, “lastNameTest”,“Male”,“0000-00-00”,“undefined”
Is there a way to specify that fields with no values gets inserted with ?
Thanks,
K
“undefined” value may occur if client side form has not field with such name, but server side configuration has such field.
If client side input with such name exists but just leaved empty - it must be an empty string on server side.
In any case you can use beforeProcessing server side events to process data before saving.
Thanks Stan.
Here’s my xml form:
<?xml version="1.0"?>
<items>
<item type="input" name="firstName" bind="firstName" label="First Name"/>
<item type="input" name="lastName" bind="lastName" label="Last Name"/>
<item type="input" name="notes" bind="notes" label="Notes"/>
<item type="button" name="addStudent" command="save" value="Save"/>
</items>
Here’s my php:
$formConn->render_table("student","id","firstName,lastName,notes,gender,birthDate");
Here’s my table definition:
id int(16)
firstName varchar(250)
lastName varchar(250)
gender enum('Male', 'Female')
birthDate date
notes text
a) Are you setting data by js command like next ?
form.setFormData({ lastName:“some”})
in such case you need to provide all form fields in the command
form.setFormData({ lastName:“some”, note:"", …})
b) with your current code you can use on server side
function fix_undefined($data){
if ($data->get_value("note") == "undefined")
$data->set_value("note", "");
}
$formConn->event->attach("beforeProcessing", "fix_undefined");
$formConn->render_table("student","id","firstName,lastName,notes,gender,birthDate");
Hi Stan,
I’m not setting the data by using setFormData.
I’m using sendData():
addStudentForm.attachEvent("onButtonClick", function(name, command){
dpfs.sendData();
});
Should I be using setFormData instead of sendData?
Thanks,
K
is dpfs an instance of dataprocessor, attached to the form?
It is valid code, you need not change it.
But if you are using latest form (3.0) i’m really not sure how you can have “undefined” on server side, as form must not produce such values.
Above server side solution can be used for filtering anyway.
If you have any kind of online demo or a sample ( just a client side part ) where issue can be reconstructed please provide the link.
Hi Stan,
Thanks for your reply.
I’ve attached a zip of my files. The html that contains the script is “students.html”. You can probably take a look at this zip for my other thread viewtopic.php?f=19&t=24585.
Thanks a lot!
K
Also, yes, dpfs is an instance of the dataprocessor attached to the form.
Can you see it now?
kitofuwi.zip (829 KB)
I can confirm the problem, we will investigate it and will provide a fix
As fast solution, you can replace
addStudentForm.loadStruct(“xml/addStudentForm.xml”);
with
addStudentForm.loadStruct("xml/addStudentForm.xml", function(){
addStudentForm.setValues({ firstName:"", lastName:"", gender:"" });
});
which will set initial values for the form, and will resolve problem with “undefined” values
Hi Stan,
Thanks for the reply.
I used your code, and setting the initial values to “” works.
Thanks!
K.