Solution - Multiple select menu/checkbox

A

alpha2zee

Guest
I have got 'multiple select menu' and 'multiple checkboxes' working in DaDaBik 3.2 beta.

Following are the dozen or so steps to enable these options. I will soon post a good text file with these instructions, in case they appear with errors on this forum, on the Sourceforge tracker - http://sourceforge.net/tracker/?group_id=39649&atid=425835. If you find bugs, please report them (and any fixes) here or on the tracker.

---------------------

0. Use phpmyadmin or any other MySQL editing program to make sure (editing if needed) that the 'type_field' field of each of the 'dadabik_' table in your database has 'select_multiple_menu' and 'select_multiple_checkbox' in it. It should look like this:

ENUM ('text','textarea','rich_editor','password','insert_date','update_date','date','select_single','select_multiple_menu','select_multiple_checkbox','generic_file','image_file','ID_user','unique_ID')

1. Edit include/internal_table.php to ensure it has select_multiple_menu and select_multiple_checkbox. Find this line:

$int_fields_ar[2][3] = "text/textarea/rich_editor/password/insert_date/update_date/date/select_single/generic_file/image_file/ID_user/unique_ID";

Edit to insert after /select_single:

/select_multiple_menu/select_multiple_checkbox

2. Edit include/config.php and uncomment (remove the '//' in front):

//$size_multiple_select = 3;

3. Edit include/business_logic.php

A. Go to function create_internal_table($table_internal_name) and look for:

ENUM('text','textarea','rich_editor','password','insert_date','update_date','date','select_single','generic_file','image_file','ID_user','unique_ID')

After 'select_single,' insert:

'select_multiple_menu','select_multiple_checkbox'

B. Go to function check_required_fields($_POST, $_FILES, $fields_labels_ar)

Look for 'break;' under 'case "select_single":'

After, add:

case "select_multiple_menu":
case "select_multiple_checkbox":
$stringed = implode ("",$_POST[$field_name_temp]);
if (strlen($stringed)<1){$check = 0;}
break;
break;

C. Go to function get_field_correct_displaying and look for:

case "select_multiple_menu":
case "select_multiple_checkbox":

(If they are not there, you can add them after the first or second 'break' in the function)

Below, replace everything till and including the first 'break' statement with:

$field_value = htmlspecialchars($field_value);
// in case field was select_single type before
$separator_first_check = stripos($field_value, $field_separator);
$separator_last_check = strripos($field_value, $field_separator);
if ($separator_first_check == "0" and $separator_last_check == (strlen($field_value)-1))
{$field_value = substr($field_value, 1, -1);} // delete the first and the last separator
$select_values_ar = explode($field_separator,$field_value);
$count_temp = count($select_values_ar);
for ($i=0; $i<$count_temp; $i++){
if ( $display_mode == "results_table") {
$field_to_display .= nl2br(wordwrap($select_values_ar[$i], $word_wrap_col))."<br />";
}
else{
$field_to_display .= nl2br($select_values_ar[$i])."<br />";
}
} // end for
break;
case "select_single": // in case field was select_multiple type before
$field_value = htmlspecialchars($field_value);
$separator_first_check = stripos($field_value, $field_separator);
$separator_last_check = strripos($field_value, $field_separator);
if ($separator_first_check == "0" and $separator_last_check == (strlen($field_value)-1))
{$field_value = substr($field_value, 1, -1);} // delete the first and the last separator
$field_to_display = $field_value;
break;

D. Go to function get_field_correct_csv_displaying and look for:

case "select_multiple_menu":
case "select_multiple_checkbox":
$field_value = substr($field_value, 1, -1);

Replace the third line with:

// in case field was select_single type before
$separator_first_check = stripos($field_value, $field_separator);
$separator_last_check = strripos($field_value, $field_separator);
if ($separator_first_check == "0" and $separator_last_check == (strlen($field_value)-1))
{$field_value = substr($field_value, 1, -1);}

And, after the first following 'break,' add:

case "select_single": // in case field was select_multiple type before
$separator_first_check = stripos($field_value, $field_separator);
$separator_last_check = strripos($field_value, $field_separator);
if ($separator_first_check == "0" and $separator_last_check == (strlen($field_value)-1))
{$field_value = substr($field_value, 1, -1);}
$field_to_display = $field_value;
break;

E. Go to function insert_record and look for:

case "select_multiple_menu":
case "select_multiple_checkbox":

Below, look for:

for ($j=0; $j<$count_temp_2; $j++){
$sql .= $fields_labels_ar[$i]["separator_field"].$_POST[$field_name_temp][$j];// add the field value to the sql statement
} // end for

Replace with:

for ($j=0; $j<$count_temp_2; $j++){
if ($_POST[$field_name_temp][$j] != ""){
$sql .= $fields_labels_ar[$i]["separator_field"].$_POST[$field_name_temp][$j];// add the field value to the sql statement
} // end if
} // end for

F. Go to function build_details_table and look for the while loop:

***************************
while ($details_row = fetch_row_db($res_details)){ // should be just one

$count_temp = count($fields_labels_ar);
for ($i=0; $i<$count_temp; $i++){
if ($fields_labels_ar[$i]["present_details_form_field"] == "1"){
$field_name_temp = $fields_labels_ar[$i]["name_field"];

$field_values_ar = array(); // reset the array containing values to display, otherwise for each loop if I don't call build_linked_field_values_ar I have the previous values

$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
if ($primary_key_field_field != ""){
$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
$primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
$primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
$linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
$linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
$alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];

for ($j=0;$j<count($linked_fields_ar);$j++) {
$field_values_ar[$j] = $details_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];

} // end for

}
else{
$field_values_ar[0] = $details_row[$field_name_temp];
}

$count_temp_2 = count($field_values_ar);
$details_table .= "<tr><td class=\"td_label_details\"><b>".$fields_labels_ar[$i]["label_field"]."</b></td><td class=\"td_value_details\">";
for ($j=0; $j<$count_temp_2; $j++) {
$field_to_display = get_field_correct_displaying($field_values_ar[$j], $fields_labels_ar[$i]["type_field"], $fields_labels_ar[$i]["content_field"], $fields_labels_ar[$i]["separator_field"], "details_table"); // get the correct display mode for the field

$details_table .= $field_to_display." "; // at the field value to the table
}
$details_table = substr($details_table, 0, -6); // delete the last  
$details_table .= "</td></tr>";

} // end if
} // end for
} // end while
***************************

And replace it with:

***************************
while ($details_row = fetch_row_db($res_details)){ // should be just one

$count_temp = count($fields_labels_ar);
for ($i=0; $i<$count_temp; $i++){
if ($fields_labels_ar[$i]["present_details_form_field"] == "1"){
$field_name_temp = $fields_labels_ar[$i]["name_field"];
$field_value = $details_row[$field_name_temp];
$details_table .= "<tr><td class=\"td_label_details\"><b>".$fields_labels_ar[$i]["label_field"]."</b></td><td class=\"td_value_details\">";
$field_to_display = get_field_correct_displaying($field_value, $fields_labels_ar[$i]["type_field"], $fields_labels_ar[$i]["content_field"], $fields_labels_ar[$i]["separator_field"], "details_table"); // get the correct display mode for the field
$details_table .= $field_to_display." ";
$details_table = substr($details_table, 0, -6); // delete the last  
$details_table .= "</td></tr>";

} // end if
} // end for
} // end while
***************************

G. Go to function build_results_table and look for:

***************************
$results_table .= "<td class=\"".$td_results_class."\">"; // start the cell
$field_name_temp = $fields_labels_ar[$i]["name_field"];
$field_type = $fields_labels_ar[$i]["type_field"];
$field_content = $fields_labels_ar[$i]["content_field"];
$field_separator = $fields_labels_ar[$i]["separator_field"];
$field_values_ar = array(); // reset the array containing values to display,
$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
if ($primary_key_field_field != "")
{$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
$primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
$primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
$linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
$alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];
$linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
for ($j=0;$j<count($linked_fields_ar);$j++)
{
$field_values_ar[$j] = $records_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
} // end for
}
else
{
$field_values_ar[0] = $records_row[$field_name_temp];
}
$count_temp_2 = count($field_values_ar);
for ($j=0; $j<$count_temp_2; $j++)
{
$field_to_display = get_field_correct_displaying($field_values_ar[$j], $field_type, $field_content, $field_separator, "results_table");
if ( $field_to_display == "")
{$field_to_display .= " ";}
$results_table .= $field_to_display." ";
}
$results_table = substr($results_table, 0, -6); // delete the last  
$results_table .= "</td>"; // end the cell
***************************

Replace it with:

***************************
$results_table .= "<td class=\"".$td_results_class."\">"; // start the cell
$field_name_temp = $fields_labels_ar[$i]["name_field"];
$field_type = $fields_labels_ar[$i]["type_field"];
$field_content = $fields_labels_ar[$i]["content_field"];
$field_separator = $fields_labels_ar[$i]["separator_field"];
$field_value = $records_row[$field_name_temp];
$field_to_display = get_field_correct_displaying($field_value, $field_type, $field_content, $field_separator, "results_table");
if ( $field_to_display == "")
{$field_to_display .= " ";}
$results_table .= $field_to_display." ";
$results_table = substr($results_table, 0, -6); // delete the last  
$results_table .= "</td>"; // end the cell
***************************

H. Go to function build_select_part and look for this 'foreach' loop:

***************************
foreach($fields_labels_ar as $field){
if ($field['present_results_search_field'] === '1' || $field['present_details_form_field'] === '1' || $field['name_field'] === $unique_field_name) { // include in the select stataments just the fields present in results or the primary key (useful to pass to the edit form)

// if the field has linked fields, include each linked fields in the select statement and the corresponding table (wiht join) in the from part. Use alias for all in order to mantain name unicity, each field has is own alias_suffix_field so it is easy
if ($field['primary_key_field_field'] !== '') {
$linked_fields_ar = explode($field['separator_field'], $field['linked_fields_field']);

foreach ($linked_fields_ar as $linked_field){
$sql_fields_part .= $quote.$field['primary_key_table_field'].$alias_prefix.$field['alias_suffix_field'].$quote.'.'.$quote.$linked_field.$quote.' AS '.$quote.$linked_field.$alias_prefix.$field['alias_suffix_field'].$quote.', ';
} //end foreach

$sql_from_part .= ' LEFT JOIN '.$quote.$field['primary_key_table_field'].$quote.' AS '.$quote.$field['primary_key_table_field'].$alias_prefix.$field['alias_suffix_field'].$quote;

$sql_from_part .= ' ON ';
$sql_from_part .= $quote.$table_name.$quote.'.'.$quote.$field['name_field'].$quote.' = '.$quote.$field['primary_key_table_field'].$alias_prefix.$field['alias_suffix_field'].$quote.'.'.$quote.$field['primary_key_field_field'].$quote;
} // end if
// if the field has not linked fiel, include just the field in the select statement
else {
$sql_fields_part .= $quote.$table_name.$quote.'.'.$quote.$field['name_field'].$quote.', ';
} // end else
} // end if
} // end foreach
***************************

Replace it with:

***************************
foreach($fields_labels_ar as $field){
if ($field['present_results_search_field'] === '1' || $field['present_details_form_field'] === '1' || $field['name_field'] === $unique_field_name) { // include in the select stataments just the fields present in results or the primary key (useful to pass to the edit form)
$sql_fields_part .= $quote.$table_name.$quote.'.'.$quote.$field['name_field'].$quote.', ';
} // end if
} // end foreach
***************************


5. Edit index.php by looking for this:

***************************
if ($fields_labels_ar[$field_index]["primary_key_field_field"] !== ''){

$linked_fields_ar = explode($fields_labels_ar[$field_index]['separator_field'], $fields_labels_ar[$field_index]['linked_fields_field']);
$is_first = 1;
foreach ($linked_fields_ar as $linked_field){
$sql .= $quote.$linked_field.$alias_prefix.$fields_labels_ar[$field_index]['alias_suffix_field'].$quote;


if ($is_first === 1){ // add the order type just to the first field e.g. order by field_1 DESC, field_2, field_3
$sql .= ' '.$order_type;
$is_first = 0;
} // end if
$sql .= ', ';
} //end foreach
$sql = substr($sql, 0, -2); // deleter the last ', '
} // end if
else{
$sql .= $quote.$table_name.$quote.'.'.$fields_labels_ar[$field_index]["name_field"];
$sql .= ' '.$order_type;
} // end else
**************************

And replace with:

**************************
$sql .= $quote.$table_name.$quote.'.'.$fields_labels_ar[$field_index]["name_field"];
$sql .= ' '.$order_type;
**************************
 
P

Phil von Sassen

Guest
Would be great to receive the changed files via mail.

Thank you in advance and best regards, Phil
 
A

alpha2zee

Guest
You can get the instruction file from the Sourceforge tracker - http://sourceforge.net/tracker/?group_id=39649&atid=425835
 
A

alpha2zee

Guest
A couple of improvements to my first posting:

1. Point 3E:

Make the entire case/break block in that function so -

case "select_multiple":
case "select_multiple_checkbox":
$field_name_temp = $fields_labels_ar[$i]["name_field"];
$sql .= "'";
if (isset($_POST[$fields_labels_ar[$i]["name_field"]])){ // otherwise the user hasn't checked any options

$count_temp_2 = count($_POST[$fields_labels_ar[$i]["name_field"]]);
for ($j=0; $j<$count_temp_2; $j++){
if (!(empty($_POST[$field_name_temp][$j])))
{
$sql .= $fields_labels_ar[$i]["separator_field"].$_POST[$field_name_temp][$j];
$add_last = 'yes';
} // end if
} // end for

if(isset($add_last) and $add_last == 'yes'){$sql .= $fields_labels_ar[$i]["separator_field"];} // add the last separator
} // end if
$sql .= "', ";
break;

2. New:

In business_logic.php, function update_record, put in a new case/break block -

case "select_multiple":
case "select_multiple_checkbox":
$sql .= $quote.$field_name_temp.$quote." = "; // add the field name to the sql statement
$sql .= "'";
$count_temp_2 = count($_POST[$field_name_temp]);
for ($j=0; $j<$count_temp_2; $j++){
if (!(empty($_POST[$field_name_temp][$j])))
{
$sql .= $fields_labels_ar[$i]["separator_field"].$_POST[$field_name_temp][$j];
$add_last = 'yes';
} // end if
} // end for
if (isset($add_last) and $add_last == 'yes'){$sql .= $fields_labels_ar[$i]["separator_field"];} // add the last separator
$sql .= "', ";
break;
 
W

wheat

Guest
Just curious, does this hack work at all with dadabik 3.2 final? I've already had 3.2 final installed.
 
A

alpha2zee

Guest
Yes, it does. If you face problems, post here and I will try to help.
 
D

Dannie

Guest
I'm looking for this feature and here it is!! Thanks alpha2zee! Does this one work with dadabik 4.0 alpha? =D

 
D

Dannie

Guest
I got this error when trying to display table results (with dadabik v4.0a)

Fatal error: Call to undefined function: stripos() in /home/dendad/www/bookreview/include/business_logic.php on line 2357

i went into business_logic.php line 2357 and it's about building the table body? Any idea how to solve this problem?
 
A

alpha2zee

Guest
I should have checked this. Turns out that stripos is a PHP 5-only function. That is in older versions, this function is not built into PHP.

If you cannot upgrade to PHP 5, add this at the bottom of config.php -

// for function stripos - undefined in PHP versions before 5

if(!function_exists('stripos'))
{
function stripos($haystack,$needle,$offset = 0)
{
return(strpos(strtolower($haystack),strtolower($needle),$offset));
}
}

// end function stripos
 
D

Dannie

Guest
alph2zee, the multiple select checkbox works pretty well. but when i tried multi-menu, it printed out the word 'Array' instead... :S

 
A

alpha2zee

Guest
I found another function - strripos - that is missing in PHP versions older than 5. Under certain conditions, therefore, the codes above will give problem. To fix for it (will not affect if running PHP 5), paste this function at bottom of config.php or in business_logic.php. -

// fix for lack of strripos function in PHP older than version 5
if (!function_exists('strripos')) {
function strripos($haystack, $needle, $offset = null)
{
if (!is_scalar($haystack)) {
user_error('strripos() expects parameter 1 to be scalar, ' .
gettype($haystack) . ' given', E_USER_WARNING);
return false;
}

if (!is_scalar($needle)) {
user_error('strripos() expects parameter 2 to be scalar, ' .
gettype($needle) . ' given', E_USER_WARNING);
return false;
}

if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
user_error('strripos() expects parameter 3 to be long, ' .
gettype($offset) . ' given', E_USER_WARNING);
return false;
}

// Manipulate the string if there is an offset
$fix = 0;
if (!is_null($offset)) {
// If the offset is larger than the haystack, return
if (abs($offset) >= strlen($haystack)) {
return false;
}

// Check whether offset is negative or positive
if ($offset > 0) {
$haystack = substr($haystack, $offset, strlen($haystack) - $offset);
// We need to add this to the position of the needle
$fix = $offset;
} else {
$haystack = substr($haystack, 0, strlen($haystack) + $offset);
}
}

$segments = explode(strtolower($needle), strtolower($haystack));

$last_seg = count($segments) - 1;
$position = strlen($haystack) + $fix - strlen($segments[$last_seg]) - strlen($needle);

return $position;
}
}
// end fix for strripos lack

---

I have not tested this myself, but found this on the web. If there are bugs or better fixes, please post.
 
A

alpha2zee

Guest
Hi Dannie,

Can you be more specific? The 'array' appears when viewing item details, in the results table, in edit form, in insert form, or in all of them?

Thank you for trying this. There are so many conditions that arise in dynamic websites and from platform/version issues that it is difficult to test everything before releasing code.

Also, note the second function fix above.
 

Dannie

New member
Hi alpha2zee!

Sorry, the word 'Array' appears in the resulting page. I only have this problem with the Multiple select menu. Multiple Checkbox, on the other hand, works pretty well. The situation was as following:

I just created a multiple select menu for Book Category which contains these options: Advanture, Comedy, Fantasy, Horror, Romance, etc. Then inserted a new record and typed everything in; for the 'Category' field, I chose Advanture and Fantasy. Saved the new entry. Viewed the result page and Detail, all the other data were okay. However, under 'Category', Advanture and Fantasy didn't show up; instead only 'Array' appeared. It seems that multiple options were not successfully saved in the database? Hope this make sense...

and thanks for the new fix! no problem so far. =)

 

alpha2zee

Well-known member
Hi Danny,

I am assuming that you put in the suggestions I had in my posts of 9-16-05 and 9-26-05, above.

Right now, I cannot think of any reason why multiple_checkboxes works but multiple_menu does not for displaying the details. If you look at the modifications, both cases are treated as same in the application logic.

Can you check if in the function get_field_correctly_displaying, you have both the cases together like so? -

case "select_multiple_menu":
case "select_multiple_checkbox":
 

alpha2zee

Well-known member
These bits of code were not presented in my first post.

*****
include/business_logic.php - function build_insert_duplication_form
*****

Find the similar lines in case 'multiple...' and correct them to be so
[pre]
if (isset($_POST[$field_name_temp])){
$count_temp_2 = count($_POST[$field_name_temp]);
[/pre]
(added 12-02-05)

*****
include/business_logic.php - function build_form
*****

Replace entire ''case multiple... break'' block with this

[pre]
case "select_multiple":
case "select_multiple_checkbox":
$what_selected_check = array();
$form .= "<td class=\"td_input_form\">";
if ($fields_labels_ar[$i]["other_choices_field"] == "1")
{$form .= "Choose, and/or type ...<br />";}
else
{$form .= "Choose ...<br />";}
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{$form .= "<select name=\"".$field_name_temp."[]\" id=\"".$field_name_temp."[]\" size=\"".$size_multiple_select."\" multiple=\"multiple\">";}
// if options provided
if ( $fields_labels_ar[$i]["select_options_field"] != "")
{$options_labels_temp = substr($fields_labels_ar[$i]["select_options_field"], 1, -1);
$select_labels_ar = explode($fields_labels_ar[$i]["separator_field"],$options_labels_temp);
$select_labels_ar_number = count($select_labels_ar);
$any_selected_check = array();
for ($j=0; $j<$select_labels_ar_number; $j++){
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{$form .= "<option value=\"".htmlspecialchars($select_labels_ar[$j])."\"";}
elseif ($fields_labels_ar[$i]["type_field"] == "select_multiple_checkbox")
{$form .= "<input type=\"checkbox\" name=\"".$field_name_temp."[]\" id=\"".$field_name_temp."[]\" value=\"".htmlspecialchars($select_labels_ar[$j])."\"";}
if ($form_type == "update" or $form_type == "ext_update")
{
$options_values_temp = $details_row[$field_name_temp];
// in case no separators flank - if was select_single before
$separator_first_check = stripos($options_values_temp, $fields_labels_ar[$i]["separator_field"]);
$separator_last_check = strripos($options_values_temp, $fields_labels_ar[$i]["separator_field"]);
if ($separator_first_check == "0" and $separator_last_check == (strlen($options_values_temp)-1))
{
$options_values_temp = substr($options_values_temp, 1, -1);
}
$select_values_ar = explode($fields_labels_ar[$i]["separator_field"],$options_values_temp);
if ( in_array($select_labels_ar[$j],$select_values_ar ))
{
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{
$form .= " selected=\"selected\"";
}
elseif ($fields_labels_ar[$i]["type_field"] == "select_multiple_checkbox")
{
$form .= " checked=\"checked\"";
}
$what_selected_check[] = $select_labels_ar[$j];
}
}
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{$form .= "> ".$select_labels_ar[$j]."</option>";}
elseif ($fields_labels_ar[$i]["type_field"] == "select_multiple_checkbox")
{$form .= " /> ".$select_labels_ar[$j]."<br />";}
} // end for
} // end if options provided
// if from foreign table
if ($fields_labels_ar[$i]["primary_key_field_field"] != "")
{
// if any value in foreign able that can be used as option
if (get_num_rows_db($res_primary_key) > 0)
{
// get options to build menu
// get number of fields to work with; if only main field, is 1. If one linked field, 2, and so on
$fields_number = num_fields_db($res_primary_key);
// get from all the rows - main and any linked fields
$options_array=array();
while ($primary_key_row = fetch_row_db($res_primary_key))
{
$linked_fields_value = "";
for ($z=1; $z<$fields_number; $z++)
{
$linked_fields_value .= $primary_key_row[$z];
$linked_fields_value .= " - ";
} // end for
$linked_fields_value = substr($linked_fields_value, 0, -3); // delete last " -
// put into array
$options_array[] = $linked_fields_value;
} // end getting options to build menu
// if form is to edit, get current filled values
if ($form_type == "update" or $form_type == "ext_update")
{
// getting current filled in values
$options_values_temp = $details_row[$field_name_temp];
// in case no separators flank - if was select_single type before
$separator_first_check = stripos($options_values_temp, $fields_labels_ar[$i]["separator_field"]);
$separator_last_check = strripos($options_values_temp, $fields_labels_ar[$i]["separator_field"]);
if ($separator_first_check == "0" and $separator_last_check == (strlen($options_values_temp)-1))
{
$options_values_temp = substr($options_values_temp, 1, -1);
}
// put into array; as is something like ~abc~def~ghi~
$select_values_ar = explode($fields_labels_ar[$i]["separator_field"],$options_values_temp);
// to keep track of matches
$what_selected_check = array();
}
// start building menu
foreach ($options_array as $key=>$option_value)
{
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{$form .= "<option value=\"".htmlspecialchars($option_value)."\"";}
elseif ($fields_labels_ar[$i]["type_field"] == "select_multiple_checkbox")
{$form .= "<input type=\"checkbox\" name=\"".$field_name_temp."[]\" id=\"".$field_name_temp."[]\" value=\"".htmlspecialchars($option_value)."\"";}
// show filled in in if in edit form
if ($form_type == "update" or $form_type == "ext_update")
{
if (in_array($option_value, $select_values_ar))
{
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{
$form .= " selected=\"selected\"";
}
elseif ($fields_labels_ar[$i]["type_field"] == "select_multiple_checkbox")
{
$form .= " checked=\"checked\"";
}
$what_selected_check[] = $option_value;
}
} // end showing filled in if form type is edit
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{$form .= "> ".$option_value."</option>";}
elseif ($fields_labels_ar[$i]["type_field"] == "select_multiple_checkbox")
{$form .= " /> ".$option_value."<br />";}
} // end foreach for building menu
} // end if any value in foreign table
} // end if from foreign table
// finish the menu
if ($fields_labels_ar[$i]["type_field"] == "select_multiple")
{$form .= "</select>";}
// start input box if allowed ('other choice')
if ($fields_labels_ar[$i]["other_choices_field"] == "1" and ($form_type == "insert" or $form_type == "update"))
{
$form .= "<br /><input type=\"text\" name=\"".$field_name_temp."[]\" id=\"".$field_name_temp."[]\" maxlength=\"".$fields_labels_ar[$i]["maxlength_field"]."\"";
if ($fields_labels_ar[$i]["width_field"] != "")
{$form .= " size=\"".$fields_labels_ar[$i]["width_field"]."\"";}
else {$form .= " size=\"25\"";}
// start if form is to edit - again; to fill in a value in box
if (($form_type == "update" or $form_type == "ext_update") and (isset($select_values_ar) and isset($what_selected_check)))
{
$for_box_array = array_diff($select_values_ar,$what_selected_check);
if (count($for_box_array)>0)
{
$for_box_string = implode($fields_labels_ar[$i]["separator_field"],$for_box_array);
$form .= " value=\"";
$form .= $for_box_string;
$form .= "\"";
}
}
// end if form is to edit - again; to fill in a value in textbox
$form .= " />";
}
$form .= "</td>";
break;
[/pre]

****
Recommended
****

I also recommend replacing the case select_single block in the same function.

1. It is useful for 'proper display' if you switch between multiple and single select [record field values inserted with multiple select, unlike with single select, are stored with ~ or similar separator in the database; e.g., ~Delhi~Paris~Havana~]

2. The select_single code has a bug. This fixes it. E.g., if the record field value does not equal any of the select_single options, it gets displayed in the 'other choices' textfield.

[pre]
case "select_single":
// current value (for use with editing but not for new insert)
if (!isset($details_row[$field_name_temp])){$details_row[$field_name_temp]="";}
$to_fill = $details_row[$field_name_temp];
// in case field was select_multiple type before, remove separators
$separator_first_check = stripos($to_fill, $fields_labels_ar[$i]["separator_field"]);
$separator_last_check = strripos($to_fill, $fields_labels_ar[$i]["separator_field"]);
if ($separator_first_check == "0" and $separator_last_check == (strlen($to_fill)-1))
{
$to_fill = substr($to_fill, 1, -1);
}
// build
$form .= "<td class=\"td_input_form\">".$select_type_select."<select single=\"single\" name=\"".$field_name_temp."\" id=\"".$field_name_temp."\">";
if ($fields_labels_ar[$i]["other_choices_field"] == "1")
{$form .= "<option value=\"\">Choose one, or type ...</option>";}
else
{$form .= "<option value=\"\">Choose one ...</option>";}
// generate options for pull down menu
$field_temp = substr($fields_labels_ar[$i]["select_options_field"], 1, -1); // delete the first and the last separator: ~Paris~London~Delhi~
if (trim($field_temp) !== '')
{
$select_values_ar = explode($fields_labels_ar[$i]["separator_field"],$field_temp);
$count_temp = count($select_values_ar);
$any_selected_check = array();
for ($j=0; $j<$count_temp; $j++)
{
$form .= "<option value=\"".htmlspecialchars($select_values_ar[$j])."\"";
// if form to edit
if (($form_type == "update" or $form_type == "ext_update") and ($select_values_ar[$j] == $to_fill))
{
$form .= " selected =\"selected\"";
$any_selected_check[] = "yes";
}
else
{
$any_selected_check[] = "no";
}
$form .= ">".$select_values_ar[$j]."</option>";
} // end if form to edit
} // end generating options
if ($fields_labels_ar[$i]["primary_key_field_field"] != "") // if from foreign table
{
$any_selected_check = array();
if (get_num_rows_db($res_primary_key) > 0)
{
// get values from foreign table
$fields_number = num_fields_db($res_primary_key);
while ($primary_key_row = fetch_row_db($res_primary_key))
{
$primary_key_value = $primary_key_row[0];
$linked_fields_value = "";
for ($z=1; $z<$fields_number; $z++)
{$linked_fields_value .= $primary_key_row[$z];
$linked_fields_value .= " - ";
} // end for
$linked_fields_value = substr($linked_fields_value, 0, -3); // delete last " -
$form .= "<option value=\"".htmlspecialchars($primary_key_value)."\"";
if (($form_type == "update" or $form_type == "ext_update") and ($primary_key_value == $to_fill))
{
$form .= " selected =\"selected\"";
$any_selected_check[] = "yes";
}
else
{
$any_selected_check[] = "no";
}
$form .= ">".$linked_fields_value."</option>";
} // end while
} // end if
} // end if from foreign table
$form .= "</select>";
// input box - if user allowed to type in other choice
if ($fields_labels_ar[$i]["other_choices_field"] == "1" and ($form_type == "insert" or $form_type == "update"))
{$form .= "<br /><input type=\"text\" name=\"".$field_name_temp."_other____"."\" id=\"".$field_name_temp."_other____"."\" maxlength=\"".$fields_labels_ar[$i]["maxlength_field"]."\"";
if ($fields_labels_ar[$i]["width_field"] != "")
{$form .= " size=\"".$fields_labels_ar[$i]["width_field"]."\"";}
if (!in_array("yes", $any_selected_check))
{$form .= " value=\"".htmlspecialchars($to_fill)."\"";}
$form .= " />";
} // end box for other choice
$form .= "</td>";
break;
[/pre]

****

These code pieces have been added to the DaDaBik 'patch' file mentioned in the first post.

Please post if this does not solve your problem or if it creates other problems.

Because of the multiple modifications needed for the 'multiple' functionality, and because I had been working with my own modified DaDaBik, I missed this part about function build_form when I released the code. My apologies.



Post Edited (12-02-05 16:38)
 

Shadow44

New member
Absolutely brilliant mod - thank you!

I have everything working great except one problem I hope you could help me on ... it's maybe similar to Dannie's above.

My select_multiple_checkbox is working great, but select_multiple_menu on edit, insert and search pages just shows as blank.

I'm trying your mod on DaDaBIK v4.0 alpha.

I've done the whole mod from your "slightly improved" text file.

Plus, I have MySQL 4.1.12, so I added the above "strripos" pre-v5 code at the bottom of business_logic.php, but still getting the same thing.

Thanks in advance for your help.

P.S.: Tiny typo above - in your post of 10-03-05 above you reference "function get_field_correctly_displaying" but I'm sure you must mean "function get_field_correct_displaying".
 
Top