テキスト ボックスを空のままにすると、テキスト ボックスの横にエラーが表示されます。例: タイプは必須です。すべての検証を定義するトレード フォームのファイル名 result.php と、データベースに挿入する price.php があります。エラーがない場合にデータベースに挿入できる最初の if ステートメントに入ります。しかし実際には、すべてのエラーを表示する空のフォームを送信しました。それは起こっていません。エラーがあっても price.php(insert) にフォームを送信します。すべての回答に感謝
<?php
$selection = '';
$type = '';
$size = '';
$bidprice = '';
$offerprice = '';
$stoploss = '';
$takeprofit = '';
////////////////////////////////
$Error = '';
$selectionError = '';
$typeError = '';
$sizeError = '';
$bidpriceError = '';
$offerpriceError = '';
$stoplossError = '';
$takeprofitError = '';
$message = '';
$errors = array();
$noErrors = true;
$haveErrors = !$noErrors;
require_once('validations/tradeformresult.php');
if ($noErrors && $userArriveBySubmittingAForm) {
require_once('price.php');// INSERTION
echo "<script type='text/javascript'>\n";
echo "alert('Trade is successfully executed!');\n";
echo "</script>";
///////////MESSAGE/////////////////
}
else if ($haveErrors && $userArriveBySubmittingAForm) {
echo "<script type='text/javascript'>\n";
echo "alert('Please re-enter your parameters.);\n";
echo "</script>";
$message = "\t\t" . '<font color="red">Fail!</font><br />' . "\n";
$message = $message . "\t\t" . 'Validation errors : <br />' . "\n";
$message = $message . "\t\t" . '<ol>' . "\n";
foreach ($errors as $key=>$errorMessage) {
$message = $message . "\t\t\t" . '<li>' . $errorMessage . '</li>' . "\n";
if ($key == 'selection') {
$selectionError = $errorMessage;
}
if ($key == 'type') {
$typeError = $errorMessage;
}
if ($key == 'size') {
$sizeError = $errorMessage;
}
if ($key == 'bidprice') {
$bidpriceError = $errorMessage;
}
if ($key == 'offerprice') {
$offerpriceError = $errorMessage;
}
if ($key == 'stoploss') {
$stoplossError = $errorMessage;
}
if ($key == 'takeprofit') {
$takeprofitError = $errorMessage;
}
}
$message = $message . "\t\t" . '</ol>' . "\n";
}
else if ($userArriveByClickingOrDirectlyTypeURL) { // we put the original form inside the $message variable
$newTitle = 'The link is broken';
$h1Title = '';
$message = '';
}
?>
トレードフォームの結果
$userArriveBySubmittingAForm = !empty($_POST);
// user arrives by GET
$userArriveByClickingOrDirectlyTypeURL = !$userArriveBySubmittingAForm;
// check if user arrives here via a POSTBACK
if ($userArriveBySubmittingAForm) {
$selectionNotGiven = empty($_POST['selection']);
// if name not given
if ($selectionNotGiven) {
// we add new error into $errors
$errors['selection'] = "Symbol is required";
}
$typeNotGiven = empty($_POST['type']);
// if name not given
if ($typeNotGiven) {
// we add new error into $errors
$errors['type'] = "Type is required";
}
$sizeNotGiven = empty($_POST['size']);
// if name not given
if ($sizeNotGiven) {
// we add new error into $errors
$errors['size'] = "Size is required";
}
$bidpriceNotGiven = empty($_POST['bidprice']);
// if name not given
if ($bidpriceNotGiven) {
// we add new error into $errors
$errors['bidprice'] = "Bid Price is required";
$offerpriceNotGiven = empty($_POST['offerprice']);
// if name not given
if ($offerpriceNotGiven) {
// we add new error into $errors
$errors['offerprice'] = "Offer price is required";
$stoplossInvalid = ($_POST['stoploss'])>($_POST['offerprice'])||($offernodecimal-$stoplossnodecimal)< 200
||($_POST['stoploss'])<($_POST['bidprice'])||($bidnodecimal-$stoplossnodecimal)< 200;
if ($stoplossInvalid) {
// we add new error into $errors
$errors['stoploss'] = "Stop Loss is invalid";
}
$takeprofitInvalid = ($_POST['takeprofit'])<($_POST['offerprice'])||($takeprofitnodecimal-$bidnodecimal)< 200
||($_POST['takeprofit'])>($_POST['bidprice'])||($offernodecimal-$takeprofitnodecimal)< 200;
if ($takeprofitInvalid) {
// we add new error into $errors
$errors['takeprofit'] = "Take Profit is invalid";
}
}
$noErrors = (count($errors) == 0);
// haveErrors is the opposite of noErrors
$haveErrors = !$noErrors;
if (!empty($_POST['selection'])) {
$selection = $_POST['selection'];
} // end if name NOT empty
if (!empty($_POST['type'])) {
$type = $_POST['type'];
} // end if name NOT empty
if (!empty($_POST['size'])) {
$size = $_POST['size'];
} // end if password NOT empty
if (!empty($_POST['bidprice'])) {
$bidprice = $_POST['bidprice'];
} // end if password NOT empty
if (!empty($_POST['offerprice'])) {
$offerprice = $_POST['offerprice'];
} // end if sex NOT empty
if (!empty($_POST['stoploss'])) {
$stoploss = $_POST['stoploss'];
} // end if sex NOT empty
if (!empty($_POST['takeprofit'])) {
$takeprofit = $_POST['takeprofit'];
} // end if diploma NOT empty
}
}
// end if no errors
/** end of proceed as normal **/
// @TODO code expected here to assign the variables in Ex1-5/registerform.php lines 10-17
// remember that $interests is an array, so we need to check $_POST['interests'] for empty and also ????
/** end of proceed as normal **/
?>