我有一个小问题,我使用PHP表单从我创建的联系表单中获得答案。
这是php:
$email_message .= "E-Commerce: \n";
$email_message .= (isset($_POST['no-credit'])) ?
"No credit card: $".implode(" ", $_POST['no-credit'])."\n" : '';
$email_message .= (isset($_POST['paypal'])) ?
"Paypal: $".implode(" ", $_POST['paypal'])."\n" : '';
当我收到电子邮件时," paypal"或"没有信用"没有检查"电子商务:"还是出现了。我试过像:
$email_message .= (isset($_POST['no-credit'])) ? (isset($_POST['paypal'])) ?
"E-Commerce: \n";
$email_message .= (isset($_POST['no-credit'])) ?
"No credit card: $".implode(" ", $_POST['no-credit'])."\n" : '';
$email_message .= (isset($_POST['paypal'])) ?
"Paypal: $".implode(" ", $_POST['paypal'])."\n" : '';
但是它不起作用,我感觉就像我不远,但我无法抓住它。
由于
答案 0 :(得分:1)
将您的条件更改为!empty()
您还错过了其他部分的三元条件中的:
部分,
$email_message .= (!empty($_POST['no-credit']) ) ?
"No credit card: $".implode(" ", $_POST['no-credit'])."\n" : "";
答案 1 :(得分:0)
像这样改变你的第二个例子。但是,当我尝试使用我的localhost时,它正在使用此代码。
$email_message .= (!empty($_POST['no-credit'])) ? ((!empty($_POST['paypal'])) ?"E-Commerce: \n":""):"";
$email_message .= (empty($_POST['no-credit'])) ?
"No credit card: $".implode(" ", $_POST['no-credit'])."\n" : '';
$email_message .= (empty($_POST['paypal'])) ?
"Paypal: $".implode(" ", $_POST['paypal'])."\n" : '';