so created contact form , works want show alert message after form submission did using iframe , targeting form iframe , echo alert iframe takes white space , alot of height if make height 1px what want do: -remove space of iframe -or find way alert withour iframe
here 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 :" 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>
here 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 sent")'; echo '</script>'; } else { echo '<script language="javascript">'; echo 'alert("something went wrong, go , try again.")'; echo '</script>';; } } } ?>
note:i used iframe show alert message on index.html page , not php page iframe empty , takes place after form
best way is:
- catch submit event js. submit form ajax.
- your php responds message (not script).
echo 'sent'
orecho 'failed'
. - in success method in ajax call, call alert method after checking response php (string sent or failed).
i recomment use jquery this. check out $.ajax method , $.post method more information.
good simple example in w3schools
your js code should this:
$("button").click(function(){ $.ajax({url: "your php file url", success: function(result){ if(result === 'sent') { // alert here } }}); });
Comments
Post a Comment