Dear all,
please help me with following issue. I use default event (DB Save) for saving data to database.
But I have a trouble with a nummeric fields. On saving empty value I allways have zero in my integer column. I have a idea how it could be work if i would save all data in custom way, but its not my goal.
Please help me!
Thanks
Alex
please help me with following issue. I use default event (DB Save) for saving data to database.
But I have a trouble with a nummeric fields. On saving empty value I allways have zero in my integer column. I have a idea how it could be work if i would save all data in custom way, but its not my goal.
Please help me!
Thanks
Alex
Hi Alex,
Do you have a default value or NOT NULL set for the column?
Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here. Note: if you are using the Easy Wizard you may need to switch to the Advanced Wizard to do this; if you want to continue to use the Easy Wizard please make a copy of your form first and add the Debugger action to the copy.
Bob
Do you have a default value or NOT NULL set for the column?
Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here. Note: if you are using the Easy Wizard you may need to switch to the Advanced Wizard to do this; if you want to continue to use the Easy Wizard please make a copy of your form first and add the Debugger action to the copy.
Bob
Default value is nothing.
In debugger looks good, but in db I still have zeroπ

Settings

DB Settings
In debugger looks good, but in db I still have zeroπ

Settings

DB Settings

I can't belive that I am alone with this question! How save other users empty values in integer field with DB Save event.
:(
:(
Hi Melgui,
I've never seen it reported here before - at least I don't remember it.
Bob
I've never seen it reported here before - at least I don't remember it.
Bob
This issues is very populer in internet. For cusom save there are a trick like:
++++
...Yes, form fields are always Strings. So when you submit them without inputting anything, you are actually submitting '' (an empty string) which gets translated into 0. You should include a simple condition to make sure the input is not empty, and take appropriate action if it does.
if (empty($_POST['input'])) { $variable_to_pass = null; }
...
+++
But I use DB Save event. What else can I do?
Thank you Bob
++++
...Yes, form fields are always Strings. So when you submit them without inputting anything, you are actually submitting '' (an empty string) which gets translated into 0. You should include a simple condition to make sure the input is not empty, and take appropriate action if it does.
if (empty($_POST['input'])) { $variable_to_pass = null; }
...
+++
But I use DB Save event. What else can I do?
Thank you Bob
Hi Melgui,
You can add a Custom Serverside validation action (or a Custom code action) and use this code:
Bob
You can add a Custom Serverside validation action (or a Custom code action) and use this code:
<?php
$integer_array = array(
'input_one',
. . .
);
foreach ( $integer_array as $input ) {
if ( !isset($form->data[$input]) || empty($form->data[$input]) ) {
$form->data[$input] = null;
}
}
?>
Bob
I have tried to implemt this code. It works, but nor 100%.If I load my data at first time, so all fields are empty. On save empty fields all field are empty as befor, thats good.
But wenn I try to change the value (that I save befor) from "6 to empty" and then save that task, so I have in DB "6".
Whats going wrong on this place.
I have set custom code on submit befor DB Save.
code looks as following:
<?php
$integer_array = array('intValue1','intValue2');
foreach ( $integer_array as $input ) {
if ( !isset($form->data[$input]) || empty($form->data[$input]) ) {
$form->data[$input] = null;
}
}
?>
I am sorry for my english π π
If the value is already nothing, so it works.
But on changing value to nothing, doesn't happens.
Nothing to Nothing = Nothing
Value to Nothing = old value
If the value is already nothing, so it works.
But on changing value to nothing, doesn't happens.
Nothing to Nothing = Nothing
Value to Nothing = old value
Hi Melgui ,
Maybe empty() isn't the correct test here? Is $form->data[$input] == '' is better?
Bob
Maybe empty() isn't the correct test here? Is $form->data[$input] == '' is better?
Bob
Hi Melgui,
"Value to Nothing = old value" because you set the field value to "Null", this will assume that the field doesn't exist in the post array and its value will be ignored, it will not be updated in the database.
Set it to "" or 0 instead.
Regards,
Max
"Value to Nothing = old value" because you set the field value to "Null", this will assume that the field doesn't exist in the post array and its value will be ignored, it will not be updated in the database.
Set it to "" or 0 instead.
Regards,
Max
This topic is locked and no more replies can be posted.