POST変数が定義されていない場合、alert()(javascript)のような関数をPHPに組み込みます。しかし、私はそれがポーズをとっていればいいのではない。PHPの__constructにJavascript関数を実行する方法
class Su{
private $nomb;
private $dir;
private $tel;
public function __CONSTRUCT($mode){
try {
if(isset($_POST['nomb'])) {
?>
<script language="javascript">alert("Sorry, this field can't be empty ")</script>
<?php
throw new Exception('?view=sucursal&mode=' . $mode . '&error=define');
}
} catch(Exception $error) {
header('location: '.$error->getMessage());
exit;
}
$this->nomb = strtoupper($_POST['nomb']);
$this->dir = strtoupper($_POST['dir']);
$this->tel = strtoupper($_POST['tel']);
}
public function __GET($var){ return $this->$var; }
public function __SET($var, $valor){ return $this->$var = $valor; }
}
変更 '場合(ISSET($ _ POST [ 'nomb']))'と 'の場合(!のISSET($ _ POST [ 'nomb']))' –
あなたが直接することはできません。あなたはあなたのAJAXコール(AJAXと仮定)でこれを処理する必要があります – Farkie
@ Farkieなぜですか?彼が通常のPOST要求(ajaxなし)を使用している場合、それは動作します。 –