Is there a way to using a input file with two different form?
I need only one input file and have to post this file to .php page depending of user selection.
Thanks.
<label for="file">Photo:</label>
<input type="file" name="file" id="file">
<form action="c.php" method="post" enctype="multipart/form-data" >
<input type="submit" name="submit" value="C">
</form>
<form action="d.php" method="post" enctype="multipart/form-data">
<input type="submit" name="submit" value="D">
</form>
You could redirect to page cd.php which includes c.php or d.php depending on the value C or D
Related
Source Code :
<form role="form" action="uploadrit.php" method="post" enctype="multipart/form-data">
<label class="input" >Choose File Of CSV Format</label>
<input class="input" type="file" name="file" id="file" class="form-control" required="required">
<button class="input" type="submit" name="AddFile" class="btn btn-primary">Submit</button>
</form>
I want to select all file from directory using file upload control and send one by one file to uploadrit.php.
You should add multiple attribute to your file tag:
<form role="form" action="uploadrit.php" method="post" enctype="multipart/form-data">
<label class="input" >Choose File Of CSV Format</label>
<input class="input" type="file" name="file" multiple id="file" class="form-control" required="required">
<button class="input" type="submit" name="AddFile" class="btn btn-primary">Submit</button>
</form>
If you need to handle the files via Javascript, you can use File API. Example documentation: http://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
Instead sending the files one by one, use the multiple flag and send the files as an array. Here is an example:
<form action="file-upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload">
</form>
Pay attention to input where I've used the multiple flag as well as have declared the name of the input as an array. In your PHP file, loop through $_FILES['files'] to get all selected files.
I have a PHP script where I upload a *.txt file and I use the information inside that *.txt file to do some things.
The form for uploading this text file:
<form method="post" action="index.php" enctype="multipart/form-data">
<input class="file-choice" name="file" type="file" />
<input class="upload-button" type="submit" value="Upload Bestand" name="start" />
</form>
After I worked with this file I want to give the visitor a choice to change some things, with their own input.
The form for the user input:
<form method="post">
<div class="input-block">
<b>Rechts naar links:</b> <br>
<input type="radio" name="horizontaal" value="rl-aan">Aan
<input type="radio" name="horizontaal" value="rl-uit">Uit<br>
</div>
<div class="input-block">
<b>Verticaal:</b> <br>
<input type="radio" name="verticaal" value="ver-aan">Aan
<input type="radio" name="verticaal" value="ver-uit">Uit<br>
</div>
<div class="input-block">
<b>Diagonaal:</b> <br>
<input type="radio" name="diagonaal" value="dia-aan">Aan
<input type="radio" name="diagonaal" value="dia-uit">Uit<br>
</div>
<input type="submit" name="test" />
</form>
My problem is when I press the submit button of either the file upload or user input the other form is retested. So for example if I press the submit for the user input, the file that I uploaded before is gone.
I tried changing the method from POST to GET and I've tried to give both the submits the same name but both did not work.
Any suggestions?
I figured it out.
I had to work with sesions to save the needed variables from reading the file and add the name of the user input submit to all the scripts except the read script from the file.
Give different form id and submit button id .
<form id="form1" name="form1" align="center" action="http://www.test.org/add-listing/?listing_type_id=test" method="POST" enctype="multipart/form-data">
<input type="file" Value="UPLOAD RESUME" id="UploadResume" name="UploadResume" >
<br>
<input type="submit" Value="Upload Resume" id="SubmitResume" >
</form>
I am trying to post form data to another page; however, it seems like it is trying to go to
http://www.test.org/add-listing
instead of
http://www.test.org/add-listing/?listing_type_id=test
is there something i'm missing here?
You form method is POST so you can't pass data through GET (URL)
If you want to pass that value, you can use hidden inputs :
<input type="hidden" name="listing_type_id" value="test">
You will be able to get it on the other side with $_POST["listing_type_id"]
I have a iframe with a name, in this case an email address that changes from users.
I need to deal with this var:
<iframe name="asd#asd.lol" src="index.html">
index.html is a simple data form like this:
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>
I need to pass the value "asd#asd.lol" to the "upload.php" file.
Is this possible?
Is it possible for you to add a querystring parameter into the index.html file?
So:
<iframe name="asd#asd.lol" src="index.html?email=asd#asd.lol">
Then in the index.html file set a hidden variable:
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="hidden" name="email" id="email" value="">
<input type="submit" value="Upload">
</form>
If this is a plain HTML file you could set the value of the hidden field with some javascript.
Then use $_POST["email"] to get the email value out of the hidden field.
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST" onsubmit='$(this).append('<input type="hidden" name="iframeEmail" value="'+$("iframe[src='index.html']").attr('name')+'">')'>
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>
Try this out ,if it wont work ,than place the iFrame and ID and find it with the ID on jQuery Selector
I have this problem when I'm using PHP5/HTML on Apache-Tomcat6.
Here's an example for one of the forms I use in my site:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
Whenever I add the 'enctype' attribute to any form; neither the $_FILES['image'] is returned nor the $_POST variables. As long as the 'enctype' is not there, everything (except for the file input of course) works as expected. Can any one guide me please?
You won't be able to post data with a method of get on your form.
In test.html:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
In hello.php:
<?php
print_r($_POST);
print_r($_FILES);
Depending upon your server configuration, this will combine $_GET, $_POST, and $_COOKIE, but you'll still want to post with file inputs.
print_r($_REQUEST);