I am making a form with over 35 input fields and files that need to be uploaded with the form that can be relevant to that form's reviewing later.
In order to upload multiple files I wrote this script inside the form:
<script type="text/javascript">
function cancelFile(v){
$(v).closest('.input_file').remove();
}
function addFile(){
$('#files').append('<div class="input_file"><input name="attachment\[\]" type="file" ><img class="cancel_img" src="images/delete.png" onclick="cancelFile(this)"></div> ');
}
</script>
<input type="button" onclick="addFile()" value="Add file"><br><br>
<div id="files">
</div>
It basically appends an input of type file with the name attachment[] when an add file button is clicked, and a span that allows to cancel (remove) that input when clicked.
When I add only one file, all the POST data uploads fine: text, dates, files and all. But when I add multiple files, the POST request is empty: var_dump($_POST) shows me an empty array.
The form has enctype="multipart/form-data" declared.I also tried the uploading of multiple files in a separate test and it worked fine.
Anyone knows why my post ends up empty?
Related
I have a form that gets data from a database and displays the results as buttons with the appropriate names. When i add javascript onclick i can diaplay the data_id. This all works but i want to be able to save the data to the main page in a textfield but it doesnt show anything? What code do you need to see or is it because i am loading an external php file to load the data that it isnt posting it past. Its doing my head in, I will post what code you want, i already have but had no joy.
For instance if i have a textfield called 'testField1' in my main page and on the same page i am getting a list of data from forms and mysql and the end is kicking out
<input id="button1" type="button" value="<?php echo $product_name; ?>" onclick="display()">
I want it to diplay that data in the main page 'testfield1' using the script
<script>
function display()
{
document.getElementById("textField1").value = "$product_name";
}
</script>
the code online is www.cheekytransport.co.uk/show.php
I am trying to use dropzone.js (with Coldfusion 9) to upload potentially multiple files on one page. I first did this using the form tag:
<cfform name='UploadFiles' action="uploadfiles.cfm" class="dropzone">
and this worked as expected.
The problem is that I need the user to upload the files and then hit a submit button that processes the files. So I would need the information from each of the files uploaded. With this method, since each one is a separate form, I could not get all the file names on submit. Because of this, I changed the tag to a div tag inside of the form:
<cfform name='uploadfiles' action="uploadfiles.cfm">
.
.
.
<div id="my-dropzone" action="uploadfiles.cfm" class="dropzone">
</cfform>
<script>
new Dropzone(
url: "/uploadfiles.cfm" // Set the url
});
</script>
This works, as it shows the different dropzones and I can drag and drop a file or select one, but nothing ever gets uploaded to the location.
I am using the same code I used when the dropzone was a from to upload when the dropzone is a div:
<cffile action="upload" destination="#uploads#\Uploaded\#filen#" nameconflict="makeunique">
What am I missing in order for it to actually upload the file?
I have an input file :
<input onchange="da_show_files();" id="file_send_chat" type="file" class="upload" name="file_send_chat[]" multiple="multiple" />
And my main problem is that I'd like to access (in order to remove) specific files in the input, but I'm only getting the last modified (added) file when using :
$('#file_send_chat').prop("files") or
$('#file_send_chat').files or
$('#file_send_chat').val()
The whole point is to be able to remove one file from the input itself, so that I can add it again (for a better user experience).
How can I do that ?
Thanks.
PS : da_show_files(); only show the filenames when uploading files.
I have a form that have 1 dropdown, 1 text box and 1 submit button.
I want to be able to run various .php files based on the dropdown item that is selected. I was
hoping to use the return value of the dropdown but I have no idea how to do that.
The value in the text box is used by all the .php files that I have in the same directory as the html code.
Thanks
If I understood correctly, you are trying to run a certain php file based on the drop down selection. You can simply include the php file you want to "run".
Let's say you have 2 "runnable" php files: a.php and b.php
a.php
// a.php
echo 'a says '.$_POST['text'];
b.php
// b.php
echo 'b says '.$_POST['text'];
selector.php (where the form POST data goes)
<?php
// select.php
include $_POST['selection'];
?>
and the HTML:
<form method="POST" action="selector.php">
some text: <input type="text" name="text" /><br/>
select function:
<select name="selection"><option value="a.php">A</option><option value="b.php">B</option></select>
</form>
This is just an example, make sure to restrict the files you can include somehow for security reason.
Assuming i understand correctly, one way would be to do something like:
include 'fileWithFunctions.php';
$selection = $_POST['drop-down-selection'];
if($selection == "option1")
firstFunction();
else if($selection == "option2")
secondFunction();
//and so on
Should work, I'm a little out of touch with PHP.
Update: If you're getting error messages before you click the submit button, then you have to put this inside an if statement checking if the button has been pressed.
I try to replace classic input file with JqueryFileUpload widget.
Here is my context :
I can have one or more file input in the same form.
The form is meant to create server side objects (each input is a field of this object and each file is a "resource" object linked to the main created object). Those object are stored in a database.
When the final user submit the form, I'd like to :
do many validation (for other inputs)
if all is ok, then trigger the ajax upload of file(s). A server-side handler create the
needed ressource object(s).
when all the uploads are completed (I can know that by using the widget callbacks), then I submit the main form (the action form is not the widget handler but a page that do the job and display a message) to create the main object : I don't want to send the file(s) here but only the ressource objects id that the handler send me back to link them to the main object).
My problem is, when I trigger the fileUpload the form is submitted and the action form page is loaded. The handler isn't called.
I made test with a simple page : if the widget is not within a form it works fine :
<body>
<div>
<!-- The file input field used as target for the file upload widget -->
<input class="fileupload" type="file" name="files[]"/>
</div>
</body>
but if I put it in a form the form is always submitted and I can't prevent this.
<body>
<form action="myPage.aspx">
<!-- The file input field used as target for the file upload widget -->
<input class="fileupload" type="file" name="files[]"/>
</form>
</body>
My questions are :
Doesn't the url option override the form action ?
Can I not use different target for the widget and the form that contains it ?
Can I put multiple widgets in a single form ?
Okay just for information it was a pretty stupid mistake from my side, I used a which default behavior is 'submit' so my form was always submitted.