date field type issue

M

Matt

Guest
I'm fairly new to DaDaBik, so whenever I've come up with an issue, I've gone through the forums and have usually found the answer. Failing that, I've gone through the php code and been able to find a solution. After several days of tweaking the interface, there are only two things that I can't figure out (I'll post a seperate topic for the second problem).

The issue I'm trying to work through is this: I have a field set as type "date". This is not a required field. In fact, a good percent of the 3000+ records in the database for which I'm using DaDaBik has no date. My problem is that when using field type "date," when updating a record or inserting a new record, the date field cannot be set or kept blank. It defaults to Jan 1st of the earliest date allowed by config.php. So new records with no date get the date set to jan 1st, and records already in the database that have no date get assigned a date of jan 1st once you use the "edit" feature to update the record in DaDaBik.

Is there any way around this (possibly a blank option above the numbers in the day/month/year drop down boxes)? Any suggestions? Thanks!

-Matt

 
M

Matt

Guest
Nevermind...I figured it out. I edited the function "build_date_select" in general_functions.php to put a blank option before each drop down box. A new day was all I needed to clear the head and find it. I should have given it another day before posting.

Thanks!
-Matt

 
J

John Rogers

Guest
Could you post the code for this mod? It is exactly what I need.
 
D

Debbie S

Guest
John

This mod is easy to implement ...

In general_functions.php, on or about line 129 (function build_date_select ($field_name, $day, $month, $year)), there you would add your blank option line right after the start of the select field:

$day_select .= "<select name=\"".$field_name."_day\"><option value=\"\"></option>";
$month_select .= "<select name=\"".$field_name."_month\"><option value=\"\"></option>";
$year_select .= "<select name=\"".$field_name."_year\"><option value=\"\"></option>";

Thanks Matt for pointing that out!

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
J

John Rogers

Guest
Debbie,

thank-you for the max characters in a field solution.

Re the date solution. On inserting the required code & testing the field I get the following error messsage-


You have inserted one or more not valid dates.
Please Go back and check the form.

Could you please advise whether the extra code is replacing existing code or is additional. I have tried numerous combinations.

Below is the unaltered code with some line numbers added.


129 function build_date_select ($field_name, $day, $month, $year)
// goal: build three select to select a data (day, mont, year), if are set $day, $month and $year select them
// input: $field_name, the name of the date field, $day, $month, $year (or "", "", "" if not set)
// output: $date_select, the HTML date select
// global $start_year, $end_year
134 {


135 global $start_year, $end_year;


137 $date_select = "";
$day_select = "";
$month_select = "";
$year_select = "";


142 $day_select .= "<select name=\"".$field_name."_day\">";
$month_select .= "<select name=\"".$field_name."_month\">";
$year_select .= "<select name=\"".$field_name."_year\">";

for ($i=1; $i<=31; $i++){
$day_select .= "<option value=\"".sprintf("%02d",$i)."\"";
if($day != "" and $day == $i){
$day_select .= " selected";
} // end if
$day_select .= ">".sprintf("%02d",$i)."</option>";
} // end for

for ($i=1; $i<=12; $i++){
$month_select .= "<option value=\"".sprintf("%02d",$i)."\"";
if($month != "" and $month == $i){
$month_select .= " selected";
} // end if
$month_select .= ">".sprintf("%02d",$i)."</option>";
} // end for

for ($i=$start_year; $i<=$end_year; $i++){
$year_select .= "<option value=\"$i\"";
if($year != "" and $year == $i){
$year_select .= " selected";
} // end if
$year_select .= ">".$i."</option>";
} // end for

$day_select .= "</select>";
$month_select .= "</select>";
$year_select .= "</select>";

$date_select = "<td valign=\"top\">".$day_select."</td><td valign=\"top\">".$month_select."</td><td valign=\"top\">".$year_select."</td>";

return $date_select;

} // end function build_date_select
 
D

Debbie S

Guest
John

I've found something that works. In addition to the info I posted for the edits to general_functions.php, you have to also change the following code in business_logic.php (begins on or about line 1028). Change the bolded value below from 0 to 1:

elseif( $fields_labels_ar[$i]["type_field"] == "date" ){
$day = $_POST[$field_name_temp."_day"];
$month = $_POST[$field_name_temp."_month"];
$year = $_POST[$field_name_temp."_year"];
if (!is_numeric($day) || !is_numeric($month) || !is_numeric($year) || !checkdate( $month, $day, $year )){
$check = 1;
$content_error_type = "date";
} // end if

This worked for me to enter a blank date field.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
J

John Rogers

Guest
Getting closer.

If I make the above change to business_logic and then in general_functions replace


$day_select .= "<select name=\"".$field_name."_day\">";
$month_select .= "<select name=\"".$field_name."_month\">";
$year_select .= "<select name=\"".$field_name."_year\">";


with


$day_select .= "<select name=\"".$field_name."_day\"><option value=\"\"></option>";
$month_select .= "<select name=\"".$field_name."_month\"><option value=\"\"></option>";
$year_select .= "<select name=\"".$field_name."_year\"><option value=\"\"></option>";


I get a blank in each of the day month and year drop down boxes. It is then possible to enter a full date or no date. It is not possible to enter a known year with blank day & month. If you do this the date gets saved as all blanks.

Any combination other than the above will not work at all. We are very close to a solution. My problem is that often only the year of bith is known for some of the entries that I need to make.

Thanks again.
 
D

Debbie S

Guest
John

What if the another option is added with day and month values of "00"?

$day_select .= "<select name=\"".$field_name."_day\"><option value=\"\"></option><option value=\"00\"></option>";
$month_select .= "<select name=\"".$field_name."_month\"><option value=\"\"></option><option value=\"00\"></option>";
$year_select .= "<select name=\"".$field_name."_year\"><option value=\"\"></option>";

I haven't tested it, but theoretically, if selected, that should give you a date value of "00-00-YYYY" and still allow for a completely blank date.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
J

John Rogers

Guest
Bingo!

The mod below allows entry of:-

1- full date
2- all blanks for day month & year
3- year with blank day
4- year with blank month
5- year with blank day & month

It is not possible to add blank year only. Changing the year option to 00 creates a year date of 2000.

In general_functions.php, just after line 129 (function build_date_select ($field_name, $day, $month, $year)),

CHANGE:-

$day_select .= "<select name=\"".$field_name."_day\">";
$month_select .= "<select name=\"".$field_name."_month\">";
$year_select .= "<select name=\"".$field_name."_year\">";

TO:-

$day_select .= "<select name=\"".$field_name."_day\"><option value=\"00\"></option>";
$month_select .= "<select name=\"".$field_name."_month\"><option value=\"00\"></option>";
$year_select .= "<select name=\"".$field_name."_year\"><option value=\"\"></option>";

ALSO:-

In the following code in business_logic.php (begins on or about line 1028) change $check = 0; TO $check = 1;

elseif( $fields_labels_ar[$i]["type_field"] == "date" ){
$day = $_POST[$field_name_temp."_day"];
$month = $_POST[$field_name_temp."_month"];
$year = $_POST[$field_name_temp."_year"];
if (!is_numeric($day) || !is_numeric($month) || !is_numeric($year) || !checkdate( $month, $day, $year )){
$check = 1;
$content_error_type = "date";
} // end if

Thanks Debbie for devising the above solution.
 
D

Debbie S

Guest
Glad to help!

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
Top