Can you please share problem URL where you added your form as well as access details and tell me how exactly you setup the fields and what fields you want to save.
I have a CRED from (orange button) with which the user can create events. If the same event should be repeated multiple times, the user can insert a "lastday" and he can also select on which days the event should take place (the checkboxes field).
For the weekdays I stored the following values in the checkboxe custom field:
Title: Monday
Value to store: 1
Title: Tuesday
Value to store: 2
Title: Wednesday
Value to store: 3
.. and so on, until ..
Title: Sunday
Value to store: 7
The PHP code in Toolset Custom Code Snippet section:
(the name of the snippet is "schwarzesbrett_serien-termine")
add_action('cred_save_data', 'terminserie_erstellen',10,2);
function terminserie_erstellen ($post_id, $form_data) {
// if a specific form
$forms = array( 10441 );
if (in_array($form_data['id'], $forms) && ($_POST['wpcf-eine-information-oder-ein-termin']['select'] == "1")) {
$id_reitanlage = $_POST['reitanlagen_id'];
$startday = $_POST['wpcf-rask-von-tag']['datepicker'];
$nextday = $startday + ( 1 * 24 * 60 * 60 );
$endday = $_POST['wpcf-rask-bis-tag']['datepicker'];
for ($day = $nextday; $day <= $endday; $day+=86400) {
$weekday = date("N", $day );
$weekdays = $_POST["wpcf-rask-wochentag"];
if (in_array($weekday, $weekdays)) {
// Create post object
$termin = array(
'post_title' => $day,
'post_status' => 'publish',
'post_type' => 'event',
'meta_input' => array (
'wpcf-rask-von-tag' => $day,
'wpcf-rask-bis-tag' => $day,
'wpcf-covid-19-journal-name-der-aktivitat' => $_POST['wpcf-covid-19-journal-name-der-aktivitat'] . $weekdays ,
'wpcf-rask-welches-journal-termine' => $_POST['wpcf-rask-welches-journal-termine'],
'wpcf-eine-information-oder-ein-termin' => '1',
),
);
// Insert the post into the database
$termin_id = wp_insert_post( $termin );
// Connect with reitanlage
if($id_reitanlage){
toolset_connect_posts(
$relationship = 'reitanlage-event',
$id_reitanlage,
$termin_id);}
}
}
}
}
If I use a fictional array $weekdays = array("1" , "3" , "6"); instead of $weekdays = $_POST["wpcf-rask-wochentag"]; the duplicate will be created. That's why I try to figure out, how I can turn the $_POST["wpcf-rask-wochentag"] into an array.
At the moment the fictional array $weekdays = array("1" , "3" , "6"); is implemented in the testsite.
Kind regards,
Lara