Recently I had a long form to display on a membership website. I wanted a visitor to be able to leave the form incomplete and then to return to finish it later. My approach with CForms was to break the long form up into a series of very short forms, each to be filled out once. For this explanation, suppose I broke the long form into four short forms. If the visitor completed the first two, I wanted the controlling page to look like:
To accomplish this, I began by adding one hidden field to each form, called Your ID with the default value {CurUserID}. Because this field is included in all forms, I could use it to determine if the current user had previously submitted a form.
I didn’t want to compose a new PHP function within CFORMS to select specific records. If I had, I could have directly determined if the stored forms in the Tracking section contained a record. Instead, I used an existing CFORM function
Using the EXEC-PHP plugin to add code to a page, I added the following in the page with links to the forms.
[exec]
function isn_did_this_user_submit_form($formname) {
global $current_user;
/* get the array of submitted forms */
if ($results = get_cforms_entries($formname)) {
foreach ($results as $submission) {
if ($current_user->ID == $submission["data"]["Your ID"]) {
return(true);
}
}
}
/* fall out the bottom without finding a submitted form */
return(false);
}
echo '<p>';
echo 'Fill out and submit the following four forms. You may stop and restart at any time. ';
echo '</p>';
echo '<ul style="list-style:none;">';
echo '<li>Form 1: ';
if ( $value = isn_did_this_user_submit_form('NameOfFormGoesHere') ):
echo 'the beginning — <em>Complete</em>';
else:
echo '<a href="/slug-of-form-page-goes-here">the beginning</a>';
endif;
echo '</li>';
echo '</ul>';
