Submitting form in HTML - redirecting - html

I have a form in my webpage,
The form uploads a file to my server.
currently when the file upload form submits, after the server side finishes saving the image it tries to redirect my webpage to a different page :( (the name of the form action)
is there a way to execute the form without the redirect part? like an ajax call for uploading my image?
thanks.
here is the form:
<form method="POST" action="/project/upload"
enctype="multipart/form-data">
Please select a file to upload : <input type="file" name="file" />
<input type="submit" value="upload" />
</form>
EDIT - Let me try to rephrase it:
is it possible to submita form in such a way that it wont change my page or redirect?
and is it possible to create a call back when it finishes?

You can use target="iframeName" on your form to get it to post to an iframe on the page with no reloads occuring. Something a little like this:
<form method="POST" action="/project/upload"
enctype="multipart/form-data" target="myFrame">
..Form content..
</form>
<iframe name="myFrame" height=0 width=0></iframe>

Think best way is using a php page which calls itself with no redirect:
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
....
</form>
So you call the same page to do upload and don't need redirect. In other way you can add header in php page "/project/upload" with automatic redirect to put after upload code:
header("location: yourpage.html");

Related

Keep on same page after submit POST through form

I've a little problem. I submit a form to my route/uploadpdf with
<form action="http://localhost:3000/user/uploadpdf" enctype="multipart/form-data" method="post" onSubmit=window.location.replace('http://localhost:3000/statictoken')>
<input type="file" name="upload" multiple>
<input type="submit" value="Upload">
</form>
and when it is complete the browser tries to traverse to uploadpdf.
What I actually want is to stay on the current page ("statictoken") and refresh. You can see I've attempted to replace onSubmit, but it doesn't work.
The form action attribute is used to send the request to the specified page. If you want to send the request to the current page itself, you should have the following :
<form action="/" ...>
But keep in mind that now, you have to tackle the functionality of uploadpdf page on your 'statictoken' page.
You can also redirect to the "statictoken" page from the "uploadpdf" page after the file upload completes.
Or better, you can use Ajax File Upload, so that form is submitted asynchronously without redirecting you to the "uploadpdf" page.

A button who submits a form and redirect to another page

I'm currently working on a checkout page for a online store. I was wondering if there are any ways to make a button that submits a form and then redirects the customer to another page?
thanks in advance :)
Using PHP, you can redirect the user after handling the submitted data:
// After handling submitted data, redirect:
header("Location: new-page-here.php");
This is actually recommended, as it stops the user re-submitting the data if they refresh the page.
As per the instructions for header(), do not echo any HTML before it. This includes whitespace before your <?php tag.
You can try the following code.
<form name="form1" ACTION="url1.php" METHOD="POST">
<input type=".."\>
<input type=".."/>
<button onclick="submitForm()">Submit</button>
</form>
<form name="form2" ACTION="http://www.example.com"></form>
<script>
function submitForm()
{
document.forms["form1"].submit();
setTimeout('document.form2.submit()',500);
}
</script>
Hope this helps you.

Iframe source to be a dynamic URL

Not using iFrames very often so I could really do with your help here...
I have a form on a webpage which opens an external online booking engine with availability depending on the dates selected in the form.
I'd like to open the external booking page in an iframe named "mainframe" on a new page, book.html.
The start and end code for the form is:
Code:
<form name="roseform" method="post" action="http://www.hotelexec.co.uk/external.asp"></form>
<input type="text" class="dimmed" placeholder="Brasil" id="keywords" name="keywords" />
Search
How would I set the target to "mainframe" at the book.html page so the results from the form would be displayed there? I understand I need to make Iframe source to be a dynamic URL.
Thanks,
Blazer
Just add target attribute.
<form name="roseform" target="mainframe" method="post" action="http://www.hotelexec.co.uk/external.asp"></form>
UPDATE
As I understood you need this steps:
For start change .html to .php
Change action of form in itmjobs.ro/lidl/page1.php to point page2.html
<form name="roseform" method="post" action="http://itmjobs.ro/lidl/page2.php"></form>
In page2.php add iframe with address http://itmjobs.ro/search-results-jobs/
<iframe src="http://itmjobs.ro/search-results-jobs/?<?php echo http_build_query($_POST)?>"></iframe>
Now you will see data from http://itmjobs.ro/search-results-jobs/ in your iframe.

URL building for login

I am working on a Django project, in which a template login.html has code like -
<form name="input" action="welcome.html" method="get">
--------------SOME FORM ELEMENTS-----------------
<input type="submit" value="Login" />
</form>
When I click on Login, I want URL to be -
http://127.0.0.1:8000/welcome.html
or
http://127.0.0.1:8000/welcome.html?xxxxxxxxxxxxxxxxxx
but url comes out to be
http://127.0.0.1:8000/login.html/welcome.html?xxxxxxxxxxxxxxxxxx
(that is, "action" from form gets appended to the URL instead of getting appended to the domain) where "xxxxxxxx" stands for query submitted through form.
How can I achieve this?
<form name="input" action="/welcome.html" method="get">
You should set the action to be "/welcome.html".
thats really wired, try making your action="/welcome.html"

html, file uploading trouble

I have a trouble with file-uploding. Here is my part of the form:
<input type="file" name="image_file" />
<input type="submit" name="add_new" value="Upload" />
And in script i have a code:
print_r($_FILES);
After image choosing and sending form, I have an empty array $_FILES. Why?
The form must be set like this:
<form action="myuploadpage.php" method="post" enctype="multipart/form-data">
...
</form>
So that the browser knows to send the image along with the data.
Have you set the form method to POST data to the PHP script and set the action to point to it? If so then you should be able to get something like $_FILES['image_file']['name']