[Resolved] Check if form value = custom field value and set radio to other value
This support ticket is created 4 years ago. 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.
What we are trying to achieve is this: We would like to use Toolset Forms to change the radio button value on tardigrade with unique code which they find at the place where is that 3D printed Tardigrade found.
So the flow is:
1) The go to university landing page which we are building, look at the map for the not found Tardigrades in czech republic
2) Go to the place
3) find tardigrade with unique ID
4) Go to website form, write the ID
5) If the ID value is found and the Radio button is set to the 0 (Not found) at the post, set the radio button to 1 and redirect to thank you, please share page.
6) if the ID value is not found, refresh the page and show the notice at the top of page - Unique ID does not exist, try it again please.
Is it possible to do this kind of data verification with toolset forms?
It seems like you want a form where the users input the tardigrades id and once they submit you check if the unique id already exists and if it is already found if not found you are changing the status as found ? I hope i got this right ?
You can make use of the Forms API in this case i would suggest using two filter cred_form_validate and cred_save_data
1) Using cred_form_validate you can validate the Unique ID by checking again the CPT Tardigrades, You might need some custom
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($error_fields, $form_data)
{
// Add the validation here, The form fields can be obtained from $_POST
// If unique id found return the form data
// Add unique id check here
// if not found return an error message
}
I understand the way you think. Thats nice, and thanks for that. I only need some more informations.
1) I can not use the edit post form at other page than post.
- I need form, which is placed on page called "Verify your findings". When I set up the form to edit posts, then I cannot use it on this page.
2) I dont know how to build the validation.
I understand that I need to use $_POST (I am new in Programming, but I wil search what is it). To get what user filled in, so:
$userinput = $_POST["name"]
Then I need to check all posts in custom post type Tardigrades and their custom field called Unique ID (wpcf_unique_id). So this should be a database query or custom post query?
And if there is a Tardigrades post, which has same unique ID, then change value of radio button (wpcf_found) to 2. So I need something like this:
if ($userinput exists in some tardigrade post) {
get that post id and change it radio button to 2
}
else display error message and dont save.
I need form, which is placed on page called "Verify your findings". When I set up the form to edit posts, then I cannot use it on this page.
Please follow the instruction here on how to create a Edit form, https://toolset.com/course-lesson/front-end-forms-for-editing-content/
And while inserting the "Edit post link" You will have to option to choose a different page or post type which needs to be editor under the post selection check the attached screenshots
Yes, your validation can be implemented with forms as mentioned in the above response the custom function needs to be hooked to the filter add_filter('cred_form_validate','my_validation',10,2); Also in your code snippet it seems you are updating the data which is not recommended in the form_validation hook however if you are sure that it needs to be there then you can proceed with that.