簡體   English   中英

使用iframe將表單發送到php

[英]sending form to php with iframe

我寫一個形式,即用戶可以發送信息,並附加文件,其通過電子郵件發送給特定的用戶。

我建立了HTML表單,並且因為我不想刷新頁面,所以我通過隱藏的iframe發送了該表單。

一切正常,直到我將驗證碼添加到表單中。 現在我有一個問題。 我將生成的驗證碼字符串存儲在主表單頁面的會話中。 但由於形態從一個iframe發送我認為PHP是創建一個新的會話,里面是空的。

誰能建議我如何將iframe和表單頁面連接到同一會話? 我想提一提,iframe要動態地由JavaScript,當用戶點擊發送表單創建。

謝謝你的建議!

編輯:我的代碼HTML表單頁面:

<input type="text" name="name"/><br />
<input type="text" name="email"/><br />
<textarea name="message"></textarea><br />
<input type="file" name="file"/><img id="captchaimg" src="http://xxx/mailsend.php?application=xxx&image=get"/><input type="text" name="captcha"/>
<input type="button" id="send" value="send"/>

我的JS文件:

function sendFromIframe() {
    if ($('#hiddeniframe').length == 0) {
        var iframe = ('<iframe name="hiddeniframe" id="hiddeniframe" src="" border="0" height="0" width="0" style="display:none"></iframe>');
        $("body").append(iframe);
    }
    setTimeout(function() {
        var form = $('#feedback');
        form.attr('target', 'hiddeniframe');
        form.attr('method', 'POST');
        form.attr('action', 'http://xxx/mailsend.php');
        form.attr("enctype", "multipart/form-data");
        form.attr("encoding", "multipart/form-data");
        form.submit();
        wait4refresh();
    }, 550);
}
function wait4refresh(counter){
    var counter = counter || 0;
    var bolean = false;
    var request = $.ajax({
        async: false,
        url: 'http://xxx/mailsend.php',
        type: 'GET',
        data: 'application=' + $('input[name="application"]').val() + '&issend'
    });
    request.done(function(msg){
        if (msg == 'true'){
            bolean = true;
        }
    });
    if (bolean){
        refreshCaptcha();
    }
    else if (counter > 10){
        return false;
    }
    else{
        setTimeout(function(){
            counter++
            wait4refresh(counter);
        },500);
    }
}
function refreshCaptcha() {
    var application = $('input[name="application"]').val();
    d = Math.round(Math.random() * 100);
    $('#captchaimg').attr('src', 'http://xxx/mailsend.php?application=' + application + '&image=get' + '&' + d);
}

和PHP文件:

當我嘗試在此處添加PHP代碼時,出現錯誤“對等連接重置”。 我能做什么?

您能否只創建<div id='htmlform'> </div>並通過jquery使它可見/不可見?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM