Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi All,

I have a form which sends Databound Form information to an email account, but if the user submits the form with no data they are getting a success message?! Really weird. I have pasted a modified version of my form script below, i would love to see if anyone can see something I've missed.

Code: Select all
<cms:if "<cms:get_flash 'submit_success' />" >
                        <div class="alert">
                          Success! Your application has been submitted.
                        </div>
                     </cms:if>

                     <cms:form
                        masterpage=k_template_name
                        mode='create'
                        enctype='multipart/form-data'
                        method='post'
                        anchor='0'
                        >

                        <cms:if k_success >

                           <cms:check_spam email=frm_email />

                           <cms:db_persist_form
                              _invalidate_cache='0'
                              _auto_title='1'
                           />
                           
                   
                         <cms:pages masterpage=k_template_name id=k_last_insert_id show_future_entries='1'>
               
                           
                        <cms:capture into='app_details' >

<!-- HTML Form Data to be emailed -->
                           
                           
                        </cms:capture>
                           
                        
                           
                        <!-- SEND MAIL BEFORE REDIRECTING -->
                        <cms:send_mail html="1" from="no-reply@example.com" to="email@example.com.au" subject="New Application Received - <cms:show frm_first_name /> <cms:show frm_last_name /> >
You have received a new application. <br />

                           <cms:show app_details />
                           
                        </cms:send_mail>
                           
                           </cms:pages>
                        

                        <cms:set_flash name='submit_success' value='1' />
                        <cms:redirect k_page_link />

                        </cms:if>

                        <cms:if k_error >
                           <div class="error">
                              <cms:each k_error >
                                 <br><cms:show item />
                              </cms:each>
                           </div>
                        </cms:if>




Any help would be greatly appreciated
OK! After a bit more testing we have now worked out that we are getting an empty email for every successful form submission / entry in the database.

So if the user submits an incomplete form and there is 5 entries in the backend d/base then we receive 5 empty email submissions, but the unsuccessful form is not being submitted to the backend and the errors are showing on the form.

Really weird.
OK! We worked it out. We were missing an additional <cms:if k_success >

before this line
Code: Select all
<cms:pages masterpage=k_template_name id=k_last_insert_id show_future_entries='1'>


and a closing </cms:if>

before this line
Code: Select all
<cms:if k_error >
                           <div class="error">
                              <cms:each k_error >
                                 <br><cms:show item />
                              </cms:each>
                           </div>
                        </cms:if>



Final Code looks like this

Code: Select all
<cms:if "<cms:get_flash 'submit_success' />" >
                        <div class="alert">
                          Success! Your application has been submitted.
                        </div>
                     </cms:if>

                     <cms:form
                        masterpage=k_template_name
                        mode='create'
                        enctype='multipart/form-data'
                        method='post'
                        anchor='0'
                        >

                        <cms:if k_success >

                           <cms:check_spam email=frm_email />

                           <cms:db_persist_form
                              _invalidate_cache='0'
                              _auto_title='1'
                           />
                           
                    <cms:if k_success >
                         <cms:pages masterpage=k_template_name id=k_last_insert_id show_future_entries='1'>
               
                           
                        <cms:capture into='app_details' >

<!-- HTML Form Data to be emailed -->
                           
                           
                        </cms:capture>
                           
                       
                           
                        <!-- SEND MAIL BEFORE REDIRECTING -->
                        <cms:send_mail html="1" from="no-reply@example.com" to="email@example.com.au" subject="New Application Received - <cms:show frm_first_name /> <cms:show frm_last_name /> >
You have received a new application. <br />

                           <cms:show app_details />
                           
                        </cms:send_mail>
                           
                           </cms:pages>
                       
                       <cms:if k_success >
                        <cms:set_flash name='submit_success' value='1' />
                        <cms:redirect k_page_link />

                        </cms:if>
                       </cms:if>
                      </cms:if>

                        <cms:if k_error >
                           <div class="error">
                              <cms:each k_error >
                                 <br><cms:show item />
                              </cms:each>
                           </div>
                        </cms:if>



Hope this helps someone, including viewtopic.php?f=4&t=8918
Hi,

I am glad you could work it out.
To make things a bit easier to understand for others, here is a bare bones version of a form showing why we need to check twice for k_success -
Code: Select all
<cms:form
    masterpage=k_template_name
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >

    <cms:if k_success >
        <!- this success indicates that the form was submitted without any errors -->
       
        <cms:db_persist_form
          _invalidate_cache='0'
          _auto_title='1'
        />
       
        <cms:if k_success >
            <!- this success indicates that the submitted data was saved into the database without any errors -->
            <!-- this is where action should be taken (like sending email etc.) -->
       
        </cms:if>

    </cms:if>
   
</cms:if>

Hope this helps.
4 posts Page 1 of 1