Topic: function customer_list_low

I have an issue with customer list row that is strange I don't think there is an issue in the function. I don't know what is going on.

This is how I'm calling it:

customer_list_row(_("Customer:"), 'debtor_no', isset($_POST['debtor_no']) ? $_POST['debtor_no'] : null, false, true);

I'm having an issue with selected_id for editing a form. I have tried manually entering a client as int 3 and string '3' also null since I'm passing update. But, it is not showing selected in the browser. It is giving me a random one. the strangest thing is it shows selected in the source and chrome inspector. have you seen anything like this before? my branch_list is working correctly below it. I have the form wrapped in a div for ajax for a few buttons and everything is working fine there.

Re: function customer_list_low

Here is how it is called elsewhere:
Line 64 in gl/includes/ui/gl_bank_ui.inc

customer_list_row(_("Customer:"), 'person_id', null, false, true, false, true);

Line 29 in sales/includes/ui/sales_credit_ui.inc and Line 267 in sales/includes/ui/sales_order_ui.inc

customer_list_row(_("Customer:"), 'customer_id', null, false, true, false, true);

Line 195 in sales/manage/recurrent_invoices.php

customer_list_row(_("Customer:"), 'debtor_no', null, " ", true);

Check the 2nd and 3rd arguments in your construct. You can try to use an intermediary variable for the isset() argument.

Re: function customer_list_low

Yeah I was looking over and noticed the 3rd example

Line 195 in sales/manage/recurrent_invoices.php

customer_list_row(_("Customer:"), 'debtor_no', null, " ", true);

I was wondering why the space for 3rd arg. It should become true since it has a space but strange.

I'm going to look it over tomorrow there has to be something I'm missing, maybe I'll try another browser. So strange that the generated source has the correct id as selected. Maybe it's a time / buffer issue.

Re: function customer_list_low

SOLVED: Customer Dropdown Showing Two Selected Options on Edit

Problem: When editing a record, the customer dropdown (`debtor_no`) was incorrectly showing two selected customers. The correct customer ID for the record was present in the `$_POST` data, but the dropdown also selected the record's primary key ID.

Cause: The issue stemmed from how the `$_POST` array was populated during the edit operation. Instead of explicitly setting each form field value from the fetched database row (`$myrow`) to its corresponding associative key in `$_POST`, the entire `$myrow` array was directly assigned to `$_POST`. This resulted in `$_POST` containing both associative keys (column names) and numerical indexes (based on the order of columns fetched).

The `combo_input` function, used to generate the dropdown, was likely accessing the `$_POST` array and inadvertently picking up the value at index `0` (which was the record's primary key `id`) in addition to the correct `debtor_no`. This led to both IDs being included in the `$selected_id` array processed by `combo_input`, causing both options to be marked as `selected` in the HTML.

Fix: To resolve this, ensure that you explicitly set each relevant form field value in the `$_POST` array using the associative keys from your fetched database row.

Incorrect (Causing the Issue):

$_POST = $myrow;

ie. Don't be lazy like me

Correct (Explicitly Setting Values):

$_POST['debtor_no'] = $myrow['debtor_no'];
$_POST['other_field'] = $myrow['other_field'];
// ... and so on for all your form fields

By explicitly assigning the values, you prevent the numerical indexes from being present in the `$_POST` array and thus avoid the `combo_input` function mistakenly selecting the record's primary key ID.

Re: function customer_list_low

Very good troubleshooting.
Kudos @trafficpest.

@joe: are there any other scripts that will benefit from this?