|
Save current page URL in custom field with CRED form
Started by: ThomasB2891
in: Toolset Professional Support
Quick solution available
Problem: I would like to use a CRED form to save the current page URL into a custom field on a new post. I plan to use this as a "saved search" so Users can visit the same search again later.
Solution: If your form does not use AJAX, you can use the following code to automatically save the current page URL in a CRED custom field:
add_action('cred_save_data', 'save_page_url_to_custom_field',10,2);
function save_page_url_to_custom_field($post_id, $form_data) {
if ($form_data['id'] == 123)
{
update_post_meta($post_id, 'wpcf-search-url', $_SERVER['HTTP_REFERER']);
}
}
Replace '123' with the numeric ID of this CRED form, and replace "search-url" with the slug of your custom field.
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
|
|
2 |
5 |
6 years, 10 months ago
ThomasB2891
|
|
Use WP REST API to create and view custom post from another website
Started by: davidZ-4
in: Toolset Professional Support
Quick solution available
|
|
2 |
7 |
6 years, 10 months ago
davidZ-4
|
|
How to use CRED date fields as timestamps in the API
Started by: maksimG
in: Toolset Professional Support
Quick solution available
Problem:
Client is trying to access the date fields submitted with a CRED form in a CRED hook, but the values available in $_POST are not in the timestamp format used to store the dates in the database.
Solution:
With the cred_save_data hook the post—and it's meta data—have already been saved, so using the post id it is possible to directly retrieve the date fields using get_post_meta that are already in the desired timestamp format.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
|
|
2 |
3 |
6 years, 11 months ago
maksimG
|
|
Assign author name and post id to title through cred form
Started by: garyF-3
in: Toolset Professional Support
|
|
2 |
4 |
6 years, 11 months ago
Shane
|
|
How to create a sticky post with CRED
Started by: johanL-2
in: Toolset Professional Support
Quick solution available
|
|
2 |
3 |
6 years, 11 months ago
johanL-2
|
|
How to build Web Apps using CRED?
Started by: AtefR7377
in: Toolset Professional Support
Quick solution available
Problem: How can I use CRED to build Web Apps?
Solution: You will find links to training guides, references and tutorials in our User Guides that discuss what you can accomplish with CRED. More advanced topics are covered in our API documentation. You can use the API to accomplish many things in CRED that you are not able to accomplish through the wp-admin area directly. These advanced features require custom code and PHP.
How you build a Web App with those CRED forms and the content they generate really depends on what your Web App is designed to do. If there is a specific part of the process you are having trouble with, feel free to create individual tickets where we can address specific questions.
Relevant Documentation:
https://toolset.com/documentation/user-guides/#cred-topics
https://toolset.com/documentation/programmer-reference/cred-api/
|
|
2 |
3 |
6 years, 11 months ago
AtefR7377
|
|
url var ?post is that equal to $post_id when used dynamically
Started by: rexJ-2
in: Toolset Professional Support
|
|
2 |
4 |
6 years, 11 months ago
rexJ-2
|
|
Creating child post with CRED: hooked actions no longer work
Started by: neilR
in: Toolset Professional Support
|
|
2 |
12 |
6 years, 11 months ago
Nigel
|
|
Favorite Posts By Logged In User (Add To / Remove not working properly)
Started by: Team DNK
in: Toolset Professional Support
Quick solution available
Problem: I would like Users to be able to choose certain posts as favorites. They should also be able to remove them from favorites.
Solution:
Create a repeating numeric field on your post type called "favorites". This field will be updated to add the current User's ID when they select a favorite. When they unfavorite a post, this field will be updated to remove their ID.
Create a CRED form that allows you to modify the posts that can be favorited. Remove all the content from the CRED form and replace it with the following code:
[credform class='cred-form cred-keep-original']
[wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '1' )"]
[cred_generic_field field='remove-favorite' type='hidden' class='']
{
"required":0,
"validate_format":0,
"default":"1"
}
[/cred_generic_field]
[/wpv-conditional]
[cred_field field='form_submit' value='Favorite' urlparam='' class='x-btn x-btn-global mam']
[/credform]
Add the following JavaScript to your CRED form's JS panel:
jQuery(window).bind("load", function() {
jQuery( "form[id^='cred_form_368']").find("input[type='submit']").val(jQuery( "input[name='remove-favorite']").length ? "Remove from Favorites" : "Add to Favorites");
}
)
This code will toggle between showing "Add to Favorites" and "Remove from Favorites" as the button name.
Add the following PHP to your child theme's functions.php file:
add_action('cred_save_data_368', 'sda_user_favorites',10,2);
function sda_user_favorites($post_id, $form_data) {
if( isset($_REQUEST['remove-favorite']) ) {
delete_post_meta($post_id, 'wpcf-favorites', get_current_user_id());
} else {
add_post_meta($post_id, 'wpcf-favorites', get_current_user_id(), false);
}
}
/* Favorites shotcode for use as a conditional */
add_shortcode( 'toolset_is_favorite', 'toolset_is_favorite_func');
function toolset_is_favorite_func($atts)
{
global $wpdb;
$post_id = $atts['id'];
$user_id = get_current_user_id();
$favorites = $wpdb->get_results( "SELECT * FROM wp_postmeta WHERE meta_key = 'wpcf-favorites' AND post_id = $post_id AND meta_value = $user_id LIMIT 1");
return sizeof($favorites) ? 1 : 0;
}
Be sure to add the toolset_is_favorite shortcode in Toolset > Settings > Frontend content > 3rd party shortcode arguments.
Place the CRED form in a View of posts, or in a Content Template for these posts.
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
|
|
3 |
19 |
6 years, 11 months ago
Team DNK
|
|
Unable to add fields to CRED form, JavaScript error in console
Started by: eun-kenL
in: Toolset Professional Support
Quick solution available
Problem:
When editing a CRED form it is not possible to insert fields, the following error appears in the JS console:
/wp-admin/admin-ajax.php?action=cred_ajax_Forms&_do_=getPostFields
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
In the PHP logs the error responsible was:
PHP Fatal error: Call to undefined function mb_convert_case()
Solution:
The standard mb_string PHP module needs to be activated on the server, consult host provider if required.
Relevant Documentation:
http://php.net/manual/en/function.mb-convert-case.php
|
|
2 |
13 |
6 years, 11 months ago
eun-kenL
|
|
Send emails/notifications to all the result of a view search
Started by: razvanP
in: Toolset Professional Support
|
|
2 |
2 |
6 years, 11 months ago
Nigel
|
|
Display error if sum of all file sizes, repeated field, cred_form_validate
Started by: tinaH
in: Toolset Professional Support
|
|
2 |
5 |
6 years, 11 months ago
Nigel
|
|
"use slug field on cred"
Started by: David Treviño
in: Toolset Professional Support
|
|
2 |
2 |
6 years, 12 months ago
Luo Yang
|
|
[ATTN: Christian Cox] – continuation of "one-to-many user relationships"
Started by: MichaelR9215
in: Toolset Professional Support
|
|
2 |
8 |
6 years, 12 months ago
Christian Cox
|
|
Can Toolset do this?
Started by: Tiago Valente
in: Toolset Professional Support
|
|
2 |
4 |
6 years, 12 months ago
Luo Yang
|