Is there any way to submit the form to an Iframe (without Javascript)?

Asked

Viewed 650 times

2

Is there any way to make a form submission where the action, instead of updating the page, be submitted to a iframe?

I’ve seen it somewhere, but I didn’t know how the magic was done. It was done without Javascript.

Something like:

<form action="/my_page" method="POST">
    <input type="text" name="name" />
    <input type="submit" value="Submit" />
</form>
<!-- o resultado deve ser exibido aqui, ao invés de atualizar a página -->
<iframe></iframe>

How can I do that?

1 answer

1


Yes, there is a way to submit a form to a iframe, no need for Javascript.

A lot of people don’t know, but it’s possible.

First you need to define the attribute target in his form. That one target should point to the iframe desired. Therefore, you need to define a name to the iframe where you want the submission to be processed. Next form you define the attribute target with the value of name attributed to the iframe.

Behold:

<form action="/my_page" method="POST" target="target_iframe">
    <input type="text" name="name" />
    <input type="submit" value="Submit" />
</form>
<!-- o resultado deve ser exibido aqui, ao invés de atualizar a página -->
<iframe name="target_iframe"></iframe>

In the above case, the result of the submission that will be processed in the url /my_page would be displayed inside the iframe without updating (refresh) the page.

Browser other questions tagged

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