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
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
Hi Melgui ,
And is there a default value in the DB Settings?
Bob
Yes, it is. NULL is a dauflt value.
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
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
Hi melgui,
I'm sorry, I don't understand what the problem is :-(
Bob
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
Hi Melgui ,
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.