Problems, need help? Have a tip or advice? Post it here.
12 posts Page 2 of 2
@KK, I am following the initial request by the topicstarter:
But I find that even if the "my_page_name" is empty, the "my_page_id" is still not empty.

We did not see the actual definitions of the fields in admin-panel – I assume the 'required' parameter is not set – that makes the fields potentially empty as quoted. Therefore a condition is a must, otherwise blank values will not allow an understandable debugging process for the orig.poster.
KK wrote: Please try using the following and let me know if this solves that issue


@KK Sir,

Yes I used the code you suggested and removed the k_page_name as suggested by @trendoman. I confirm that the my_page_id is blank. It only gets set when I submit a blank form (setting the last id as discussed earlier above).

the code is:
Code: Select all
<div class="col-12 col-md-4 mb-3">
   <div class="card shadow">
      <div class="card-body">
         <h5 class="card-title mb-3">
            Add Feed
         </h5>

         <cms:set submit_success="<cms:get_flash 'submit_success' />" />
          <cms:if submit_success >
              <div class="alert alert-success alert-dismissible fade show">
                 Record created.
                 <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
              </div>
          </cms:if>

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

              <cms:if k_success >
                 <cms:set my_template_name = "cattle-feed/index.php" />
                 my_template_name::<cms:show my_template_name /><br>
                  <cms:set my_page_title = "<cms:show frm_feed_name/> <cms:show frm_feed_weight/>" />
                  my_page_title::<cms:show my_page_title /><br>
                  <cms:php>
                  global $CTX, $FUNCS;
                  $name = $FUNCS->get_clean_url( "<cms:show my_page_title />" );
                  $CTX->set( 'my_page_name', $name );
               </cms:php>
               my_page_name::<cms:show my_page_name /><br>
               <cms:set my_page_id = '' 'global' />
               <cms:pages masterpage=my_template_name page_name="<cms:show my_page_name />" limit='1' show_future_entries='1'>
                  <cms:set my_page_id=k_page_id  'global' />
               </cms:pages>
               my_page_id::<cms:show my_page_id /><br>
               <cms:if my_page_id=''>
                     <cms:db_persist_form
                         _invalidate_cache='0'
                         _auto_title='0'
                         k_page_title = "<cms:show frm_feed_name /> <cms:show frm_feed_weight />"
                         k_page_name = "<cms:show k_page_title />"
                     />
                     <cms:if k_success>
                        <cms:set_flash name='submit_success' value='1' />
                        <cms:redirect k_page_link />
                    </cms:if>
                </cms:if>
              </cms:if>

              <cms:ignore>
              <cms:if k_error >
                  <div class="error">
                      <cms:each k_error >
                          <br><cms:show item />
                      </cms:each>
                  </div>
              </cms:if>
             </cms:ignore>
            
            <div class="form-floating mb-3">
               <cms:input type="bound" class="form-control" name="feed_name" id="feed_name" placeholder="feed_name" />
               <label for="feed_name">
                  Feed Name <span class="gxcpl-error">*</span>
               </label>
               <cms:if k_error_feed_name>
                  <span id="feed_name_error" class="gxcpl-error" style="display:block;">
                     <small>
                        <em>
                           Required
                        </em>
                     </small>
                  </span>
               </cms:if>
            </div>

            <div class="form-floating mb-3">
               <cms:hide>
                  <cms:input type="bound" name="feed_weight" id="feed_weight" />
               </cms:hide>
               <input type="number" class="form-control" name="f_feed_weight" id="f_feed_weight" placeholder="" value="<cms:show frm_feed_weight />" />
               <label for="f_feed_weight">
                  Feed Weight <span class="gxcpl-error">*</span>
               </label>
               <cms:if k_error_feed_name>
                  <span id="feed_name_error" class="gxcpl-error" style="display:block;">
                     <small>
                        <em>
                           Required
                        </em>
                     </small>
                  </span>
               </cms:if>
            </div>

            <button class="btn gxcpl-btn-blue-a700 gxcpl-button shadow" type="submit">
               <i class="fa fa-plus"></i> CREATE
            </button>

         </cms:form>
      </div>
   </div>
</div>


I didnot try putting the code into the k_success block.

(will take up raising error for duplicate pages later)

We could now look at this. When I submit the blank form I want to just show required message, as in the code above (in this message), rather than the actual errors set by k_error.
Actually there are two errors that need to be set:
1. when the form is submitted with empty fields, error message to display will be "Required".
2. when a duplicate page exists.

@trendoman:
As you mentioned, I am sharing the editable region code here. Hope it gives a fair idea.
Code: Select all
    <cms:editable name="feed_name" label="Feed" type="text" required="1" order="1" />
    <cms:editable name="feed_weight" label="Packaging Weight" type="text" validator="non_negative_integer" required="1" order="2" />


Regards,
GenXCoders
Image
where innovation meets technology
12 posts Page 2 of 2