05.24
Today, I wanna share with you a way to submit forms using a ajax look & feel altought it’s not really ajax.
The question you might ask is :
why should I use this method instead of real ajax ?
Well they’re is numereous answer to that but one good reason it that is doesnt require any type of ajax libs and you can start using it even if you never used ajax before.
So here it goes.
<form method=”post” action=”formProcess.php” target=”hiddenIFrame”>
<input type=”text” name=”test” />
</form>
<iframe style=”width:0px;height:0px;border:0px;” name=hiddenIFrame />
This is just a normal form but you’ll notice the target in the form tag, this tells the form to submit in the iframe instead of the current page.
It’s works exactly as the target attribut on the A tag.
Also the iframe is hidden from the user using style=”width:0px;height:0px;border:0px;”
now the file formProcess.php is not different from your normal form processing file but if you want do something on the main page you have to use JS like that :
window.parent.whatEverYouWannaDoInParentForm();
You can also upload file with this method !
Please checkout the formphp for full example.
Cheers !
Nb : You will see the status bar acts like the page is reloading but it’s really not.
No Comment.
Add Your Comment