Tell us what you are trying to do? I would like to validate file data structure on upload. not file extension validate.
Is there any documentation that you are following? https://toolset.com/documentation/programmer-reference/cred-api/
Is there a similar example that we can see?
I don't know
What is the link to your site?
hidden link
Hi,
I'm using cred_form_ajax_upload_validate to validate the file extension on upload successfully.
The issue I have is that I would like to validate the file data structure as well but not sure how to get the uploaded file path.
Ideally I would like to have the following process
1. Validate file extension is correct (using : cred_form_ajax_upload_validate)
1a. if error - deny upload, ask user to upload file with acceptable file extension.
1b. if no error - go to step 2
2. get file path and validate file data structure
2a. if error - deny upload, ask user to correct the file data structure and try again (go to step 1 on ne upload).
2b. in no error - accept the file and continue to the form (so user can complete the form submitting)
Currently I have an issue with getting the file path in step 2 and I cannot run validation on file data structure.
The file we extensions I accept are txt, csv, and excel. The data structure is a table with two columns and unlimited row numbers.
Any ideas on how to do the validation process above before user submit the form and with one hook?
Or do I need to use another hook for step 2 (like cred_form_validate)?
Please advise,
Thanks,
David
Hello,
I assume you are going to get the absolute file path of uploaded file.
If it is, it is possible, for example, if you are uploading the file to post featured image field, it is in below variable:
...
list($fields,$errors)=$error_fields;
$tmp_name = $fields['_featured_image']['field_data']['tmp_name']; // absolute file path
...
More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_ajax_upload_validate
Thanks Luo,
Allow me to confirm with you that I understand the syntax.
In my code it will look like this:
$filepath = $fields['wpcf-my-field-slug']['field_data']['tmp_name'];
I understand that the "['field_data']['tmp_name']" will provide the absolute path to file that was uploaded to the custom field named "my-field-slug".
please let me know if this is correct.
thanks,
David
Yes, you are right, it should be:
$filepath = $fields['wpcf-my-field-slug']['field_data']['tmp_name'];
And you can simply output the $fields variable manually by these:
...
list($fields,$errors)=$error_fields;
var_dump($fields); // debug the $fields variable
die();
$tmp_name = $fields['_featured_image']['field_data']['tmp_name']; // absolute file path
...
Upload a file with the post form in front-end, you should be able to see the results in your Chrome browser network console window, see my screenshot network.JPG
Thanks Luo,
I'm going to check this in the next couple of days and will keep you updated if i need further help.
regards,
David
I have marked this thread as "Waiting for feedback" status, you can update here if still need assistance.