Frank Schneider Posted December 6, 2022 Share Posted December 6, 2022 I have a Processwire application. In it I have two areas company and their employees. I insert an image in Employees and upload it, it works fine so far, now I do the same in the company and want to use it as a logo, it doesn't work there. When I click save, the $_files field is empty, but not for the employee. So exactly the same as with the employee does not work, same fields, same code. The field is defined in fields as Image and assigned to the template I've searched the whole internet but can't find the reason. my code: $form_fields = array( ..... 'foto' => array('type' => 'file', 'required' => true), ); // --- WireUpload settings --- $upload_path = $config->paths->assets . "files/.tmp_uploads/"; // tmp upload folder $file_extensions = array('jpg', 'jpeg', 'gif', 'png'); $max_files = 1; $max_upload_size = 1*1024*1024; // make sure PHP's upload and post max size is also set to a reasonable size $overwrite = false; $update_page = ($page->url == $pages->get("/firmenverwaltung/edit/")->url) ? $pages->get("id=".(int)$input->urlSegment0) : null; $file_field = "foto"; //HTML <div class="col-lg-6"> <div class="form-group"> <label class="form-control-label">Logo: <?php if ($form_fields['foto']['required']) { ?><span class="tx-danger">*</span><?php } ?></label> <div class="<?php if ($errors["foto"]) { echo "parsley-error"; } ?> custom-file"> <input id="foto" type="file" name="foto[]"> </div> <?php showError($errors, "foto"); ?> </div> <?php if ($firma) { $foto = null; foreach ($firma->foto as $image) { $foto = $image->width(250); break; } if ($foto != null) { echo "<img src='".$foto->url."' />"; } } ?> </div> //Save if($input->post->action == 'send') { // first validate the CSRF token to check if it is a valid request if(!$session->CSRF->hasValidToken()){$errors['csrf'] = "Form submit was not valid, please try again."; } //Look for required fields and make sure they have a value foreach($required_fields as $req) { //print_r($_FILES); //die; // required file upload field if($form_fields[$req]['type'] == 'file'){if(empty($_FILES[$req]['name'][0])){$errors[$req] = "Wählen Sie Dateien zum Hochladen aus.."; } } else if($form_fields[$req]['type'] == 'checkbox'){if($form_fields[$req]['value'] == 0){$errors[$req] = "field necessary.";} // erforderliche Textfelder } else if($form_fields[$req]['type'] == 'text' || $form_fields[$req]['type'] == 'textarea' || $form_fields[$req]['type'] == 'email') { if(!strlen($form_fields[$req]['value'])){$errors[$req] = "Feld notwendig."; } // reqired email fields if($form_fields[$req]['type'] == 'email') { if($form_fields[$req]['value'] != $input->post->$req){$errors[$req] = "Bitte eine gültige E-Mail Adresse angeben.";} } } } Link to comment Share on other sites More sharing options...
Jan Romero Posted December 6, 2022 Share Posted December 6, 2022 How are you uploading from the client? Does your form element have the attribute enctype="multipart/form-data"? Link to comment Share on other sites More sharing options...
Frank Schneider Posted December 6, 2022 Author Share Posted December 6, 2022 i add this and no changes, $_FILES is empty Link to comment Share on other sites More sharing options...
Jan Romero Posted December 7, 2022 Share Posted December 7, 2022 @Frank Schneider Did you get it fixed? I fear there may not be enough information here to diagnose it. You should look at the POST request in your browser console and maybe post the (presumably javascript) code that makes the request in this thread. Link to comment Share on other sites More sharing options...
gebeer Posted December 8, 2022 Share Posted December 8, 2022 To me this looks like a redirect issue. Thing is, that $_FILES gets cleared when POST requests are redirected. You can check for redirects in your browser dev tool's network tab when you submit the form. If you use the exact same form for both submissions (company and employee), you need to check what is different when you submit the form. Is the form action URL for both exactly the same? Do you have any code in place that redirects the form submission to a different URL when using it for employee? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now