我有以下形式如何實現代碼檢查到我的提交表單
<form action="/wp-content/themes/wallstreet/welcome.php" method="post" class="basic-grey">
<h1>Form
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Your Nickname* :</span>
<input id="name" type="text" name="name" placeholder="It will appear in the text" />
</label>
<label>
<span>Your Email* :</span>
<input id="email" type="email" name="email" placeholder="Valid Email Address" />
</label>
<label>
<span>Message* :</span>
<textarea id="messagebook" name="messagebook" placeholder="The text that will appear" maxlength="80"></textarea>
</label>
<label>
<span>Code* :</span>
<input id="code" type="text" name="code" placeholder="The Code That we sent to your email" maxlength="8" />
</label>
<label>
<span> </span>
<input type="submit" class="button" value="Send" />
</label>
</form>
它使用下面的PHP,這PHP基本上張貼消息值轉換成txt文件
<?php
$var = $_POST['messagebook'];
file_put_contents("/var/www/wordpress/wp-content/themes/wallstreet/data.txt", $var . "\n", FILE_APPEND);
exit();
?>
但我只要我的代碼字段與存儲在像這樣的txt文件中的代碼匹配就可以工作提交按鈕
zACHAS5r
rKUzob3X
omqYjVQZ
BeF375BG
rFKQomMX
y8EVBTGH
Z7icxNoD
wnZ5qBvK
ftbPiCZa
sXJKDETK
wYDVLDPd
AjURjBdZ
LZR4fbtk
gmFY89TV
BAWDxpZ2
bGLLd9Az
qg4C93wN
YJnrDh2c
jwH6hV9h
tm3S4f5j
MU2ikfbu
ZXnUpfmY
hijZPTk4
C2oWha3T
irTg9oUA
jmjLDvL3
jUbiBtJo
gCCAQx6Z
Theorically我可以使它與此代碼工作,但我不知道哪裏來實現它
function is_valid($code)
{
return in_array($code , explode(' ',file_get_contents('coderoute')));
}
EDIT1:Currrently我都這樣了,我得到這個錯誤
<?php
function is_valid($code)
{
return in_array($code , explode(' ',file_get_contents("/wp-content/themes/wallstreet/codes.txt")));
}
$code = $_POST['code'];
if (is_valid($code)) {
$var = $_POST['messagebook'];
file_put_contents("/var/www/wordpress/wp-content/themes/wallstreet/data.txt", $var . "\n", FILE_APPEND);
}
exit();
?>
PHP的警告: file_get_contents(/wp-content/themes/wallstreet/codes.txt):未能成功 打開流: /var/www/wordpress/wp-content/themes/wallstreet/welcome.php沒有這樣的文件或目錄在線4,
'if(is_valid){add_to_file}' –