• Resolved dailymay

    (@dailymay)


    I am currently using VSEL (very simple events) with ACF and would like to use Forminator to build a frontend event post submission form. VSEL from my understanding uses post custom fields, however, it is not showing in the Forminator custom field section. I have input the meta values but nothing works? The ACF works just fine. Wondering where I am going wrong?

Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @dailymay

    I hope you are doing good today.

    I was able to replicate this on my lab site as well. As we don’t know VSEL coding and architecture we can’t confirm why this is behaving such. I pinged our SLS Team to review VSEL core and we will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Thread Starter dailymay

    (@dailymay)

    Hi Kris,

    Thank you so much for looking into this, I will await your teams response.

    Kind Regards,

    Hanna

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hey there @dailymay

    We got some updates from our Second Level Support developers.

    For date fields we need to set up the fields like the following image:
    https://monosnap.com/file/l2zbZqhN8oab84nBevtYtoHuJWonqO

    date-1 and time-1 is for start date and time and date-2 and time-2 is for the end date and time. We also selected the 24-hour time format.
    In the VSEL plugin they are combining the date and time fields and storing them as a timestamp, so for Forminator to do that we need to add the following code as a MU-plugin:

    <?php
    add_action( 'forminator_post_data_field_post_saved', 'wpmudev_forminator_create_event_date' ,10, 4);
    function wpmudev_forminator_create_event_date( $post_id, $field, $data, $page ){
    	if( $field['element_id'] == 'postdata-1' ){
    		//Start Date
    		$date = $_REQUEST['date-1'];
    		$time = $_REQUEST['time-1-hours'].':'.$_REQUEST['time-1-minutes'];
    		$start_date = sanitize_text_field(strtotime($date.$time));
    		update_post_meta( $post_id, 'event-start-date', $start_date);
    
    		//End Date
    		$end_date = $_REQUEST['date-2'];
    		$end_time = $_REQUEST['time-2-hours'].':'.$_REQUEST['time-2-minutes'];
    		$end_dates = sanitize_text_field(strtotime($end_date.$end_time));
    		update_post_meta( $post_id, 'event-date', $end_dates);
    	}
    }

    In custom fields, we do not need to map the start and the end date because we are doing it from the above snippet. Other than those two, we can map all the other fields. Here are the meta keys and accepted values (these can be found in the file vsel.php, the names are being used in the update_post_meta() function):

    event-hide-end-time : yes/no
    event-all-day : yes/no
    event-location : textual data
    event-link : URL
    event-link-label : textual data
    event-link-target : yes/no(open in new window/do not open in new window)
    event-link-title : yes/no - this is for linking event title
    event-summary : textual data

    Warm regards,
    Dimitris

    Thread Starter dailymay

    (@dailymay)

    Hi Dimitris,

    Thank you for getting back to me, the text and url fields are working great with the code however, I can’t seem to get the date and time fields working, it is delivering back this error message? https://monosnap.com/file/fO0gwLhn41vXBy87ST6vqJDzVqsu1G

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @dailymay

    If I correctly understand, that notice is triggered when VSEL plugin tries to read either date or time that’s already saved in the database.

    Specifically, it’s happening when it tries to read that date and time and that would mean that the date/time info stored in DB is malformed. It’s difficult to check that without looking into the database, though.

    I tested the code snippet on my own test site and I couldn’t replicate the issue but there are two things that I noticed that may be related:

    1. did you for sure set both timepicker fields to a 24 hour time format instead of 12 hour (so AM/PM) format?

    2. did you remove any attempted date/time fields mapping from form’s “post data” field’s “custom fields” settings (the code does mapping for these so they should not be still set to be mapped as custom fields in form)?

    Best regards,
    Adam

    Thread Starter dailymay

    (@dailymay)

    Hi Adam,

    Is it possible if you could take a snapshot of the mock Custom field section of the ‘Post Data’ so I can have a better understanding to how you have set this up.

    I have attached two screenshot of my settings, the timepicker was indeed set to 12-hour format I have corrected this, however the information for the date and time still isn’t showing in the backend of the post.

    https://monosnap.com/file/U7ROfuOF9Zu9tn7h3XKMCGOlCWvS2z

    https://monosnap.com/file/xCYcoy1pUJlfLiYJpE1Wu0IfK3mTlh

    Am I missing something?

    Kind Regards,

    Hanna

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @dailymay Please do not create duplicate topics. I have archived your new one.

    Duplicate topics make it harder for the volunteers here (everyone here is a volunteer including plugin support) to support you.

    I have archived your new topic.

    Thread Starter dailymay

    (@dailymay)

    Hi Jan, thank you for achieving it, I presumed the other thread was closed, was only after I duplicated I saw the unresolved settings. Thanks again ??

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @dailymay

    I looked at your screenshots and the second one – this one

    https://monosnap.com/file/xCYcoy1pUJlfLiYJpE1Wu0IfK3mTlh

    also needs to be changed. You do not need to and you should not use these settings for the start and end date/time in “Custom fields” settings of “post data” field of the form.

    Remove them form there – those that carry event start/end date and time. Other fields can be set/mapped there but those are not needed there at all because code takes care of it.

    Best regards,
    Adam

    Thread Starter dailymay

    (@dailymay)

    Hi Adam,

    Thank you for getting back to me, I have removed the mapping from the “Custom fields” settings of the “Post Data” as suggested, unfortunately, the date and time fields are still not saving to the back of the site from the form? All the other fields are working fine.

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @dailymay

    Could you export your form https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export and share using Google drive so we can run some tests?

    Best Regards
    Patrick Freitas

    Thread Starter dailymay

    (@dailymay)

    Hi Patrick,

    Thank you so much for your help, I have managed to solved the problem for the date and time, all the fields are now working great!

    If I may ask just one more question, I am currently using this code below on the same frontend form to limit users (via IP) submissions to 5 posts every 30 days.

    https://wpmudev.com/forums/topic/forminator-pro-limiting-form-submissions-via-ip-address-within-time-period/

    I have changed this line to: $future_time = strtotime( ‘+30 day’, strtotime( $entry->date_created_sql ) );

    Is this correct? and was also wondering where do I change the number of post submissions?

    Thanks again ??

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @dailymay

    That is correct, but it is for one submission every 30 days, as it gets the latest submission only

    
    $last_entry = Forminator_Form_Entry_Model::get_last_entry_by_ip_and_form( $form_id, $user_ip );

    I pinged our developers to check what is the best approach to add an extra verification for 5 submissions.

    We will keep you posted.

    Best Regards
    Patrick Freitas

    Thread Starter dailymay

    (@dailymay)

    Thank you so much Patrick, I will await to hear from the team.

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @dailymay,

    Could you please try the following Snippet and see whether it helps:

    <?php
    
    add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) {
        // Add your form IDs here.
        $form_ids = array( 361 );
        // Change this to the message that you want to show.
        $message = 'You cannot submit more than 5 times within 30 days.';
        if ( in_array( intval( $form_id ), $form_ids, true ) ) {
            $user_ip = Forminator_Geo::get_user_ip();
            if ( ! empty( $user_ip ) ) {
                $last_entry = wpmudev_get_last_few_entries( $form_id, $user_ip );
                if ( ! empty( $last_entry ) ) {
                    $entry = Forminator_API::get_entry( $form_id, $last_entry );
                    $current_time = strtotime( date( 'Y-m-d H:i:s' ) );
                    $future_time = strtotime( '+30 days', strtotime( $entry->date_created_sql ) );
                    if ( $current_time < $future_time ) {
                        $submit_errors[]['submit'] = $message;
                    }
                }
            }
        }
        return $submit_errors;
    },15,3);
    
    function wpmudev_get_last_few_entries( $form_id, $user_ip ){
        global $wpdb;
        $table_name       = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY_META );
        $entry_table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY );
        $sql              = "SELECT m.<code>entry_id</code> FROM {$table_name} m LEFT JOIN {$entry_table_name} e ON(e.<code>entry_id</code> = m.<code>entry_id</code>) WHERE e.<code>form_id</code> = %d AND m.<code>meta_key</code> = %s AND m.<code>meta_value</code> = %s order by m.<code>meta_id</code> desc limit 4,5";
        $entry_id         = $wpdb->get_var( $wpdb->prepare( $sql, $form_id, '_forminator_user_ip', $user_ip ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
        if ( $entry_id ) {
            return $entry_id;
        }
        return false;
    }
    
    

    Please make sure to update the line:

        $form_ids = array( 361 );
     

    To your Form ID, ie suppose your form ID is 123, the above line will change to:

        $form_ids = array( 123 );
     

    Since its 30days, if you are looking to test it out quickly you can change the value +30 days in the following line:

                    $future_time = strtotime( '+30 days', strtotime( $entry->date_created_sql ) );
     

    To +30 mins, so that you could test it out to see whether it works in limiting the submission within 30 mins:
    $future_time = strtotime( '+30 mins', strtotime( $entry->date_created_sql ) );

    The above code can be added as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,
    Nithin

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘Custom Field error for Front-End Form’ is closed to new replies.