If i have simple form, and i want to use dropzonejs for uploat multiple files, can i upload them when i post the form?
if i post the form below and print $_FILES i don't get any data...
I looked at other topics here but i got no answer to my question
<?PHP
if ($_POST)
print_r($_FILES);
?>
HTML
<form method='post' action='index.php' enctype='multipart/form-data'>
<input type='text' name='title' value="" class="form-control" />
<textarea name="msgText" class="form-control" ></textarea>
<label class="control-label col-sm-1">Attached File:</label>
<div class="dropzone"></div>
<input type="submit" value="Submit" class="btn btn-success form-control">
</form>
Related
<form method="post" action="">
<input type="text" class="form-control" name="name" placeholder="some name">
<input type="text" class="form-control" name="code" placeholder="123456">
<input type="submit" class="btn btn-info" value="Submit" name="submit" />
</form>
<br>
<?php
//submit data
if (isset($_POST['submit'])) {
echo $_POST['name']."<br/>";
echo $_POST['code']."<br/>";
}
?>
that was my index.php and i want to post data into this form from another web page and get response by using php
Set the action-attribute to anotherwebpage.php and catch the values with the $_POST-Variables. So you basically move your PHP-block to anotherwebpage.php.
I'm trying to use dropzonejs in order to upload multiple files.
I want to upload them only when i submit the form (post the page)
how can i do that?
<?PHP
if ($_POST)
print_r($_FILES);
?>
here is my form:
<form method='post' action='index.php' enctype='multipart/form-data'>
<input type='text' name='title' value="" class="form-control" />
<textarea name="msgText" class="form-control" ></textarea>
<label class="control-label col-sm-1">Attached File:</label>
<div class="dropzone"></div>
<input type="submit" value="Submit" class="btn btn-success form-control">
</form>
Add name attribute to submit imput
<input type="submit" value="Submit" name="button" class="btn btn-success form-control">
Then in PHP:
if(isset($_POST['button'])){
...some code...
}
I am trying to implement file upload in Order Detail page.
Created form
<form action="" method="post" id="uploadForm" enctype="multipart/form-data">
<label for="fileUpload">{l s='File to upload:'}</label>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<input type="file" name="fileUpload" id="fileUpload" />
<div class="submit">
<input type="hidden" name="id_order" value="{$order->id|intval}" />
<input type="submit" class="unvisible" name="submitMessage" value="{l s='Send'}"/>
<button type="submit" name="submitMessage" class="button btn btn-default button-medium"><span>{l s='Send'}<i class="icon-chevron-right right"></i></span></button>
</div>
</form>
and added this to OrderDetailController.php
if (Tools::isSubmit('submitMessage')) {
$idOrder = (int)Tools::getValue('id_order');
$msgText = Tools::getValue('msgText');
if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name']))
{
$this->errors[] = Tools::displayError('Works');
}
...
Now when i submit form - it saves message and completely ignores file.
Does anyone know why?
Solved myself. Answered here
It was ajax issue not sending $_FILES[] data
I'm assuming you placed this into order-detail.tpl of default template.
You put your file input into a separate form that doesn't do anything since it does not have a submit button. The comments form on that page is a completely different one that's why your input is ignored.
What you want to do is place your html code without <form> tags into a proper form that submits message. The form is at the bottom of order-detail.tpl.
<form action="{$link->getPageLink('order-detail', true)|escape:'html':'UTF-8'}" method="post" class="std" id="sendOrderMessage">
<h3 class="page-heading bottom-indent">{l s='Add a message'}</h3>
<p>{l s='If you would like to add a comment about your order, please write it in the field below.'}</p>
<p class="form-group">
<label for="id_product">{l s='Product'}</label>
<select name="id_product" class="form-control">
<option value="0">{l s='-- Choose --'}</option>
{foreach from=$products item=product name=products}
<option value="{$product.product_id}">{$product.product_name}</option>
{/foreach}
</select>
</p>
<p class="form-group">
<textarea class="form-control" cols="67" rows="3" name="msgText"></textarea>
</p>
<!-- Your html snippet -->
<p class="form-group">
<label for="fileUpload">{l s='File to upload:'}</label>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<input type="file" name="fileUpload" id="fileUpload" />
</p>
<div class="submit">
<input type="hidden" name="id_order" value="{$order->id|intval}" />
<input type="submit" class="unvisible" name="submitMessage" value="{l s='Send'}"/>
<button type="submit" name="submitMessage" class="button btn btn-default button-medium"><span>{l s='Send'}<i class="icon-chevron-right right"></i></span></button>
</div>
</form>
I would like to know how do I edit in HTML5 validation message if there is error in form.
<form method="post" id="login" action="<?php echo $_SERVER['PHP_SELF']?>">
<div class="form_settings">
<label for="textfield">Meno:</label>
<input class="zaoblene" type="text" name="meno" value="Meno....." onclick="javascript: document.forms['login'].meno.value=''" required>
<br><br>
<label for="textfield">Heslo:</label>
<input class="zaoblene" type="password" name="heslo" value="heslo....." onclick="javascript: document.forms['login'].heslo.value=''" required>
<br><br>
<input class="prihlasit" type="submit" name="prihlasit" value="prihlásit" >
</div>
</form>
You can use javascript to do it!
Here you've the jquery plugin that does this work : http://bassistance.de/jquery-plugins/jquery-plugin-validation/
I am writing a page where a user can fill out form data, select two files for upload, and then hit Submit to pass the form data into the PHP page, and also the two files will be uploaded.
The problem is the submit button seems to be able to only be either a 'submit' or a 'File_Upload'. It can't do both... or can it?
Here is the gyst of HTML file (Just enough to get the point across... I hope)
<form class='form' name="frm_new_session" method="POST" enctype="multipart/form-data">
<div class='frm_row'>
<label>Title</label>
<input id="titleF" type='text' name="title" size='50' />
<input type="hidden" name="_chkuser" value="1"/>
</div>
<div class='frm_row'>
<label>Description</label>
<textarea id="descF" rows='3' cols='53' name="desc"></textarea>
</div>
<div class='frm_row'>
<label>Image</label>
<input id="imageF" type="file" name="uploadedimage">
<input type="hidden" name=MAX_FILE_SIZE" value='50000000'/>
</input> <br />
</div>
<div class='frm_row'>
<label>Session Media</label>
<input type='radio' id="mediaF" name="media" />
Upload: <input type='file' name="fileupload">
</input> <br />
<input type='radio' id="mediaF" name="media" />
Enter media URL:
<input type='text' size='75' name="mediaFile"/>
</input>
</div>
<div class='frm_row'>
<input type="submit" value="Save Session"/>
<div class='btn' type="submit" style='float: left;'>
<a href='#' id='btn_save_session'><span>Save Session</span></a>
<div class='kill_clear'></div>
</div>
</form>
I know I can do this using multiple forms, but I would like to avoid that and enjoy having just a single 'Save' button.
Any suggestions?
i don't understand the problem, the info will be in the $_POST array and the files in the $_FILES array.
however, you are missing a double quote in MAX_FILE_SIZE, i tested the following code, and it works :D
<?php
print_r($_POST);
print_r($_FILES);
?>
<form class='form' name="frm_new_session" method="POST" enctype="multipart/form-data">
<div class='frm_row'>
<label>Title</label>
<input id="titleF" type='text' name="title" size='50' />
<input type="hidden" name="_chkuser" value="1"/>
</div>
<div class='frm_row'>
<label>Description</label>
<textarea id="descF" rows='3' cols='53' name="desc"></textarea>
</div>
<div class='frm_row'>
<label>Image</label>
<input id="imageF" type="file" name="uploadedimage">
<input type="hidden" name="MAX_FILE_SIZE" value='50000000'/>
</input> <br />
</div>
<div class='frm_row'>
<label>Session Media</label>
<input type='radio' id="mediaF" name="media" />
Upload: <input type='file' name="fileupload">
</input> <br />
<input type='radio' id="mediaF" name="media" />
Enter media URL:
<input type='text' size='75' name="mediaFile"/>
</input>
</div>
<div class='frm_row'>
<input type="submit" value="Save Session"/>
<div class='btn' type="submit" style='float: left;'>
<a href='#' id='btn_save_session'><span>Save Session</span></a>
<div class='kill_clear'></div>
</div>
</form>
<form action="/add-news.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
<input type="text" name="title" />
<input type="file" name="image" />
<textarea rows="40" cols="50" name="content"></textarea>
</form>
Try adding hidden field MAX_FILE_SIZE where value is max size of files in bytes.
It works for me.
What you mean by: "It can't do both", what are the indications?