下面是我有的代碼,它檢查文本框是否爲空,然後在文本框旁邊提交警告,一旦點擊提交。php - 停止php如果空文本框和處理其他html形式
<?php
if(isset($_POST["submit"])) {
$fqdn = $_POST["fqdn"];
$ip = $_POST["ip"];
$fileText = $fqdn."\n".$ip;
$file = fopen("inputFile.txt","w");
fwrite($file, $fileText);
fclose($file);
}
?>
<form action = "<?php $_PHP_SELF ?>" method = "post">
<table style= "width:400px">
<tr class="spaceUnder">
<td><b>FQDN:</b></td>
<td><input type="text" name="fqdn" placeholder="server.domain.com"/></td>
<td> <?php if(isset($_POST['fqdn']) && $_POST['fqdn'] == ''){ echo "<font color='red'>FQDN cannot be empty</font>";} ?> </td>
</tr>
<tr class="spaceUnder">
<td><b>IP:</b></td>
<td><input type="text" name="ip" placeholder="***.***.***.***"/></td>
<td> <?php if(isset($_POST['ip']) && $_POST['ip'] == ''){ echo "<font color='red'>IP cannot be empty</font>"; } ?> </td>
</tr>
<tr>
<td align="center" colspan="2">
<input type = "submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
點擊提交後,php仍然在寫入文件。如果我給退出()或返回false;在下面的步驟:
<td> <?php if(isset($_POST['fqdn']) && $_POST['fqdn'] == ''){ echo "<font color='red'>FQDN cannot be empty</font>"; exit();} ?> </td>
表格變得不完整,意味着,IP文本框和提交按鈕將不存在。任何方式使它正確?
你爲什麼不穿上提交代碼 –
這一條件如果值是空曠的迴音否則警告執行代碼 –
我們如何可以打印文本框旁邊的警告,如果我在提交的代碼塊。這雲幫助。 – Joshi