Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload issue #1590

Open
rajaevvotech opened this issue Sep 9, 2024 · 1 comment
Open

File upload issue #1590

rajaevvotech opened this issue Sep 9, 2024 · 1 comment
Assignees

Comments

@rajaevvotech
Copy link

rajaevvotech commented Sep 9, 2024

Hello.

I have used the file type to create a custom attribute. The file has been successfully updated in the admin portal lead form. however, while utilising the embed web form, the file has not been uploaded but, rest all field were updated. Kindly advice me to fix this issue.

I have tried to modify Ajax code too, but not working.

Ajax code path: packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js.blade.php

Ajax code:

` $("#krayinWebForm").validate({
submitHandler: function(form) {

                document.querySelector('#loaderDiv').classList.add('loaderDiv');

                document.querySelector('#imgSpinner').classList.add('imgSpinner');

                $.ajax({
                    url: "{{ route('admin.settings.web_forms.form_store', $webForm->id) }}",
                    type: 'post',
                    data: formData,
                    headers: {
                        'X-CSRF-TOKEN': "{{ csrf_token() }}"
                    },
                    dataType: 'json',
                    success: function (data) {

                        document.querySelector('#loaderDiv').classList.remove('loaderDiv');

                        document.querySelector('#imgSpinner').classList.remove('imgSpinner');

                        var validator = $("#krayinWebForm").validate();

                        if (data.message) {
                            $('.alert-wrapper .alert p').text(data.message);

                            $('.alert-wrapper').show();
                        } else {
                            window.location.href = data.redirect;
                        }

                        $("#krayinWebForm").trigger("reset");
                    },

                    error: function (data) {

                        document.querySelector('#loaderDiv').classList.remove('loaderDiv');

                        document.querySelector('#imgSpinner').classList.remove('imgSpinner');
                        
                        var validator = $("#krayinWebForm").validate();

                        for (var key in data.responseJSON.errors) {
                            var inputNames = [];
                
                            key.split('.').forEach(function(chunk, index) {
                                if(index) {
                                    inputNames.push('[' + chunk + ']')
                                } else {
                                    inputNames.push(chunk)
                                }
                            })
        
                            var inputName = inputNames.join('');

                            var error = {};

                            error[inputName] = data.responseJSON.errors[key][0];

                            validator.showErrors(error);
                        }
                    }
                });
            }
        });
    });`

Path: packages/Webkul/Attribute/src/Repositories/AttributeValueRepository.php

if ($attribute->type === 'image' || $attribute->type === 'file') { try { if (request()->hasFile($attribute->code)) { $file = request()->file($attribute->code); if ($file->isValid()) { $data[$attribute->code] = $file->store($data['entity_type'] . '/' . $entityId); } else { throw new \Exception('Uploaded file is not valid.'); } } else { $data[$attribute->code] = null; } } catch (\Exception $e) { Log::error('File upload error: ' . $e->getMessage()); $data[$attribute->code] = null; // Handle file upload error gracefully } }

file

Thanks!

suraj-webkul added a commit to suraj-webkul/laravel-crm that referenced this issue Sep 10, 2024
suraj-webkul added a commit to suraj-webkul/laravel-crm that referenced this issue Sep 11, 2024
@suraj-webkul
Copy link
Collaborator

This issue has been fixed in this pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants