Skip Navigation

[Geschlossen] validate file data structure on upload – cred_form_ajax_upload_validate

This support ticket is created vor 2 Jahre, 9 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 Antworten, has 2 Stimmen.

Last updated by Luo Yang vor 2 Jahre, 9 Monate.

Assisted by: Luo Yang.

Author
Artikel
#2094865

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

#2095301

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

#2095443

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

#2095449
network.JPG

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

#2095459

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

#2095629

I have marked this thread as "Waiting for feedback" status, you can update here if still need assistance.

Das Thema „[Geschlossen] validate file data structure on upload – cred_form_ajax_upload_validate“ ist für neue Antworten geschlossen.