Hello everyone and thanks in advance.
I have a problem and I have 2 form into one another, the domestic form is to perform a file upload.
As I can do to make when sending in internal form not run the main form.
<form name="x" method="post" action="xxx.php">
....
<form action="" method="post" enctype="multipart/form-data" target="xxx">
<input type="file" />
<input type="submit" />
</form>
<iframe id="xxx" src="process.php">
</iframe>
....
<input type="submit" name="pro" value="Register user"/ >
</form>
Doing this does not work, as this within another form.
Any help or possible solution.
Forms cannot be nested. That's simply is not allowed in HTML and if you do so you might get undefined behavior which could vary between browsers. So try removing the inner form and put the enctype on the outer form.
Related
I've a form for adding user to my database and it also uploads an image to my site, this all works fine. I am using http://nativedroid.godesign.ch/ as my site is for mobiles.
The problem is when I include this line on the php page with the form:
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
This causes $_FILES to be empty. Even if I simplify the form to this the $_FILES array is empty.
This is my simple form:
<form action="upload.php" method="post" enctype="multipart/form-data" >
<input type="file" name="myfile"><p>
<input type="submit" value="Add Staff"></p>
</form>
When I echo this in my upload.php
$name = $_FILES["myfile"]["name"];
I get an undefined error for "name", because the array is empty.
For some reason including the jquery is emptying the array, but I can't find a solution. I've been stuck on this for days now so any help is appreciated.
I think js conflict will be there so your code will not working there and you are getting empty array.
Change form code .. please check submit tag..
<form action="upload.php" method="post" enctype="multipart/form-data" >
<input type="file" name="myfile"><p>
<input type="submit" name="anyname" value="Add Staff"></p>
</form>
hope this help!
I need little help i am making an upload page, so i have two different forms and two different action
form is ajax picture upload (profile picture of user) its working fine action is action='ajaximage.php'
form is simple user info details like Name,Bio, etc etc. its also working fine.. and its action is action="add.php"
Doubt/Problem
In my website input boxes are not arranged orderly because of the design.
<form id="form" method="post" enctype="multipart/form-data" action='add.php'>
<b>Tittle</b>
<input type="text" name="name">
</form>
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'>
<input type="file" title="Choose Image" name="photoimg" id="photoimg">
</form>
<form id="form" method="post" enctype="multipart/form-data" action='add.php'>
<b>Description</b>
<textarea name="description" rows="1" cols="1"></textarea>
<button input="submit">Save Changes</button>
</form>
Ajax image uploader is working but in case of add.php it is working only for Description.
I cannot change the design so how can it be solved ?? Please Help
You need one submit button for each form. A submit button will just submit the form it is in.
#bwoebi is right about the submits but I'd be very surprised if your arrangement would work anyway. By my reckoning you have 3 forms. Just using the same name again wouldn't work. A single form needs to be distinct - unless you want to do a whole lot of javascript processing on submit. Have another look at fixing your layout to keep forms together.
Just saw your comments above. Why have separate forms with separate actions anyway? Why not have one form with one action that simply does both the file upload and adds the details (presumably to a database)?
You could also simply have different submit buttons on your form and add an onclick attribute to each setting the action for the form to be different:
<input type="submit" name="sub1" value="Upload Image" onclick="document.myform.action='ajaximage.php';">
<input type="submit" name="sub2" value="Add User" onclick="document.myform.action='add.php';">
This means the form action will be changed depending on which submit button is used .
To upload images via ajax you do not need to submt a form, that is the whole point of doing it via ajax. You can upload the image, and then submit the form for the text inputs.
pseudocode:
<form id="form" method="post" enctype="multipart/form-data" action='add.php'>
<input name="name"/>
<input name="profilePic" id="profilePic"/>
<input name="descrption"/>
</form>
You can then use javascript(I prefer jQuery) to upload your image via ajax, specifying #profilePic.
Also, you should look at: http://blueimp.github.io/jQuery-File-Upload/
I have a form such that a list of questions with inputs is followed by an invitation to upload files if they have them.
I have avoided nesting forms by popping up the form containing the upload. The difficulty is that if they press submit on the Uploader form, it will process the upload on the destination page, and likewise if they hit submit on the rest of the form, the uploads are not submitted.
How can I do both at once?
My code:
<form id="questions" action="page2.php" method="POST">
Question 1 <input name="q1"/>
Question 2 <input name="q2" />
Have any files to add? <button id="upload-button">Upload</button>
<input type="submit" value="Submit Answers" />
</form>
<div class="hidden">
<form id="fileupload" enctype="multipart/form-data" action="uploader.php" method="POST">
<input id="fileupload" type="file" name="files[]" multiple>
<input type="submit" value="Upload Files" />
</form>
</div>
jQuery will pop up the hidden div if someone presses the button to add files.
I don't have a problem with them being posted to the same place, but I tried using javascript to use the click event for each button to submit both forms and it did not work.
(Reading stack overflow later explained that only the last submission gets processed in this way)
Any ideas? Thanks
Very simply, structure your HTML like this, and process the logic from both page2.php and uploader.php in one shot (i.e. include the file-upload logic in page2.php). If you show us the contents of both of those files, I can show you how to combine them.
Also added labels with links to the associated inputs, and swapped the submit input for a button element.
<form id="questions" enctype="multipart/form-data" action="page2.php" method="POST">
<label for="q1">Question 1</label>
<input id="q1" name="q1" type="text" />
<label for="q2">Question 2</label>
<input id="q2" name="q2" type="text" />
<label for="fileupload">Upload a File<label>
<input id="fileupload" type="file" name="files[]" multiple />
<button type="submit">Submit</button>
</div>
I want to post an entire IMAGE when SUBMIT button is clicked.
<FORM action=".." method=post>
<img src="...."/>
<input type="submit" value="Click"/>
</FORM>
Is it possible?
Please help me......
Thanks in advance.....
Are you looking to upload an image? If so, then you'll want the "file" HTML input element type:
<input type="file"/>
And include enctype="multipart/form-data" in your form tag.
Here's a basic tutorial and more info:
http://www.tizag.com/phpT/fileupload.php
if you want to post an image inside a form, you should have that image already on your server. In which case all you have to do is put a hidden element on the form with the location of that image and voila you have the image in the form
<input type="hidden" name="image_location" id="image_location" value="/images/bleh.jpg" />
You can do it like this:
<FORM action=".." method="POST" enctype="multipart/form-data">
<input type="file" id="file" placeholder="upload a file"
name="file">
<button type="submit">Submit</button>
</FORM>
I have a form and a div. I want the user to select an text file and hit submit and that will populate the div with the content of the file. I would like to do that without having to refresh the page.
<form action="action.php" method="post" enctype="multipart/form-data">
Click the "Choose File" button and browse for the file to import.<br /><br />
<input type="file" name="filelocation" value="Browse" /><br />
<input type="submit" name="submitform" value="Submit" />
</form>
<div id="filecontent">
</div>
There is no easy way to submit/upload the files via ajax. However, you can go for the jQuery Uploadify plugin to the trick for you.
Uploadify is a jQuery plugin that
integrates a fully-customizable
multiple file upload utility on your
website. It uses a mixture of
Javascript, ActionScript, and any
server-side language to dynamically
create an instance over any DOM
element on a page.
Theres is no easy way to do that, but u can use an Iframe with an ajax call to get your file to the server and work with it the normal ajax way
<form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >
File: <input name="myfile" type="file" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
look at target="yourhiddeniframe"
here is a complete howto:
http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html
greetings