Skip Navigation

[Fermé] validate file data structure on upload – cred_form_ajax_upload_validate

This support ticket is created Il y a 3 années et 5 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Marqué : 

Ce sujet contient 5 réponses, a 2 voix.

Dernière mise à jour par Luo Yang Il y a 3 années et 5 mois.

Assisté par: Luo Yang.

Auteur
Publications
#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?
lien caché

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.

Le sujet ‘[Fermé] validate file data structure on upload – cred_form_ajax_upload_validate’ est fermé à de nouvelles réponses.