Home › Forums › Quform WordPress › file code.txt validation
- This topic has 8 replies, 3 voices, and was last updated 6 years, 9 months ago by
Icemanmx.
- AuthorPosts
- July 10, 2018 at 7:12 pm #26292
Icemanmx
ParticipantHello
I want to make that i can make a code.txt file instead of array of pass codes if that can be done.add_filter('quform_element_valid_1_37', function ($valid, $value, $element) {
$codes = array('PASS', 'pass');if (!in_array($value, $codes)) {
$element->addError('Código no válido');
$valid = false;
}return $valid;
}, 10, 3);Thanks in advance
IcemanmxJuly 12, 2018 at 11:18 pm #26310Icemanmx
ParticipantOr even can use a api for codes….
- This reply was modified 6 years, 10 months ago by
Icemanmx.
July 23, 2018 at 5:26 pm #26345Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 23, 2018 at 9:10 pm #26353Icemanmx
ParticipantThanks again,,,
Will try it later today..Thanks
July 24, 2018 at 6:25 am #26355Icemanmx
ParticipantHello
I did not function for me.add_filter('quform_element_valid_1_37', function ($valid, $value, $element) { / $codes = file(WP_CONTENT_DIR . '/surveyhdapg/codes.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!in_array($value, $codes)) { $element->addError('Código no válido'); $valid = false; } return $valid; }, 10, 3);
I have all the files under plugin folder /surveyhdapg/codes.txt in that text file i have one word on each row:
test
test1
TEST1But i get the error Código no válido
I also tried to put 666 permission on the txt file, but normally 644 should be okay..
Best Regards
IcemanmxJuly 25, 2018 at 2:43 am #26365katw
ParticipantHi @Icemanmx
Saw your post and thought I could help.
You said your code.txt file is in the plugin folder – yes?
If yes, the code you are using is looking for file in WP Content folder. Also you have a leading slash at start of the line which shouldn’t be there.
Try:
add_filter('quform_element_valid_1_37', function ($valid, $value, $element) { $codes = file(WP_PLUGIN_DIR . '/surveyhdapg/codes.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!in_array($value, $codes)) { $element->addError('Código no válido'); $valid = false; } return $valid; }, 10, 3);
July 26, 2018 at 3:22 am #26387Icemanmx
ParticipantHello
I already try that without the trailing slash, but he don´t read the txt file what i put in it… Maybe need right permissions, but i try 666 and 644 and did not help…Best Regards
Icemanmx- This reply was modified 6 years, 9 months ago by
Icemanmx.
July 26, 2018 at 3:53 am #26389katw
ParticipantThe SLASH at start of $codes line shouldn’t be there so take it out. I didn’t suggest removing a trailing slash, just the one at start of the first line.
Did you see the directory path change in my code?
WP_PLUGIN_DIR not WP_CONTENT_DIR
You could add a debug statement to see what path is being created and then test the path manually to see if you can access the code.txt file from that path.
You might also see from doing this if the text file contains the correct contents. Sometimes when file security is set wrong the contents shows an error message not the file itself which gives you heads-up you need to fix file attributes.
add_filter('quform_element_valid_1_37', function ($valid, $value, $element) { $pathcheck = WP_PLUGIN_DIR . '/surveyhdapg/codes.txt'; echo '<script language="javascript">'; echo 'alert("Path:' . $pathcheck .'")'; echo '</script>'; $codes = file(WP_PLUGIN_DIR . '/surveyhdapg/codes.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!in_array($value, $codes)) { $element->addError('Código no válido'); $valid = false; } return $valid; }, 10, 3);
I assume you have the correct field reference 1_37 too? You will know soon enough if the alert box appears.
July 26, 2018 at 4:53 am #26392Icemanmx
ParticipantThanks katw
This function perfect now…
Best Regards
Icemanmx - This reply was modified 6 years, 10 months ago by
- AuthorPosts
- You must be logged in to reply to this topic.