jQueryデータテーブルエディタプラグインを使用すると、次のコードが意図したとおりに動作します。指定された検証を実行します(簡略化のためにいくつかのフィールドは省略されています)。スペースをトリムした後のjQueryデータセットでのインライン編集による検証
Editor::inst($db, 'file_upload')
->fields(
Field::inst('id')->validator('Validate::notEmpty'),
Field::inst('name')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
return $length > 30 ? 'Length must be 30 characters or less' : true;
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('document_title')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
return $length > 50 ? 'Length must be 50 characters or less' : true;
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('email_address')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
return $length > 60 ? 'Length must be 60 characters or less' : true;
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
})
)->where(function ($q) {
$q->where('file_type', "('jpg', 'jpeg', 'gif', 'png')", 'IN', false);
})->process($_POST)
->json();
しかし、検証ロジックが僅かこの場合以下、
Editor::inst($db, 'file_upload')
->fields(
Field::inst('id')->validator('Validate::notEmpty'),
Field::inst('name')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
// The following line has been modified
return $length === 0 ? 'This field is required' : ($length > 30 ? 'Length must be 30 characters or less' : true);
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('document_title')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
// The following line has been modified
return $length === 0 ? 'This field is required' : ($length > 50 ? 'Length must be 50 characters or less' : true);
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
}),
Field::inst('email_address')->validator('Validate::notEmpty')
->validator(function ($val, $data, $opts) {
$length = strlen(trim(preg_replace('/\s+/', ' ', $val)));
// The following line has been modified
return $length === 0 ? 'This field is required' : ($length > 60 ? 'Length must be 60 characters or less' : true);
})->getFormatter(function ($val, $data, $opts) {
return htmlspecialchars($val, ENT_QUOTES, "UTF-8");
})->setFormatter(function ($val, $data, $opts) {
return trim(preg_replace('/\s+/', ' ', $val));
})
)->where(function ($q) {
$q->where('file_type', "('jpg', 'jpeg', 'gif', 'png')", 'IN', false);
})->process($_POST)
->json();
ように変更されたとき、彼らはなく、値が送信されないべきである(そして同時にデータテーブルが更新されていない)として、検証が実行されますデータベースに転送します。 Enterキーを押すと、インライン編集のテキストボックスが開いたままになります。
何故その理由と修正方法はありますか?おそらく、私はPHPについて非常に基本的なものを見逃しています。
必要に応じて、対応するクライアントスクリプトを投稿します。
余分な条件は、抽象層、データベースに送信されることからの入力値を防止施行されている場合、他のバリデータがトリガされていることが表示されます。これは、インラインセル編集の場合には起こりません。
どのような救済策ですか?