检查用户输入是否匹配值数组。 PHP
|
如果用户输入与我的数组中的邮政编码匹配的邮政编码,然后单击“转到”,则我有一个字段(用于邮政编码),然后单击“转到”-如果没有,则将它们重定向到下一步-显示“超出我们的服务范围”信息。表单和php脚本在同一页面上。到目前为止,我该怎么做?
<form>
<input type=\"text\" id=\"zipcode\" name=\"zipcode\" />
<input type=\"submit\" id=\"submit\" value=\"GO\" />
</form>
<?php
$allowedzips = array(\"10051\", \"10061\", \"10071\", \"10081\");
$input = echo $_POST[\"zipcode\"];
$input = str_split($input);
$message = \"Out of our service area\";
foreach($input as $zip) {
if (in_array($zip, $allowedzips)) {
$message //redirect goes here
break;
}
}
echo $message;
?>
没有找到相关结果
已邀请:
3 个回复
香腔弥胯瓤
确保为
,因为这将阻止脚本进一步执行。
闲窍
然后在提交呼叫时,将邮政编码传递给checkZipCode。
墩瓣茅械
函数确定要查找的元素是否在有效邮政编码列表中,并进行相应的重定向。