0

我正在尝试制作一个在提交时将值传递给外部 URL 并将结果显示为 iframe 的表单。表格是主页,结果也必须显示在第一页。

每次我提交它都会返回一个 404 错误。

这是代码:

<form id="buscaAereo" method="POST" name="formularioAereo" action="<?php echo home_url('/' ); ?>">
    <fieldset>
        <div class="half">
            <label class="radio">
                <input type="radio" name="idaevolta" id="idaevolta" value="1" checked>
                Ida e Volta
            </label>
        </div>

        <div class="half">
            <label class="radio">
                <input type="radio" name="idaevolta" id="idaevolta" value="2" checked>
                So ida
            </label>
        </div>

        <div class="half">
            <label for="name">Origem:</label>
            <input type="text" class="cidade" name="origem" data-provide="typeahead">
        </div>
        <div class="half">
            <label for="name">Destino:</label>
            <input type="text" id="cidade" name="destino" data-provide="typeahead">
        </div>

        <div class="half">
            <label for="name">Data de ida:</label>
            <div class="input-prepend">
                <span class="add-on"><i class="icon-calendar"></i></span>
                <input class="sapn1" id="date" name="ida" type="text">
            </div>
        </div>

        <div class="half">
            <label for="name">Data de volta:</label>
            <div class="input-prepend">
                <span class="add-on"><i class="icon-calendar"></i></span>
                <input class="" id="date" name="volta" type="text">
            </div>
        </div>

        <div class="quarter">
            <label for="country">Adultos:</label>
            <select id="country" name="adultos">
                <option value="0">00</option>
                <option value="1" selected="selected">01</option>
                <option value="2">02</option>
                <option value="3">03</option>
                <option value="4">04</option>
                <option value="5">05</option>
                <option value="6">06</option>
                <option value="7">07</option>
                <option value="8">08</option>
                <option value="9">09</option>
            </select>
        </div>
        <div class="quarter">
            <label for="country">Criancas:</label>
            <select id="country" name="criancas">
                <option value="1" selected="selected">00</option>
                <option value="1">01</option>
                <option value="2">02</option>
                <option value="3">03</option>
                <option value="4">04</option>
                <option value="5">05</option>
                <option value="6">06</option>
                <option value="7">07</option>
                <option value="8">08</option>
                <option value="9">09</option>
            </select>
        </div>

        <div class="quarter">
            <label for="country">Bebes:</label>
            <select id="country" name="bebes">
                <option value="1" selected="selected">00</option>
                <option value="1">01</option>
                <option value="2">02</option>
                <option value="3">03</option>
                <option value="4">04</option>
                <option value="5">05</option>
                <option value="6">06</option>
                <option value="7">07</option>
                <option value="8">08</option>
                <option value="9">09</option>
            </select>
        </div>

        <div class="quarter">
            <input type="submit" id="busca" name="submit" class="btn btn-primary botao" value="Pesquizar">
        </div>
    </fieldset>
</form>

和 PHP 代码:

function buscaPassagem() {
    if(isset($_POST['submit'])) {
        $idaevolta = $_POST["idaevolta"];
        $origem = $_POST["origem"];
        $destino = $_POST["destino"];
        $ida = $_POST["ida"];
        $volta = $_POST["volta"];
        $adultos = $_POST["adultos"];
        $criancas = $_POST["criancas"];
        $bebes = $_POST["bebes"];

        $link = "http://www.portaldoagente.com.br/OTAFrame/SuiteAerea/guiAereoAeroportos.aspx?PesquisaAutomatica=S&Tipo="; 

        $UrlFinal = $link
            .$idaevolta
            ."&Origem=".$origem
            ."&Destino=".$destino
            ."&Adultos=".$adultos
            ."&Criancas=".$criancas
            ."&Bebes=".$bebes
            ."&DataIda=".$ida
            ."&DataVolta=".$bebes
            ."&LojaChave=bG9qYXRlbXBvc3Jpbw==";

        echo "<script>window.open('$UrlFinal', 'meu_frame');</script>";
    }
}

有谁知道解决方案?

4

1 回答 1

0

您必须将表单操作定位到您的 iframe。此外,该操作必须指向您的 php 代码。(您问题的第二段代码)

 <form target='iFrame' id="buscaAereo" method="POST" name="formularioAereo" action="your_php_code">
   ....
 </form>

 <iframe id="iFrameID" name="iFrame"></iframe>

编辑:试试这个代码

查询:

function enviar()
{
   var link = "http://www.portaldoagente.com.br/OTAFrame/SuiteAerea/guiAereoAeroportos.aspx?PesquisaAutomatica=S&Tipo="; 

   var UrlFinal = link + $('input[name=idaevolta]:checked').val()
        +"&Origem="+$("#origem").val()
        +"&Destino="+$("#destino").val()
        +"&Criancas="+$('#criancas :selected').val()
        +"&DataIda="+$("#ida").val()
        +"&DataVolta="+$("#volta").val()
        +"&Bebes="+$('#bebes :selected').val()
        +"&Adultos="+$('#adultos :selected').val()
        +"&LojaChave=bG9qYXRlbXBvc3Jpbw==";
    $("#iFrameID").attr("src", UrlFinal);
}

HTML:

艾达和伏打

    <div class="half">
        <label class="radio">
            <input type="radio" name="idaevolta" value="2" checked>
            So ida
        </label>
    </div>

    <div class="half">
        <label for="name">Origem:</label>
        <input id="origem" type="text" class="cidade" name="origem" data-provide="typeahead">
    </div>
    <div class="half">
        <label for="name">Destino:</label>
        <input type="text" id="destino" name="destino" data-provide="typeahead">
    </div>

    <div class="half">
        <label for="name">Data de ida:</label>
        <div class="input-prepend">
            <span class="add-on"><i class="icon-calendar"></i></span>
            <input class="sapn1" id="ida" name="ida" type="text">
        </div>
    </div>

    <div class="half">
        <label for="name">Data de volta:</label>
        <div class="input-prepend">
            <span class="add-on"><i class="icon-calendar"></i></span>
            <input class="" id="volta" name="volta" type="text">
        </div>
    </div>

    <div class="quarter">
        <label for="adultos">Adultos:</label>
        <select id="adultos" name="adultos">
            <option value="0">00</option>
            <option value="1" selected="selected">01</option>
            <option value="2">02</option>
            <option value="3">03</option>
            <option value="4">04</option>
            <option value="5">05</option>
            <option value="6">06</option>
            <option value="7">07</option>
            <option value="8">08</option>
            <option value="9">09</option>
        </select>
    </div>
    <div class="quarter">
        <label for="criancas">Criancas:</label>
        <select id="criancas" name="criancas">
            <option value="1" selected="selected">00</option>
            <option value="1">01</option>
            <option value="2">02</option>
            <option value="3">03</option>
            <option value="4">04</option>
            <option value="5">05</option>
            <option value="6">06</option>
            <option value="7">07</option>
            <option value="8">08</option>
            <option value="9">09</option>
        </select>
    </div>

    <div class="quarter">
        <label for="bebes">Bebes:</label>
        <select id="bebes" name="bebes">
            <option value="1" selected="selected">00</option>
            <option value="1">01</option>
            <option value="2">02</option>
            <option value="3">03</option>
            <option value="4">04</option>
            <option value="5">05</option>
            <option value="6">06</option>
            <option value="7">07</option>
            <option value="8">08</option>
            <option value="9">09</option>
        </select>
    </div>

    <div class="quarter">
        <button onClick="javascript:enviar();">Pesquizar</button>
    </div>
</fieldset>
<iframe id="iFrameID" name="iFrame"></iframe>

希望这可以帮助。

于 2013-04-18T21:37:55.840 回答