Open iframe link after post PHP + JS

Asked

Viewed 600 times

0

I asked another question here on the forum about another subject that helped me a lot about this but the link opens in new page.

What I would like to do is to click on the Ubmit to open inside an iframe inside the page and if the field was not filled in receive a message (popup) stating that the field was not filled in..

<?php
if (isset($_REQUEST['txt_url'])) {
$link = 'http://' . $_REQUEST['txt_url'] . '.datatix.com.br';
header('Location: ' . $link);
} 
?>

<div class="instancia">
<div class="content">
<img src="img/logo_datatix.jpg" height="32px">
<form action="" method="post">
<input type="text" name="txt_url" value="" placeholder="Digite sua Instância">
<input type="submit" value="Ok" name="ok "class="ok">
</form>
</div>
</div>

<div class="iframe">
<iframe id="conteudo_iframe"></iframe>
</div>

If possible not to use php would be much better.

It would be more or less what is in the code below, but the user does not put the whole domain only the subdomain.

Example: It puts "test" and "OK" but in iframe it would load the link test.dominio.com.br

body{ padding:0; margin:0;}
.instancia{ background-color:#D3172F; color:#FFF; font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif; width:100%; position:fixed; border-bottom:#9B1022 2px solid !important;}
.instancia .content{ width:320px; margin:0 auto; display:table;}
.instancia img{ float: left;}
.instancia input{ height:30px; padding-left:5px; padding-right:5px; width:176px; border:0; float: left;}
.instancia .ok{ border:0; background-color:#9B1022; height:32px; width:32px; color:#FFF; float:left; font-weight:bold; cursor:pointer;}
<div class="instancia">
<div class="content">
<img src="img/logo.jpg" height="32px">
<form action="" method="post">
<input type="text" name="txt_url" value="" placeholder="Digite sua Instância">
<input type="submit" value="Ok" name="ok "class="ok">
</form>
</div>


</div>

<div class="iframe">
<iframe name="exemplo" width="100%"></iframe>
</div>

2 answers

1


Use the attribute target of link or of form, with a value equal to that of the attribute name of <iframe>

<a href="/" target="exemplo">pt.stackoverflow.com</a>
<form action="/" target="exemplo">
  <input type="submit"/>
</form>
<iframe name="exemplo"></iframe>

Remark: the <iframe> will not finish loading due to OS restrictions, but saving the content in an HTML file will work.

  • But how do I play the php post on this link? .

  • @Rodrigob.Silva modified the answer, the process for form and link is the same

  • <?php if (isset($_REQUEST['txt_url'])) { $link = 'http://' . $_REQUEST['txt_url'] . '.datatix.com.br'; header('<script type="text/javascript"> window.location.href =" . $link . '.datatix.com.br" ; </script>'); } ? > If I do so it does not load

  • edited the question.

0

Use the tag targert to identify that you want to open inside the iframe, if you want to do some other validation create a function in the onsubmit

  • But how do I play the php post on this link? .

  • You want to put the url obtained through php as the form action ?

  • That’s right, or it could be like a include.

  • <?php if (isset($_REQUEST['txt_url'])) { $link = 'http://' . $_REQUEST['txt_url'] . '.dominio.com.br'; include ($link); } ?>

  • Do you have the domain? You could save the domain to a javascript variable and ask the user to type the domain name. The click of the button would trigger a javascript event that would do all the validation. <form onsubmit="funcao()> within the function you would do all your validation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.