Comments (7)
Hi,
Try this
$jaxon->register(Jaxon::USER_FUNCTION, 'myFunction', ['upload' => "'upload_example'"]);
That's how options are passed to functions when they are registrered.
from jaxon-core.
I had some progress now thanks to your advice, now I am saving the image but lost all other form data.
I get PHP Notice: Undefined index
because there is no form data.
I debugged the content and nothing is being received as agrs in the function.
$jaxon->setOption('upload.default.dir',$_SERVER['DOCUMENT_ROOT'].'/upl/temp');
$jaxon->register(Jaxon\Jaxon::USER_FUNCTION, 'myFunction', ['upload' => "'upload_example'"]);
I decided to go arroud this and created a simple ajax function that creates a formData var and adds the image to it, then it POSTs it to myUploaderController.php and waits for the response, if ok, then it calls
jaxon_myFunction(jaxon.getFormValues('myForm'));
Here is my workarroud:
html calling ajax function:
<button type="button" onclick="processImage();">Save all this data</button>
Jaxon controller:
$jaxon->register(Jaxon\Jaxon::USER_FUNCTION, 'prepareForm');
$jaxon->register(Jaxon\Jaxon::USER_FUNCTION, 'myFunction');
$jaxon->processRequest();
function prepareForm(){
$jxnr = new Jaxon\Response\Response();
// setup form html with smarty in my case
$jxnr->setFunction('processImage', '', "
var fileInput = document.getElementById('upload_example');
var file = fileInput.files[0];
var formData = new FormData();
formData.append('file', file);
//##DEBUG:
//for (var [key, value] of formData.entries()) {
// console.log('log: ' + key, value);
//}
//2097152 = 2MB
if(formData.get('file')['size'] > 2097152 ){
console.log('too big')
}else{
$.ajax({
url: 'util/myUploaderController.php',
type: 'POST',
data: formData,
contentType: false,
cache: false,
processData: false,
dataType: 'json'
}).done(function (response) {
if(response.hasError){
//ok, call jaxon
jaxon_myFunction(jaxon.getFormValues('myForm'));
}else{
//ERROR, popMsg
console.log('ERROR: '+response.msg)
}
//console.log('bo: '+response.bo);
//console.log('msg: '+response.msg);
});
}
return false;
");
return $jxnr;
}
function myFunction( $formData ){
$jxnr = new Jaxon\Response\Response();
$jxnr->setReturnValue($formData );
$jxnr->script(" console.log('debugging in browser console...') ");
//validate form data and do whatever I need to do with it
return $jxnr;
}
My uploader controller demo:
<?php
// deal with image here
$response = array(
'hasError' => true,
'msg' => 'demo msg',
'data' => null
);
echo json_encode($response);
?>
from jaxon-core.
Hi,
Does your browser support FormData?
When the browser does not support FormData, Jaxon will send 2 requests to your application. The first request uploads the files, and thus contains no data other than the files. The second request will then contain your form data.
Replace $jaxon->canProcessRequest();
with the following to handle this case
if($jaxon->canProcessRequest())
{
// Process the request.
$jaxon->processRequest();
}
else if($jaxon->hasUploadedFiles())
{
// Process upload.
$jaxon->saveUploadedFiles();
}
from jaxon-core.
Hello, thanks for your reply!
I tried
if($jaxon->canProcessRequest()){
// Process the request.
$jaxon->processRequest();
}else if($jaxon->hasUploadedFiles()){
// Process upload.
$jaxon->saveUploadedFiles();
}
and also
if($jaxon->canProcessRequest()){
// Process the request.
$jaxon->processRequest();
}else if($jaxon->hasUploadedFiles()){
// Process upload.
$jaxon->processRequest();
$jaxon->saveUploadedFiles();
}
I get the image in my configured directory, but still myFunction wont get the args.
from jaxon-core.
Run the request in debug mode and see what's the value returned by the jaxon.getFormValues('myForm')
call.
Also try to put the file input field in a separated form.
<form id="myForm" name="myForm">
<input id="someText" name="someText" type="text">
</form>
<form>
<input type="file" id="upload_example" name="example_file" />
</form>
from jaxon-core.
Hi,
I have made a change to properly decode parameters when they are "multipart/formdata" encoded.
Check out the 2.2.6 release.
There've also been some changes in the js library: Raw values of input fields of type file are no more included form data, and "multipart/formdata" encoding is used if the user actually selects files to upload.
They are in the 2.2.6 release.
from jaxon-core.
Wow thanks!
I'll check it out!
from jaxon-core.
Related Issues (20)
- replace funciton not working HOT 3
- getClass deprecated in Di\Container.php HOT 3
- Domain for Documentation seems down HOT 1
- Call to undefined function Jaxon\CodeIgniter\Filter\jaxon() HOT 2
- Jaxon-Upload Help
- CSP if SSL is in use...
- Examples links are returning an Error HOT 4
- Reinstate CallableObjects in version 4 possible? HOT 2
- PHP 8.2 warning: Deprecated: Creation of dynamic property Jaxon\Utils\Template\Context is deprecated HOT 2
- work with swoole framwork HOT 3
- Problems running most jaxon examples HOT 1
- Uncaught TypeError: Jaxon\Plugin\Request\CallableFunction\CallableFunction::configure(): Argument #2 ($sValue) must be of type string HOT 1
- Paramter as string '0' HOT 1
- Going from V2.x to V4.x HOT 6
- Stuck on 3.8.2; will not update to latest
- myJaxon extends Jaxon || myResponse extends Response HOT 10
- Register CALLABLE_CLASS problem HOT 6
- Jaxon with single class file per web page HOT 7
- Jaxon and the factory pattern HOT 21
- Directory Registration HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jaxon-core.