This was working but stopped afterwards.
Other fields have no issue submitting.
When I press submit the other fields are added to the database but this one is not.
To prevent confusion the value that matters is photo_url not photo_dir.
Further clarification: photo_dir is the value of a drop down menu with a compass direction. All I want is to store the file name in the DB under column photo_url.
This is the form field
<label for="photo_url">Upload:</label>
<input type="file" name="photo_url">
This is the SQL
$sql="INSERT INTO photo(photo_project_id,photo_section,photo_subsection,photo_date,photo_post,photo_desc,photo_url,photo_dir)VALUES('$_POST[photo_project_id]','$_POST[photo_section]','$_POST[photo_subsection]','$_POST[photo_date]',now(),'$_POST[photo_desc]','$_POST[photo_url]','$_POST[photo_dir]')";
The file is also being uploaded to the server which is working without issue. Though I would like to be able to rename them to datetime() but that is a topic for a different day.
You can access to file element with $_FILE like this
$_FILES['photo_dir']
in the first step print_r this because it has another child
First of all your should have this attribute enctype="multipart/form-data" for using input type file, Should look like this :
<form action="" enctype="multipart/form-data">
After form submit, check :
if(isset($_FILES['photo_url'])){
$file_name = $_FILES['photo_url']['name'];
}
Rewrite query then :
$sql="INSERT INTO photo(photo_project_id,photo_section,photo_subsection,photo_date,photo_post,photo_desc,photo_url,photo_dir)VALUES('$_POST[photo_project_id]','$_POST[photo_section]','$_POST[photo_subsection]','$_POST[photo_date]',now(),'$_POST[photo_desc]','$_POST[photo_url]','$file_name')";
Related
We currently have a site that provides webforms. (podio.com)
These webforms are limited, as it does not provide conditional formatting.
(ex. Selecting option A, unhides field 1,2,4 to fill out or
Selecting option B, unhides field 1,4,6 to fill out.)
My solution: I created a php webform, with the same fields, and im able to control conditionals this way. I then just POST the variables to the other site/webform and it submits the form.
Works Great!
Now the issue is attachments.
So my question is: How would i go about pushing an attachment from my new form to the other form so it actual is submitted?
My current code for the attachment:
<input type="file" name="attachments[]" value="" accept="" data-reactid=".0.1.1.0:$0.0">
This obviously lets them chose a file, but how would i go about carrying this attachment to the actual webforms 'choose file upload' field, so it submits with the other data?
Please let me know if i need to explain more.
change this line
<form class="contact100-form validate-form" action="/infotech/webforms/tickets/results.php"
method="post" name="it_webform">
to this
<form class="contact100-form validate-form" action="/infotech/webforms/tickets/results.php"
method="post" name="it_webform" enctype="multipart/form-data">
as Clint pointed out, this needs to be there. This is infact required on ANY form that is expected to send files, without this enctype attribute, the form is just basic text for all the server cares and the files array is not sent.
Maybe like this : you can't use a local image in your second form, because the file is not stored on the user computer. but when you receive the first form : encode the image in base64 and use it in second generated form
1) use <img src = "data:image/png;base64, xxxxxx" . to display image
2) use a hidden field with value="xxxxxx..." to send to 2nd script
note : the picture cannot be changed.
you can add a option (input check box) "choose another file" to allow picking another local file, then the script check if it should handle the first picture
(base 64 encoded) or the new picture, according the "choose another file" check box value
I have build a form in which you can add images. Unfortunatelly, I am not able to call "move_uploaded_file" in PHP, as the server is running PHP safe mode and there is no way to modify this (I have checked). Therefore, I submit my form to my OWN server, which handles the file uploading.
On my own server, the file however; is not found. I think it has to do with the form calling the external url.
I know this because
echo $_FILES['uploadFile']['name'] ."<br>";
returns just an empty line.
The form itself is:
<form action="http://ejw.patrickh.nl/load.php" method="get" enctype="multipart/form-data" onsubmit ="return checkInput();"> </form>
and contains several input buttons.
Bottomline: the form on my own server submits the file perfectly, however when I make use of the form which is on another site, with the above action; no file is found.
Can this be fixed, and if so; how?
Thanks in advance!
You have to use method="post" to submit files.
Also the enctype attribute alone can be used only, if method="post".
In my create page, i am using one or more file upload text box , select box ,text box inside a form , After filling all form datas and submit, I will do a server validation then insert into db...
Before insert into db, if server validation fails, filled datas are lossed , Is there any easy way to prevent data loss?
for select and text box we can pass the value of $_POST
But for file upload text box , how to prevent data loss? Can we store in session?
Thanks in advance..
well you can use some variables to store the data, then you can perform the validation
well i am giving a example of php validation
<?php
if(isset($_POST['submit'])){
$name = $_POST['name']; //
// and some other data input
and goes the validation part
?>
<form ... >
<input type="text" name="name" value="<?php if(isset($name)) echo $name; ?>"
</form>
well.. this must work..
you might find other better ways.. but this will also work
As per my knowledge you can not maintain the file upload values as like the other form elements.
If you still want to maintain the $_FILES values. You can take them in session.
$_SESSION['imagename'] = $_FILES['image']['name'];
$_SESSION['imagetmp'] = $_FILES['image']['tmp_name'];
You can save the data in variables and populate it later, except for the type="file" input field. It will be a security problem if the files can be prepopulated(or say selected without user permission) and browsers won't allow it.
One option is to save the file in any temporary folder in server and if validations worked fine, move it to the uploads directory.
Another option is to show your form in steps(in pages) and the file upload option in the last step, so that the user will reach the file upload section after all validations and you can do the file upload validation in the last step.
I need help with my form. There's a mix of input, textarea and file upload that i want to enter into the database..
What do I use in the ? Do I use the normal form attribute :
<form action="" method="">
or
<form enctype="" action="" method="">
Please have it in mind that, I have to do this in a single page, and the picture upload must be done along with other text input.
Thanks for your time.
You must use enctype="multipart/form-data" for file uploading, this will also work fine for non-file upload forms.
You need to set enctype="multipart/form-data" and use method="post" for any form that includes a file input. This won't stop you from including other types of fields.
(The way those fields will be submitted to the server will change, but your form parsing library will deal with the differences automatically, you only need to worry about them if you are parsing the raw input yourself).
<form enctype="multipart/form-data" method="post" action="submit.php">
submit.php being, in this case, the external PHP script that will process your form ( if you decide to use PHP ). But you can name the .php script whatever you like ( e.g. cats.php ).
The uploaded file/image data will be stored inside $_FILES, and all the textfield, textarea, radio buttons, check boxes and other data will reside inside the $_POST superglobal.
When submit.php receives the submitted form you can do all kinds of processing on it such as validating that user has submitted the correct type of file/image, store the file path of the file/image in your local database( client/server or file system based ), and much more.
Make sure to validate user input client side and server side too.
<form enctype="multipart/form-data" action="yourpage.php" method="post">
You'll need the enctype attribute if you want the file upload to work. FYI, a form can contain every field type, including file uploads, and work just fine.
In Classic ASP I had to access my textfield as load.getFileData("textfield")
instead of the standard Request("textfield") when using the enctype="multipart/form-data"
$('#images_upload_add').click(function(){
$('.images_upload:last').after($('.images_upload:last').clone().find('input[type=file]').val('').end());
});
using this code to append file input's does not upload the file in firefox.
also
$('#image_server_add input[type=button]').click(function(){
var select = $(this).siblings('select').find(':selected');
if(select.val()){
$('#image_server_add').before('<tr class="images_selection"><td><input type="button" value="Delete"></td><td class="main">'+select.html()+'<input type="hidden" value="'+select.html()+'" name="images_server[]"/></td></tr>');
}
})
also does not upload the values to the $_POST
I can't find anything to say why this wouldn't work in the documentation, this works in IE but not it Firefox/WebKit
Why wouldn't these examples correctly upload the form values?
Bottom line the markup on the page was mangled.
The form was in a table based layout, not by my choice, and the form declaration was inside a tr.
I moved the form declaration to a parent td of the form inputs and now it works.
This is an interesting result considering the rendering engine will correctly submit inputs that are improperly placed, but attempting to add those inputs using jQuery/javascript? into the same place will not work in Firefox/WebKit.
I imagine this has to do with the dom manipulation that javascript does and how it may be more strict about the block level element requirements.
Any more notes/conjectures about my findings would be appreciated.
Are you having the same problem if you create a new input rather than cloning an existing one?
Are you changing the name of the cloned input to avoid name collisions or are you using an array style name (e.g. file[])?
What is the purpose of adding the markup of the selected option to a hidden input?
For fun, have you tried using .clone(true)?
Wow! Sometimes jQuery can actually be too dense to read. Would also help if we could see your markup.
Stab in the dark here because I'm guessing at what you're trying to do.
You can't programmatically enter a filename into a file field and it be uploaded to the server. That would be dangerous.
Perhaps I'm barking up the wrong tree?
Maybe rather than adding the element just as the form is submitted, put the element in, but with default values.
Then when the button is clicked, populate that element with the right value.
I just say that because by the time you click on the submit, it might be too late for the added element to be submitted along with the form.
I got to this section from google searching a similar problem.
To me, I was able to fix it by taking a step back at the problem -
in a example form:
<table>
<form method="post">
<tr>some content <input type="text" name="test"> </tr>
</form>
</table>
This will work in Internet explorer for some reason, but it is actually invalid html.
Move the form tags to outside the table, like so:
<form method="post">
<table>
<tr>some content <input type="text" name="test"> </tr>
</table>
</form>
And it will then work.
The input's will work fine (even dynamicly) this way, I was having a lot of trouble where a form would work, until you inserted more inputs or form elements - only the original elements would submit, which was very hard to track.