Page 1 of 1
Form_CustomValidate for GridEdit and MultiEdit
Posted: Wed Nov 30, 2022 8:55 pm
by totza2010
Form_CustomValidate for GridEdit and MultiEdit not work.
// Form Custom Validate event
function Form_CustomValidate(&$customError)
{
$myCount = ExecuteScalar("SELECT COUNT(*) FROM stock WHERE stock.StockSerialNumber = "."'".CurrentPage()->InboundItemSerialNumber->CurrentValue."'"."");
$Language = Container("language");
if ($myCount != 0) {
$this->InboundItemSerialNumber->addErrorMessage($Language->phrase("Duplicated"));
return false;
}
return true;
}
when the above conditions are met You'll usually see a Error message below the input field. But in the latest template No error message appears, but the gridedit or multiedit page is closed and the data is not edited.
Re: Form_CustomValidate for GridEdit and MultiEdit.
Posted: Wed Nov 30, 2022 10:00 pm
by mobhar
Make sure you have already enabled Server-side under PHP -> General Options -> Validation, after that re-generate ALL the script files again.
Re: Form_CustomValidate for GridEdit and MultiEdit.
Posted: Thu Dec 01, 2022 9:52 am
by totza2010
I already set accordingly. Normal template version 6 is still usable. When testing the system again in the latest version 7 templates, it does not work.
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 10:06 am
by mobhar
Did you have "Duplicated" phrase in your .xml language file?
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 10:15 am
by arbei
- You should use
$this
instead of CurrentPage()
, although it also works,
- Make sure the form has the field "InboundItemSerialNumber" included or
$this->InboundItemSerialNumber->CurrentValue
does not have value.
- You should use
AdjustSql($this->InboundItemSerialNumber->CurrentValue)
to avoid SQL injection.
- Enable Debug and check for errors in the log file.
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 11:04 am
by totza2010
mobhar wrote:
Did you have "Duplicated" phrase in your .xml language file?
Yes.
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 11:16 am
by totza2010
arbei wrote:
- You should use
$this
instead of CurrentPage()
, although it also works,
- Make sure the form has the field "InboundItemSerialNumber" included or
$this->InboundItemSerialNumber->CurrentValue
does not have value.
- You should use
AdjustSql($this->InboundItemSerialNumber->CurrentValue)
to avoid SQL injection.
- Enable Debug and check for errors in the log file.
I already have an error to file setting but no error pops up. When opening the inspect page in chrome and checking it, it pops up saying...
{success: false, error: ""}
error: ""
success: false
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 11:54 am
by arbei
arbei wrote:
Enable Debug and check for errors in the log file.
You are using server side Form_CustomValidate, you should check server side error in the log file. You may also add your own log to debug your code, e.g.
$sql = "SELECT COUNT(*) FROM stock WHERE stock.StockSerialNumber ...";
$myCount = ExecuteScalar($sql);
Log("Form_CustomValidate", [$this->InboundItemSerialNumber->CurrentValue, $sql, $myCount]);
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 12:19 pm
by totza2010
// Form Custom Validate event
public function formCustomValidate(&$customError)
{
$sql = "SELECT COUNT(*) FROM stock WHERE stock.StockSerialNumber = "."'".$this->InboundItemSerialNumber->CurrentValue."'"."";
$myCount = ExecuteScalar($sql);
Log("Form_CustomValidate", [$this->InboundItemSerialNumber->CurrentValue, $sql, $myCount]);
$myCount = ExecuteScalar("SELECT COUNT(*) FROM stock WHERE stock.StockSerialNumber = "."'".$this->InboundItemSerialNumber->CurrentValue."'"."");
$Language = Container("language");
if ($myCount != 0) {
$this->InboundItemSerialNumber->addErrorMessage(Language()->phrase("Duplicated"));
return false;
}
return true;
}
Log file.
[2022-12-01T11:17:56.740268+07:00] log.DEBUG: Form_CustomValidate [null,"SELECT COUNT(*) FROM stock WHERE stock.StockSerialNumber = ''",0] []
[2022-12-01T11:18:17.794742+07:00] log.DEBUG: Form_CustomValidate ["gj","SELECT COUNT(*) FROM stock WHERE stock.StockSerialNumber = 'gj'",1] []
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 12:46 pm
by arbei
Since you use server side Form_CustomValidate, make sure you have enabled "Server-side validation".
You may provide complete information for testing. Have you enabled any one of below? (Assume you use v2023)
- Use Ajax Actions
- Infinite Scroll Table
- Modal GridEdit and MultiEdit
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Thu Dec 01, 2022 1:12 pm
by totza2010
Since you use server side Form_CustomValidate, are you sure you have enabled "Server-side validation"?
You may provide complete information for testing. Have you enabled any one of below? (Assume you use v2023)
Use Ajax Actions - Yes.
Infinite Scroll Table - No.
Modal GridEdit and MultiEdit - I Use Modal.
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Mon Dec 05, 2022 11:52 am
by Webmaster
Re: Form_CustomValidate for GridEdit and MultiEdit
Posted: Wed Dec 07, 2022 1:17 pm
by totza2010
Tried the latest version. can now be used normally