Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Willan Correia
Willan Correia
410 Points

Submit custom form in wordpress that generates a iframe

I am trying to submit a form in wordpress that generates a custom iframe from a external domain, i get an error: Uncaught SecurityError: Blocked a frame with origin "http://portaldoagente.com.br" from accessing a frame with origin "http://localhost". Protocols, domains, and ports must match.

//the php code

<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $idaevolta = $_POST["Tipo"]; $origem = $_POST["Origem"]; $destino = $_POST["Destino"]; $ida = $_POST["DataIda"]; $volta = $_POST["DataVolta"]; $adultos = $_POST["Adultos"]; $criancas = $_POST["Criancas"]; $bebes = $_POST["Bebes"]; $LojaChave = $_POST["LojaChave"];

    $link = "http://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=" . $volta . "&LojaChave=". $LojaChave ;

} ?>

// the form

<form id="formularioAereo" method="POST" name="formularioAereo" target="dadosConsulta" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <fieldset> <div class="full"> <div class="radios"> <label > <input type="radio" id="Tipo" name="Tipo" value="2" checked> Ida e volta </label> <label > <input type="radio" id="Tipo" name="Tipo" value="1"> So ida </label> </div> </div><!-- radio --> <div class="quarter"> <label for="name">Origem:</label> <input type="text" id="Origem" class="cidade" name="Origem" data-provide="typeahead" autocomplete="off" > </div> <div class="quarter"> <label for="name">Destino:</label> <input type="text" id="Destino" class="cidade" name="Destino" data-provide="typeahead" autocomplete="off" > </div>

                <div class="quarter">
                    <label for="name">Data de ida:</label>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input class="date form-control" id="DataIda" name="DataIda" type="text" autocomplete="off" >
                    </div>

                </div>

                <div id="volta"class="quarter">
                    <label for="name">Data de volta:</label>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input class="date form-control" id="DataVolta" name="DataVolta" type="text" autocomplete="off" >
                    </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>

                <input type="hidden" id="LojaChave"  name="LojaChave" value="<?php the_field('chave_da_loja', 'option'); ?>">

                <div class="quarter">
                    <button type="submit" class="btn btn-primary btn-lg btn-block botao" value="">Pesquisar</button>
                </div>
              </fieldset>
            </form>

// the iframe

    <?php echo '<iframe id="dadosConsulta" name="dadosConsulta" width="100%" src="'. $UrlFinal .'"frameborder="0" scrolling="no"></iframe>'; ?>

2 Answers

Felix Yakubov
Felix Yakubov
17,475 Points

Do you use security plugin such as bulletproof security? I dont quite understand your code but most of my WP problems were caused by security plugin blockings

Felix Yakubov
Felix Yakubov
17,475 Points

Maybe Chrome is blocking your requests. http://www.w3.org/TR/2008/WD-access-control-20080912/

Try to disable chrome security or/and plugins. Its a pretty common problem with Chrome, I encountered this in WP support pages. Never had that problem myself though