• Resolved rish30990

    (@rish30990)


    hi! I want to show preview of form after user click on submit button. Same as the preview option is available in “Caldera-forms -> Registor” option. Is it possible to make preview for user when he/she click on submit. Or any other kind of preview if not popup then atleast through page redirect, i can show preview of form data to user. Thanks in advance ??

    https://www.ads-software.com/plugins/caldera-forms/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter rish30990

    (@rish30990)

    Ok may be I asked too much thats why I did’t get reply. However I figured out a lot. I am calling “wp_cf_form_entry_values” table (in which all entries available) through a template file. And its working fine.

    BUT I have one problem remaining. My plan is that when user click on submit button then he/she redirected to a different page (template page in which I am calling ‘wp_cf_form_entry_values’ table from $wpdb). And there they can watch their detail (which they have added just now). But right now the page is showing whole record of the table BUT I want to show only their record

    So can you at least tell me how can I call last submitted entry instead of whole table. I know a way ($last_insert_id = $wpdb->insert_id;) but that did’t work.

    I know its somewhere in your plugin one line code that I need in my template file but can’t find out which one because so many files and code are available in your plugin.

    So can you please tell me which line I need to add in my template file so that I can show user only their record as a preview.

    Here is my code of template file :

    <?php
    /*
    Template Name: Registration
    */
    get_header();
    
    global $wpdb;
    
    //Create a mulit dimensional array for each slug.
    $field_slugs = array();
    //$last_insert_id = $wpdb->insert_id;
    $fields = $wpdb->get_results( 'SELECT * FROM wp_cf_form_entry_values');
    foreach($fields as $field){
        $field_slugs[$field->slug][$field->entry_id] = $field->value;
    }
    
    //the table
    echo '<table width="100%" border="1" cellspacing="1">';
    $i=0;
    foreach($field_slugs as $slug=>$values){
    
        //the table header (only in the first loop)
        /*if($i==0){
            echo '<tr>';
            foreach($values as $person_id=>$val){
                echo '<th></th>';
                echo '<th>Person '.$person_id.'</th>';
            }
            echo '</tr>';
        }
    */$slug = str_replace('_', ' ', $slug);
    $slug = ucwords($slug);
        // one line per person
        echo '<tr id="'.$slug.'">';
        echo '<td><b>'.$slug.'</b></td>';
        foreach($values as $person_id=>$val){
            echo '<td>'.$val.'</td>';
        }
        echo '</tr>';
        $i++;
    }
    
    if($i==0){
       echo "<table width='100%' border='1' cellspacing='1'><tr><td>No Records Found</td></tr></table>";
    }
    
    echo '</table>';
    
    get_footer();?>

    I hope its not too much to ask

    Plugin Contributor David Cramer

    (@desertsnowman)

    I’m writing this on my phone, so I might be wrong. But try $entry = Caldera_Forms::get_entry( (int) $_GET['cf_id'] );

    Thread Starter rish30990

    (@rish30990)

    I put the line of code just before the foreach loop. so after putting that line (which is being stored in $entry) what should I do with the $entry varible.

    Plugin Contributor David Cramer

    (@desertsnowman)

    no, what I meant is this is so you don’t need any database query at all.
    $entry will contain all the values of the entry.
    So $entry kind of replaces $field_slugs

    basically, try this code and replace your_form_id with your form ID

    if( !empty( $_GET['cf_id'] ) ){
    
    	$entry = Caldera_Forms::get_entry( (int) $_GET['cf_id'], 'your_form_id' );
    
    	var_dump( $entry );
    
    }

    Thread Starter rish30990

    (@rish30990)

    Thanks david! It really helped. Actually I couldn’t understand completely that how to print data value from your code, may be because i am habitual to work with database query. So that code seems more advanced as per my current level.

    But I GOT A Major hint from your code which helped me to resolve my problem. I simply fetch cf_id to print form. HERE is an example what I did :

    if(isset($_GET['cf_id']))
    {
    $entryid = $_GET['cf_id'];
    if($entryid)
    {
    global $wpdb;
    $results = $wpdb->get_results( "SELECT * FROM wp_cf_form_entry_values where entry_id='$entryid'");
    if(!empty($results)) {
    
    CONTENTS....
    
    }}}

    That solution is working as per my expectation.

    Thnks for the help David ??

    Plugin Contributor David Cramer

    (@desertsnowman)

    you’re welcome.

    Sorry what file would I need to go to add that chunk of code? I found 2 which one is it?
    caldera-forms/processors/functions.php or caldera-forms/includes/functions.php

    As always help would be appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to get preview of registered data after form submit’ is closed to new replies.