Multiple Images from separate input fields with php ajax - php

How to insert and update multiple images from multiple input fields in one form with PHP Ajax.
For example:
<form>
<input type="file" name="img1">
<input type="file" name="img2">
<input type="file" name="img3">
<input type="submit" value="Save">
</form>

Put your input name into an array.
<form>
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="submit" value="Save">
</form>

Related

Submitting an image alongside a form with one button

I have a regular form which submits to my database but I want to include a file upload in the form, so as to receive the form input in the expected table using PHP post and also receive the uploaded image.
Use <input type="file"> to include a file upload in the form.
Use something like this to send Files as well as other inputs to the processing page where you can access files and post variables.
<form action="#" method="post" enctype="multipart/form-data">
<input type="text" name="txtbox">
<br />
<input type="file" name="filebox">
<br />
<input type="submit" name="submit" value="submit">
</form>
When this is submitted you can access the data from $_FILES and $_POST
There are various input types in HTML just as the below:
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">
Each of the above inputs demand different conditions and formats to be satisfied.
For your query the answer is either:
<input type="file">
For webpages that require inputs in a file format. Or,
<input type="image">
For webpages requiring input in an image format.
For further details view the below link for help:
https://www.w3schools.com/html/html_form_input_types.asp

Put input value back to input filed

I have two submit buttons in one form and when I used the first submit, all the text input fields become blank. I try to solve this by using a session to store the textfield inputs.However, I don't know how I can put back the value to the input field that I stored in the session after the first submit is used.
The HTML code:
<form method="post" enctype="multipart/form-data">
<input type="text" name="headline" id="headline" required />
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload Images" name="submit_image">
<input type="submit" name="submit_post" value="Submit Your Post"/>
</form>
The php code:
<?php
session_start();
if (isset($_POST["submit_image"])) {
if (!empty($_POST['headline'])) {
$_SESSION["headline_session"] = $_POST ["headline"];
}
}
$headline_session = $_SESSION["headline_session"];
?>
Why you want to use a session!
you can echo the value of $post parameter in a property called (value) like this
<form method="post" enctype="multipart/form-data">
<input type="text" name="headline" id="headline" value="<?php echo $_POST ['headline']; ?>" required />
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload Images" name="submit_image">
<input type="submit" name="submit_post" value="Submit Your Post"/>
</form>
You can still save things to session if you need them later but I recommend just echoing out the previous value.
<form method="post" enctype="multipart/form-data">
<input type="text" name="headline" id="headline" value="<?php echo $_POST['headline']; ?>" required />
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload Images" name="submit_image">
<input type="submit" name="submit_post" value="Submit Your Post"/>
</form>
Should you need to compare the previous submissions with what was already submitted then this is one way to do it.
Good work thinking forward :) happy coding

Form action html to php

i have
<form action = "https://creator.zoho.com/api/xml/fileupload/scope=creatorapi&authtoken=**************" method="post" enctype="multipart/form-data">
<input type="text" name="applinkname" value="sample">
<input type="text" name="formname" value="Employee">
<input type="text" name="fieldname" value="File_upload">
<input type="text" name="recordId" value="1235667754455">
<input type="text" name="filename" value="profile.jpg" >
<input type="file" name="file">
<input type="submit" value="Update">
</form>
But i must send 2500 files, how can i transform this html to php, my problem is <input type="file" name="file">, how convert it to give a value in php ?
thanks you
You can use $_REQUEST['FILE']=$SOME VARIABLE;
And name is same what you use in your database
then apply enctype="multipart/form-data".

form action, send data from the current form in the URL

for the life of me cant remember how i should be doing this / if its possible.
I am creating a form that takes the user to another page but want to pass the value of the text box in the url.
so e.g:
<form action="newadvert.php?vrm=" class="newadvertform" method="post">
<input type="text" name="carvrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
How can i send the user to newadvert.php?vrm= THE ENTERED TEXT HERE
I need this to then get value on the next page.
Use GET method
<form action="newadvert.php" class="newadvertform" method="GET">
And rename carvrm to vrm
<input type="text" name="vrm" class="carvrm"/>
Use the GET method and rename carvrm to vrm.
<form action="newadvert.php" class="newadvertform" method="GET">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
When submitting the form, it'll go as http:///newadvert.php?vrm=
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
change your form method from post to get
Like this:
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="carvrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
you can get input value by :
$_REQUEST['carvrm']
or change input name to vrm :
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
now you can get input value by :
$_REQUEST['vrm']
doc: http://www.w3schools.com/PHP/php_forms.asp

How to Combine Post and Upload in HTML

<body>
<form method="post" action="xx.php" >
Enter Title of the Post<INPUT type="text" name="title">
<br/>
Enter Description
<textarea rows="10" cols="50" wrap="physical" name="post">
</textarea><br/>
<input type="Submit" value="Post">
<br/><br/>
<form enctype="multipart/form-data" action="xx.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name="uploaded_file" type="file" />
<input type="submit" value="Upload" />
</form>
How Do I get the user to write the text and browse the image, only after which pressing a single button would both upload the text and the file?
You can't submit two forms with the same button. You'll need to combine the two fields into a single form.
You can move the file input to the first <form> (which btw, you haven't closed) and use javascript to check if text has been entered and file has been selected.
Don't nest your form tags (It's invalid HTML). You can place all the inputs in one form so they are posted together.
e.g.
<form enctype="multipart/form-data" action="xx.php" method="post">
Enter Title of the Post<INPUT type="text" name="title">
<br/>
Enter Description
<textarea rows="10" cols="50" wrap="physical" name="post">
</textarea>
<br/>
<br/>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name="uploaded_file" type="file" />
<input type="submit" value="Upload" />
</form>
Oh, as a sidenote, you may not want to use a name like "post" in your input control.

Categories