i've got the following form
<form action="http://test.mysideurl.de/upload.php" method="post" enctype="multipart/form-data" target="upload_target" id="MyUploadForm" >
<input name="file[]" type="file" class="file" multiple>
This form should send multiple files (if selected) to upload.php which looks like follows:
foreach($_FILES['file']['tmp_name'] as $key => $tmp_name){
$file_name = $key.$_FILES['file']['name'][$key];
$tmp_name = $key.$_FILES['file']['tmp_name'][$key];
$doc_id=process_image($file_name,$tmp_name,$doc_id);
}
console of firefox says:
Warning: Invalid argument supplied for foreach() in ...myurl... on line 15
Has anyone an idea, why it doesn't receive the files array?
Best regards Daniel
Related
I want to use helper.repeat to create several input elements. But I want to declare the input tags as html instead of using #helper.input methods. But to do that I have to use a #index inside this loop. I am unable to instantiate and increase this variable. I tried something like the code below but I this output appear in html page:
BaseScalaTemplate(play.twirl.api.HtmlFormat$#5a8a0ced) = {0}
is output in html.
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
#index = {0}
#helper.repeat(questionForm("answer.alternatives"), min = 7) { (alternative) =>
<div class="checkbox">
<input type="checkbox" value="#alternative("correct") ">
<input type="text" id="answer_alternatives_(#index)_text" name="answer.alternatives[#index].text" value="">
</div>
}
</div>
</div>
Is there another maybe cleaner way to do what I want? Maybe with #for?
I use playframework 2.4.6 with Java8.
Playframework will let you do what you need, but you will have to do it in another way.
1) Your form definition will have a Seq[String] to save the results that come from the template.
2) Your form definition will need to include this change. In your case:
"answer_alternatives" -> seq(nonEmptyText)
3) Change the name and id from the template to #{alternative.name} so Playframework can link your input text to the sequence of String.
<input type="text" id="#{alternative.name}" name="#{alternative.name}" value="">
I can't figure out how to upload files to the remote server in Mojolicious Lite. Here's some code, first, html form:
<form method='post' action='add_photo'>
<input type="file" name="upload" enctype="multipart/form-data">
<button type="submit" class="btn btn-default">Submit</button>
</form>
and here's an add_photo testing route:
post '/add_photo' => sub {
my $self = shift;
my %params;
my $file = $self->param('upload');
$params{filename} = $file->filename;
$params{filesize} = $file->size;
$params{worknamne} = $self->param('name');
$params{stone} = $self->param('stone');
$params{cat} = $self->param('cat');
$self->stash(params => \%params);
$self->render('test');
};
And here's the error message I recive:
Can't locate object method "filename" via package "name_of_file.jpg" (perhaps you forgot to load "name_of_file.jpg"?) at sv line 31
Thanks in advance!
The encoding type goes in the form tag, not the file input:
<form method="post" action="add_photo" enctype="multipart/form-data">
For a detailed example, just look at: Mojolicious::Lite #File uploads
Also, this question/answer has similar information: How Upload file using Mojolicious?
I'm migrating from codeigniter to Fat-Free (F3) and trying to get my head around the quirks.
Regarding the following form:
<form ACTION = "<?php echo $_SERVER['PHP_SELF'];?>" METHOD="POST">
<input type="text" name="theirName" value="" required="required">
...
In standard PHP I get the POST value like this:
$name = $_POST['theirName'];
Or in codeignitor:
echo form_open('someclass/some_method_of_someclass');
$name = $this->input->post('name');
How do I get data from a form in a view in f3/fatfree?
You can get it from the Hive:
$name = $f3->get('POST.name');
I dunno if its a silly mistake but a post/get variable is not being set, while it is supposed to be. Here are the HTML and php code snippets:
<html>
<head>
<title>
Chain Story
</title>
</head>
<body>
<form method="GET" action="check-valid.php">
<textarea name="a" rows="5" cols="50"></textarea>
<input type="submit" value="Add" />
</form>
</body>
</html>
check-valid.php:
<?php
require 'includes/connect.inc.php';
$conn_ref = connect_db('chainstory') or die(mysqli_error());
if(isset($_GET)){
echo 'Get variable set';
if(isset ($_GET['a'])){
$as = $_GET['a'];
$query = "insert into story1 values (1, " . $as . ")";
mysql_query($query, $conn_ref);
}
else{
echo $_GET;
}}
?>
I get the following output:
Get variable set
Notice: Array to string conversion in /home/kevin/Code/php/myWebsite/check-valid.php on line 15
Array
I am coding this in netbeans. Can anyone point me out what mistake im making? :(
Did you try rename the textarea? Longer name , and give id to textarea same the name.
What browser does you use for testing?
I met some problems with input names in IE for example if an input name matches a javascript function name or protected names. Have you a javascript function or variable in your code what's name is a ? Because if the name of the input conflicts with a js var or name IE does not send the input field to the server. (Chrome Firefox and other browsers does)
i want to use zend_form to validate and filter the POST data,and some form fields are disabled element,
but when i use $form->isValid($post) filtering the data and use $form->getValues() to get the filtered data, it returns all the elements value (including the disabled elements value which i don't want).
such as :
<form method="post" action="">
<input type="text" disabled="disabled" name="account_id" value="123456">
<input type="text" name="name" value="">
<input type="text" name="email" value="">
<input type="text" disabled="disabled" name="created_date" value="2011-06-12">
<input type="text" disabled="disabled" name="created_by" value="admin">
<input type="submit">
</form>
so is there any way to get rid of the disables elements value ?
(because there are many fields and disabled elements ,so i don't want to trim them manually)
thanks!
This is some sort of a hack. We get all elements and iterate through it. When we see an element is disabled we can skip.
$somearray = array();
$elements = $form->getElements();
foreach ($elements as $key => $element) {
//echo $key;
if( $element->disabled ) {
continue;
}
$somearray[$key] = $element->getValue();
}
Hope this helps, or you can hack on it ;) .
It looks like this is not a bug, but an accepted workflow for validating forms. see this: http://framework.zend.com/issues/browse/ZF-6909
it looks like the accepted solution/trick is to use
$form->isValidPartial($this->getRequest()->getPost())
instead of
$form->isValid($this->getRequest()->getPost())
isValidPartial only tests the form fields that are present in the post. disabled elements should not end up posted.