I have a field in my form that if it is left blank, I want the value entered into the DB to be NULL. It keeps submitting a value of 0. The DB Table allows null values as I set the value to NULL from the DB Admin tool but not when I submit the Chronoform. How do I have the value be set to null if the field is blank?
thanx,
thanx,
Hi vividal,
I think that if you unset that value from the form data then MySQL will use the default NULL value.
Bob
I think that if you unset that value from the form data then MySQL will use the default NULL value.
Bob
Sorry I dont understand what you mean by unset that value from the form data.
Hi vividal,
You can use PHP in a Custom Code action before the Save Data action to check the value submitted and unset* it. See Page 34 of the manual for the basics
* Looking at page 34 I'm not sure that you can use unset() so the code above sets the value to NULL
You can use PHP in a Custom Code action before the Save Data action to check the value submitted and unset* it. See Page 34 of the manual for the basics
if ( empty($this->data('input_name')) ) {Bob
$this->data('input_name', NULL, true);
}
* Looking at page 34 I'm not sure that you can use unset() so the code above sets the value to NULL
Hi,
unset also can be used:
unset also can be used:
if(empty($this->data["name"])){Best regards
unset($this->data["name"]);
}
So I can't get either of these to work (or several other combinations that I have randomly tried). should this be placed in a "Customer Code" or a "PHP" action (I have tried both). If I skip trying the IF statement and just go to "hard set" the value I can set it to a value like 5, but I can't get it to set to NULL.
If I put this is a PHP action it works
$this->data(home_score,5,true); // works just fine
If I change it to this, nothing happens
$this->data(home_score,NULL,true); // doesnt work
thoughts?
If I put this is a PHP action it works
$this->data(home_score,5,true); // works just fine
If I change it to this, nothing happens
$this->data(home_score,NULL,true); // doesnt work
thoughts?
Hi vividal,
Please try this:
Best regards
Please try this:
if(empty($this->data["name"])){in a php action just before the "Save data" action.
unset($this->data["name"]);
}
Best regards
I have put the following in as you requested (I tried with " around it too
if(empty($this->data[home_score])){
unset($this->data[home_score]);
}
this is what gets returned now
Parse error: syntax error, unexpected 'unset' (T_STRING) in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line2
if(empty($this->data[home_score])){
unset($this->data[home_score]);
}
this is what gets returned now
Parse error: syntax error, unexpected 'unset' (T_STRING) in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line2
Please use the double quotes as in my code
if(empty($this->data["home_score"])){
unset($this->data["home_score"]);
}
does the same thing
Parse error: syntax error, unexpected 'unset' (T_STRING) in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line2
unset($this->data["home_score"]);
}
does the same thing
Parse error: syntax error, unexpected 'unset' (T_STRING) in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line2
Hi vividal,
This code should work:
Best regards
This code should work:
if(empty($this->data["name"])){There are some hidden characters in the code posted before, but the version here should work!
unset($this->data["name"]);
}
Best regards
I am still getting a php error with this code
if(empty($this->data["away_score"])){
unset($this->data["away_score"]);
}
Parse error: syntax error, unexpected 'unset' (T_STRING) in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line2
if(empty($this->data["away_score"])){
unset($this->data["away_score"]);
}
Parse error: syntax error, unexpected 'unset' (T_STRING) in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line2
Array ( [option] => com_chronoforms6 [cont] => manager [chronoform] => tourn-game-edit [game_id] => 92 [event] => submit [aid] => 92 [game_start] => 2018-02-23 18:00:00 [away_score] => [home_score] => [location_id] => 53 [button13] => [intercom-lou-tvfkokak] => 1 [joomla_user_state] => logged_in [5c8a1c575b995dbdf3c3e56651c22852] => b7ef4c221c1d34607f660b5b0ae45236 [88ce27ccca7738dcd49df6b5d9f53e1b] => ffe1d3a997e49d463ed9098194bd93f7 [Itemid] => )
Array ( [php20] => Array ( [returned] => [var] => ) )
OK so update to where I am at with this (STILL NOT WORKING). I am not convinced however that this is Chrono issue but perhaps someone can help on the MYSQL side. I have tried different things and have gotten this to do what I expect on the Chrono site using a custome code action (not PHP). See the code and the debug below.
Even though the SQL Statement shows `away_score` = 'NULL' it is getting changed to 0. Is mysql doing this (the column is set to allow NULL and a default value of NULL)?
CODE:
<?php
$away = $this->data["away_score"];
if (empty($away)) {
$away='NULL';
}
$this->data["away_score"] = $away;
?>
Even though the SQL Statement shows `away_score` = 'NULL' it is getting changed to 0. Is mysql doing this (the column is set to allow NULL and a default value of NULL)?
CODE:
<?php
$away = $this->data["away_score"];
if (empty($away)) {
$away='NULL';
}
$this->data["away_score"] = $away;
?>
Array
(
[option] => com_chronoforms6
[cont] => manager
[chronoform] => tourn-game-edit
[game_id] => 92
[event] => submit
[aid] => 92
[game_start] => 2018-02-23 18:00:00
[away_score] => NULL
[home_score] =>
[location_id] => 53
[button13] =>
[intercom-lou-tvfkokak] => 1
[joomla_user_state] => logged_in
[5c8a1c575b995dbdf3c3e56651c22852] => b7ef4c221c1d34607f660b5b0ae45236
[88ce27ccca7738dcd49df6b5d9f53e1b] => 6a3a1b80edd7d0d55e45b989d80b8410
[Itemid] =>
)
Array
(
[validate_fields2] => Array
(
[log] => Automatic validation enabled.
[var] => 1
)
[save_data12] => Array
(
[data] => Array
(
[created] => 2018-02-23 17:36:19
[user_id] => 0
[aid] => 92
[game_start] => 2018-02-23 18:00:00
[away_score] => NULL
[home_score] =>
[location_id] => 53
)
[_success] => Data saved successfully
[log] => Array
(
[0] => INSERT INTO `LO_TournamentGames` (`created`, `user_id`, `aid`, `game_start`, `away_score`, `home_score`, `location_id`) values ('2018-02-23 17:36:19', '0', '92', '2018-02-23 18:00:00', 'NULL', '', '53') ON DUPLICATE KEY UPDATE `created` = '2018-02-23 17:36:19',`user_id` = '0',`aid` = '92',`game_start` = '2018-02-23 18:00:00',`away_score` = 'NULL',`home_score` = '',`location_id` = '53';
)
[var] => Array
(
[created] => 2018-02-23 17:36:19
[user_id] => 0
[aid] => 92
[game_start] => 2018-02-23 18:00:00
[away_score] => NULL
[home_score] =>
[location_id] => 53
)
)
)
HI vividal,
NB NULL (without quotes) and 'NULL' (with quotes) are not the same. Without quotes it is a NULL value, with quotes it it a text string.
Bob
NB NULL (without quotes) and 'NULL' (with quotes) are not the same. Without quotes it is a NULL value, with quotes it it a text string.
Bob
Yes I have tried all 3 ways no quotes, single quote, double quote. With no quotes, nothing gets passed to the SQL statement. see debug below
<?php
$away = $this->data["away_score"];
if (empty($away)) {
$away=NULL;
}
$this->data["away_score"] = $away;
?>
<?php
$away = $this->data["away_score"];
if (empty($away)) {
$away=NULL;
}
$this->data["away_score"] = $away;
?>
Array ( [option] => com_chronoforms6 [cont] => manager [chronoform] => tourn-game-edit [game_id] => 178 [event] => submit [aid] => 178 [game_start] => 2018-02-23 20:00:00 [away_score] => [home_score] => [location_id] => 50 [button13] => [intercom-lou-tvfkokak] => 1 [joomla_user_state] => logged_in [5c8a1c575b995dbdf3c3e56651c22852] => 8b7145ca8ec89cf0d3acf8756bcd0c01 [88ce27ccca7738dcd49df6b5d9f53e1b] => 4109e935f032820445ce41227027dc5f [Itemid] => )
Array ( [validate_fields2] => Array ( [log] => Automatic validation enabled. [var] => 1 ) [save_data12] => Array ( [data] => Array ( [created] => 2018-02-24 12:59:36 [user_id] => 623 [aid] => 178 [game_start] => 2018-02-23 20:00:00 [away_score] => [home_score] => [location_id] => 50 ) [_success] => Data saved successfully [log] => Array ( [0] => INSERT INTO `LO_TournamentGames` (`created`, `user_id`, `aid`, `game_start`, `away_score`, `home_score`, `location_id`) values ('2018-02-24 12:59:36', '623', '178', '2018-02-23 20:00:00', '', '', '50') ON DUPLICATE KEY UPDATE `created` = '2018-02-24 12:59:36',`user_id` = '623',`aid` = '178',`game_start` = '2018-02-23 20:00:00',`away_score` = '',`home_score` = '',`location_id` = '50'; ) [var] => Array ( [created] => 2018-02-24 12:59:36 [user_id] => 623 [aid] => 178 [game_start] => 2018-02-23 20:00:00 [away_score] => [home_score] => [location_id] => 50 ) ) )
Hi vividal,
The code below should work:
Best regards
The code below should work:
if(empty($this->data["away_score"])){But please do not copy and paste it in your PHP action, please type it there and let me know how it works.
unset($this->data["away_score"]);
}
Best regards
Please add a debugger after the PHP action, what do you get in the debugger ?
OK so i still can't get it work with a PHP Action. I get the following
Parse error: syntax error, unexpected '<' in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line1
using custom code action with PHP code I dont get the error . below is the debug. Please note that I have started with a new form and DB Table b/c i needed to go "live" with my other table and came up with a work around where I change all read 0 to NULL before publishing info (but that wont really work long term). the New form/Table uses the field name blanknum. Below is the debug after the custom code.
Parse error: syntax error, unexpected '<' in/home4/vividal/public_html/chvlny.org/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d codeon line1
using custom code action with PHP code I dont get the error . below is the debug. Please note that I have started with a new form and DB Table b/c i needed to go "live" with my other table and came up with a work around where I change all read 0 to NULL before publishing info (but that wont really work long term). the New form/Table uses the field name blanknum. Below is the debug after the custom code.
Array ( [option] => com_chronoforms6 [cont] => manager [chronoform] => test-null-write [event] => submit [text] => test-blank number field [blanknum] => [button3] => [intercom-id-tvfkokak] => 15798103-86f9-464c-9027-ab218218f9a9 [intercom-lou-tvfkokak] => 1 [5c8a1c575b995dbdf3c3e56651c22852] => eeb5b5864bf178ce4795e272e3c0af51 )
Array ( [validate_fields2] => Array ( [log] => Automatic validation enabled. [var] => 1 ) )
Hi vividal,
Ok, you can try to do it a different way:
Best regards
Ok, you can try to do it a different way:
$provider = $this->data;Then use {var:test} as the data provider.
unset($provider['some_var']);
$this->set('test', $provider);
Best regards
This topic is locked and no more replies can be posted.