Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Let me start with the code, then I'll explain the issues:

EDIT: Code removed after I realized a huge error in it. Problem still isn't fixed, but it's better than it was.

1) If I attempt to create a book club, it allows me to do so. Then it doesn't actually create said club in the system.

2) If I attempt to edit a book club, I get an error that a page_id is required. I think I'm providing one, but given how convoluted the form is, I have no idea at this point.

Thanks for any help.
Sam
After realizing that nested forms were a huge part of the issue, I recoded the page: I'm still not getting cloned pages generating from the form:

Code: Select all
<?php require_once ( '../couch/cms.php' ); ?>
<cms:if k_logged_in >
<!DOCTYPE HTML>
<html>
   <head>
      <cms:embed 'header.html' />
   </head>
   <body>
      <div class="container-fluid">
         <cms:embed 'staff_menu.html' />
         <div class='row'>
            <div class='col-md-3'>
               <div class='panel panel-default' >
                  <div class='panel-heading' >
                     <h2>A Moment of Zen</h2>
                  </div>
                  <div class='panel-body' >
                     <script>
                        showQuotation();
                     </script>
                  </div>
               </div>
            </div>
            <div class='col-md-9'>
               <div class='panel panel-default'>
                  <div class='panel-heading'>
                     <h2>Book Club Worksheet</h2>
                     <cms:set edit_club_success="<cms:get_flash 'edit_club_success' />" />
                     <cms:set create_club_success="<cms:get_flash 'create_club_success' />" />
                     <cms:set option_select="<cms:get_flash 'option_select' />" />
                     <cms:set active_edit="<cms:get_flash 'active_edit' />" />
                     <cms:set active_club="<cms:get_flash 'active_club' />" />
                     
                     <cms:if edit_club_success >
                        <h4>Your edit was successful.</h4>
                     <cms:else_if create_club_success />
                        <h4>You created a new book club!</h4>
                     </cms:if>
         
                     <cms:form name='task_selector' enctype='multipart/form-data' method='post' anchor='1'>
                        <label>Would you like to create a new book club or edit an existing book club?</label>
                           <cms:input type='radio' name='work_option' opt_values='Create | Edit ' />
                        <p/>
                        
                        <button type='submit' class='btn btn-default'>Submit</button>
                        <p/>
                     
                        <cms:if k_success>
                           <cms:if frm_work_option='Edit' >
                              <cms:set_flash name='option_select' value='2' />
                           <cms:else />
                              <cms:set_flash name='option_select' value='1' />
                           </cms:if>
                           
                           <cms:redirect k_page_link />
                        
                        </cms:if>
                     </cms:form>
                     
                     
                     <cms:if option_select='1' >
                        <cms:form
                           name='club_creator'
                           masterpage='book_clubs.php'
                           mode='create'
                           enctype="multipart/form-data"
                           method='post'
                           anchor='0'
                        >
                           <cms:if k_success>
                              <cms:db_persist_form
                                 _invalidate_cache = '0'
                                 _auto_title='1'
                              />
                                    
                              
                                 <cms:set_flash name='create_club_success' value='1' />
                                 <cms:redirect k_page_link />
                           
                           <cms:else_if k_error />
                              <div class="error">
                                 <cms:each k_error >
                                    <br><cms:show item />
                                 </cms:each>
                              </div>
                                             
                           </cms:if>
                                 
                           <label>Book Club Name</label>
                              <cms:input name='book_club_name' type='bound' />
                           <p/>
                                 
                           <label>Book Club Contact</label>
                              <cms:input name='book_club_contact' type='bound' />
                           <p/>
                                 
                           <label>Book Club Contact Phone</label>
                              <cms:input name='book_club_contact_phone' type='bound' />
                           <p/>
                                 
                           <label>Currently Reading:</label>
                              <cms:input name='next_title' type='bound' />
                           <p/>
                                 
                           <label>Next Meeting:</label>
                              <cms:input name='next_meeting' type='bound' />
                           <p/>
                                 
                           <label>Hosting Branch:</label>
                              <cms:input name='branch_location' type='bound' />
                           <p/>
                                 
                           <button type='submit' class='btn btn-default' />Create Book Club</button>
                                 
                        </cms:form>
                     <cms:else_if option_select='2' />   
                        <cms:if active_edit>
                           <cms:form
                              name='club_editor'
                              masterpage='book_clubs.php'
                              mode='edit'
                              page_id=active_club
                              enctype="multipart/form-data"
                              method='post'
                              anchor='0'
                           >
                                    
                              <cms:if k_success >
                                 <cms:db_persist_form />

                                 <cms:if k_success >
                                    <cms:set_flash name='edit_club_success' value='1' />
                                    <cms:redirect k_page_link />
                                 </cms:if>
                              </cms:if>
                                       
                              <label>Next Book</label>
                                 <cms:input name='next_title' type='bound' />
                              </p>
                                       
                              <label>Next Meeting Date</label>
                                 <cms:input name='next_meeting' type='bound' />
                              <p/>
                                       
                              <p>If any other information needs to be updated, please submit it to the <a href="<cms:cloak_email 'slink@columbiacountyga.gov' />">systems librarian</a> for addition</p>
                                       
                              <button type='submit' class='btn btn-default'>Complete Edits</button>
                                       
                           </cms:form>
                        <cms:else />
                           <cms:form name='club_selector' enctype='multipart/form-data' method='post'>
                              <label>Choose the club to edit: </label>
                                 <cms:input type='dropdown' name='edit_this_club' opt_values="<cms:pages masterpage='book_clubs.php' ><cms:if k_current_record=k_total_records ><cms:concat book_club_name '=' k_page_id /><cms:else /><cms:concat book_club_name '=' k_page_id ' | ' /></cms:if></cms:pages>" />
                              <p/>
                                 
                              <button type='submit' class='btn btn-default'>Select Club</button>
                                 
                              <cms:if k_success>
                           
                                 <cms:set_flash name='active_edit' value='1' />
                                 <cms:set_flash name='active_club' value=frm_edit_this_club />
                                  <cms:redirect k_page_link />
                              </cms:if>
                           </cms:form>                        
                           
                        </cms:if>
                     </cms:if>                           
                  </div>
               </div>
            </div>   
         </div>   
      </div>
   <cms:embed 'footer.html' />   
   </body>
</html>
<cms:else />

   <cms:redirect k_site_link />
   
</cms:if>
<?php COUCH::invoke(); ?>
And after some more prodding, I've found the problem, but I don't know how to fix it:

The first form that appears (task_selector) works properly with the set_flash, etc - no subsequent forms are successfully submitting or setting the flash properties.

I'm not sure what the next step would be.
Hi Slink,

Your issue seams to be with the form side. The Masterpage isn't looking in the correct place. So you need to list where that folder is so if its within the members then masterpage='members/book_clubs.php' or what folder book_club.php is within.

Let me know how you get on

Code: Select all
  <cms:if option_select='1' >
                        <cms:form
                           name='club_creator'
                           masterpage='book_clubs.php'
                           mode='create'
                           enctype="multipart/form-data"
                           method='post'
                           anchor='0'
                        >
The masterpage for the forms is in the root, and it's being called correctly. The nested <cms:page> call in the club_selector is working.

Going through step by step:

When I load the page, I get the initial task_selector form. A <cms:dump /> shows everything in order.

After submitting task_selector, I get the appropriate second form - either the club_selector or club_creator. <cms:dump /> shows all the variables being set correctly.

When I hit submit on either club_selector or club_creator, it kicks me back to the initial task_selector - which is correct for the club_creator, but the club_selector should take me on to the edit form. Moreover, a <cms:dump /> shows that none of the set_flash variables that should be set are actually set, which indicates that there's a k_error. If I run to check for k_error, there isn't one.

It's a mystery.
@slink

Curiously, you are using 'flash_variables' to select one of three forms present on the same page.
Please recall that a flash_variable is available for only a single page refresh.

So, suppose you select 'create', set this selection in flash and redirect, the refresh shows the 'create' form as expected.
Now you try to create a page by submitting this form. The page refreshes but the flash variable denoting 'create' is now gone - so we don't land back on the form we submitted.
Hope can see what was happening. Same thing happens for 'edit' too (hence the error about missing page_id)

Now while I have my reservations on using such convoluted code, since I have been presented with a problem, I'll just post the solution.

In the various forms, we need to set the relevant flash variables again so that upon submitting the forms we get back to from where we started.

Following is what was working for me (I'm using only a single bound field 'k_page_title' because my test template did not have all the regions defined in your template - but I'm sure that won't be a problem for you).
Code: Select all
<cms:if k_logged_in >
<cms:set_flash name='active_edit' value='0' />
<!DOCTYPE HTML>
<html>
   <head>
      <cms:embed 'header.html' />
   </head>
   <body>
      <div class="container-fluid">
         <cms:embed 'staff_menu.html' />
         <div class='row'>
            <div class='col-md-3'>
               <div class='panel panel-default' >
                  <div class='panel-heading' >
                     <h2>A Moment of Zen</h2>
                  </div>
                  <div class='panel-body' >
                     <script>
                        showQuotation();
                     </script>
                  </div>
               </div>
            </div>
            <div class='col-md-9'>
               <div class='panel panel-default'>
                  <div class='panel-heading'>
                     <h2>Book Club Worksheet</h2>
                     <cms:set edit_club_success="<cms:get_flash 'edit_club_success' />" />
                     <cms:set create_club_success="<cms:get_flash 'create_club_success' />" />
                     <cms:set option_select="<cms:get_flash 'option_select' />" />
                     <cms:set active_edit="<cms:get_flash 'active_edit' />" />
                     <cms:set active_club="<cms:get_flash 'active_club' />" />
                     
                     <cms:if edit_club_success >
                        <h4>Your edit was successful.</h4>
                     <cms:else_if create_club_success />
                        <h4>You created a new book club!</h4>
                     </cms:if>
         
                     <cms:form name='task_selector' enctype='multipart/form-data' method='post' anchor='1'>
                        <label>Would you like to create a new book club or edit an existing book club?</label>
                           <cms:input type='radio' name='work_option' opt_values='Create | Edit ' />
                        <p/>
                       
                        <button type='submit' class='btn btn-default'>Submit</button>
                        <p/>
                     
                        <cms:if k_success>
                           <cms:if frm_work_option='Edit' >
                              <cms:set_flash name='option_select' value='2' />
                           <cms:else />
                              <cms:set_flash name='option_select' value='1' />
                           </cms:if>
                           
                           <cms:redirect k_page_link />
                       
                        </cms:if>
                     </cms:form>
                     
                     
                     <cms:if option_select='1' >
                        <cms:set_flash name='option_select' value='1' /> 
                       
                        <cms:form
                           name='club_creator'
                           masterpage='book_clubs.php'
                           mode='create'
                           enctype="multipart/form-data"
                           method='post'
                           anchor='0'
                        >
                           <cms:if k_success>
                              <cms:db_persist_form
                                 _invalidate_cache = '0'
                                 _auto_title='1'
                              />
                                   
                             
                                 
                                 <cms:set_flash name='create_club_success' value='1' />
                                 <cms:redirect k_page_link />
                                 
                           
                           <cms:else_if k_error />
                              <div class="error">
                                 <cms:each k_error >
                                    <br><cms:show item />
                                 </cms:each>
                              </div>
                                             
                           </cms:if>
                                 

                                 
                           <label>Hosting Branch:</label>
                              <cms:input name='k_page_title' type='bound' />
                           <p/>
                                 
                           <button type='submit' class='btn btn-default' />Create Book Club</button>
                                 
                        </cms:form>
                     <cms:else_if option_select='2' />   
                        <cms:set_flash name='option_select' value='2' />
                       
                        <cms:if active_edit>
                           <cms:set_flash name='active_edit' value='1' />
                           <cms:set_flash name='active_club' value=active_club />
                           
                           <cms:form
                              name='club_editor'
                              masterpage='book_clubs.php'
                              mode='edit'
                              page_id=active_club
                              enctype="multipart/form-data"
                              method='post'
                              anchor='0'
                           >
                                   
                              <cms:if k_success >
                                 <cms:db_persist_form />

                                 <cms:if k_success >
                                    <cms:set_flash name='edit_club_success' value='1' />
                                    <cms:redirect k_page_link />
                                 </cms:if>
                              </cms:if>
                                       
                              <label>Next Book</label>
                                 <cms:input name='k_page_title' type='bound' />
                              </p>
                                       
                              <p>If any other information needs to be updated, please submit it to the <a href="<cms:cloak_email 'slink@columbiacountyga.gov' />">systems librarian</a> for addition</p>
                                       
                              <button type='submit' class='btn btn-default'>Complete Edits</button>
                                       
                           </cms:form>
                        <cms:else />
                           <cms:form name='club_selector' enctype='multipart/form-data' method='post'>
                              <label>Choose the club to edit: </label>
                                 <cms:input type='dropdown' name='edit_this_club' opt_values="<cms:pages masterpage='book_clubs.php' ><cms:if k_current_record=k_total_records ><cms:concat k_page_title '=' k_page_id /><cms:else /><cms:concat k_page_title '=' k_page_id ' | ' /></cms:if></cms:pages>" />
                              <p/>
                                 
                              <button type='submit' class='btn btn-default'>Select Club</button>
                                 
                              <cms:if k_success>
                           
                                 <cms:set_flash name='active_edit' value='1' />
                                 <cms:set_flash name='active_club' value=frm_edit_this_club />
                                  <cms:redirect k_page_link />
                              </cms:if>
                           </cms:form>                       
                           
                        </cms:if>
                     </cms:if>                           
                  </div>
               </div>
            </div>   
         </div>   
      </div>
   <cms:embed 'footer.html' />   
   </body>
</html>
<cms:else />

   <cms:redirect k_site_link />
   
</cms:if>

Hope this helps.
Thanks, KK. I'm also not thrilled with how convoluted the code is (which was part of the issue I was having - I knew I had all the right set_flash variables, I just wasn't sure they were in the right place), but it does what it's supposed to, now.
@KK

I took your concern under advisement and simplified the solution by splitting the create and edit functions across two pages; I think it's also more user-friendly.
8 posts Page 1 of 1