Well, my idea was not that good but, trying it I found the origin of the problem and fixed it!
After an error occurred there is not much happening, a new object $cInfo is created, an associative array with fields name as key and parameters as values. So I checked if it was populated and all was looking OK except I found out some fields names/keys were different from when you first open (edit) this page. And guess which fields it was, those that got blank!
I did a quick fix by making old and new fields names equal. Around line 372 where you have
PHP Code:
} else {
if ($error == true) {
$cInfo = new objectInfo($_POST);
$processed = true;
I changed it to:
PHP Code:
} else {
if ($error == true) {
$cInfo = new objectInfo($_POST);
$cInfo->company = $cInfo->entry_company;
$cInfo->street_address = $cInfo->entry_street_address;
$cInfo->suburb = $cInfo->entry_suburb;
$cInfo->postcode = $cInfo->entry_postcode;
$cInfo->city = $cInfo->entry_city;
$cInfo->state = $cInfo->entry_state;
$processed = true;
Blank fields problem is fixed but there were still other problems. DOB and email address need some checking and error message if necessary. Around lines 647 and 676 (after above fix) there is a line like this that I changed to this for DOB:
PHP Code:
);
echo($error == true && $entry_date_of_birth_error == true ? ' ' . ENTRY_DATE_OF_BIRTH_ERROR : '');?>
And this for email address:
PHP Code:
);
echo($error == true && $entry_email_address_check_error == true ? ' ' . ENTRY_EMAIL_ADDRESS_ERROR : '');?>
Now, in case of wrong entry a message will appear under concerned field.
But it is not over yet! Date validation is buggy and will bring an error 500 if you make an error in filling any field of the form. PHP checkdate function needs integers as arguments. I added '(int)' in lines 143, 144 and 145 to solve that.
No more crash, well nearly... The order of parameters sent to checkdate function is designed for dates coming from database and already sanitized to this format 'yyyymmdd'. When updating with American date mm/dd/yyyy everything got messed up! I added a condition in the if test to accept this format as well. Code is now like this:
PHP Code:
if (ACCOUNT_DOB == 'true') {
if (checkdate(
(int)substr(zen_date_raw($customers_dob), 4, 2),
(int)substr(zen_date_raw($customers_dob), 6, 2),
(int)substr(zen_date_raw($customers_dob), 0, 4)
) || checkdate(
(int)substr(zen_date_raw($customers_dob), 0, 2),
(int)substr(zen_date_raw($customers_dob), 3, 2),
(int)substr(zen_date_raw($customers_dob), 6, 4)
)) {
$entry_date_of_birth_error = false;
To make it work with Great Britain and few other European countries date format dd/mm/yyyy, following code should be added too:
PHP Code:
) || checkdate(
(int)substr(zen_date_raw($customers_dob), 3, 2),
(int)substr(zen_date_raw($customers_dob), 0, 2),
(int)substr(zen_date_raw($customers_dob), 6, 4)
There was a lot to fix and there is still few things to improve too in this file... For example First name is not mandatory, design or bug I don't know but I think it should be, I changed this around line 600:
PHP Code:
) . ' class="form-control" id="customers_firstname" minlength="' . ENTRY_FIRST_NAME_MIN_LENGTH . '"'
To
PHP Code:
) . ' class="form-control" id="customers_firstname" minlength="' . ENTRY_FIRST_NAME_MIN_LENGTH . '"',
true
That should be all for today, I will post this on GitHub issue tomorrow.
Bookmarks