Form_CustomValidate for GridEdit and MultiEdit

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
totza2010
User
Posts: 107

Form_CustomValidate for GridEdit and MultiEdit

Post 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.


mobhar
User
Posts: 11660

Post by mobhar »

Make sure you have already enabled Server-side under PHP -> General Options -> Validation, after that re-generate ALL the script files again.


totza2010
User
Posts: 107

Post 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.


mobhar
User
Posts: 11660

Post by mobhar »

Did you have "Duplicated" phrase in your .xml language file?


arbei
User
Posts: 9286

Post by arbei »

  1. You should use $this instead of CurrentPage(), although it also works,
  2. Make sure the form has the field "InboundItemSerialNumber" included or $this->InboundItemSerialNumber->CurrentValue does not have value.
  3. You should use AdjustSql($this->InboundItemSerialNumber->CurrentValue) to avoid SQL injection.
  4. Enable Debug and check for errors in the log file.

totza2010
User
Posts: 107

Post by totza2010 »

mobhar wrote:

Did you have "Duplicated" phrase in your .xml language file?

Yes.


totza2010
User
Posts: 107

Post by totza2010 »

arbei wrote:

  1. You should use $this instead of CurrentPage(), although it also works,
  2. Make sure the form has the field "InboundItemSerialNumber" included or $this->InboundItemSerialNumber->CurrentValue does not have value.
  3. You should use AdjustSql($this->InboundItemSerialNumber->CurrentValue) to avoid SQL injection.
  4. 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


arbei
User
Posts: 9286

Post 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]);

totza2010
User
Posts: 107

Post 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] []

arbei
User
Posts: 9286

Post 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

totza2010
User
Posts: 107

Post by totza2010 »

Since you use server side Form_CustomValidate, are you sure you have enabled "Server-side validation"?

  • yes, I am sure.

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.


Webmaster
User
Posts: 9425

Post by Webmaster »

Try v2023.8.0.


totza2010
User
Posts: 107

Post by totza2010 »

Tried the latest version. can now be used normally


Post Reply