Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
My client's site has two locations. On each location page I have a contact form that gets emailed to the appropriate location. This form is embedded throughout the site and the first step is to select which location. On the actual location page I want to automatically select the location in the form and not quite sure how to detect the page and apply selected with the code below:

Code: Select all
<select name="department" class="department"  >
         <option value="">Choose Location</option>
        <cms:pages masterpage='location.php'>
         <option value="<cms:show k_page_title />" <cms:if k_is_page>selected</cms:if>>
                <cms:show k_page_title />
            </option>
        </cms:pages>
       </select>
Let's pave the right way as follows:
Code: Select all
<select name="department" class="department"  >
   <option value="">Choose Location</option>
   <option value="Location 1 (page-id #001)" >Location 1</option>
   <option value="Location 2 (page-id #002)" >Location 2</option>
</select>


With above simplification let's assume that location.php template has these 2 pages, and the embedded form is viewed on page_view of each of these locations. it is getting clear that a simple conditional can be employed to find currently-viewed page to be marked as selected. Rewritten piece can look like this:
Code: Select all
<cms:set current_page_id = k_page_id scope='global' /> - remember viewed page 

<cms:pages masterpage='location.php' skip_custom_fields='1' >
      <cms:if k_paginated_top >
      <select name="department" class="department">
            <option value="-">Choose Location</option>
      </cms:if>
     
      <cms:set selected =
             "<cms:if current_page_id eq k_page_id >selected<cms:else /></cms:if>"   scope='global' />
     
      <option value="<cms:show k_page_id />" <cms:show selected /> ><cms:show k_page_title /></option>
       
      <cms:if k_paginated_bottom ></select></cms:if>
</cms:pages>


It's an option though to try luck with cms:input.
Code: Select all
<cms:set locations = 
        "
          <cms:pages masterpage='location.php' >
                 <cms:if k_paginated_top >Select location = none | </cms:if>
                 <cms:show k_page_title /> = <cms:show email />
                 <cms:if k_paginated_bottom='0' >|</cms:if>
           </cms:pages>
         " scope='global' />

<cms:input
        name='location'
        type='dropdown'
        class="department"
        opt_values=locations
        opt_selected=email />

The idea behind the above code is that each page has unique editable email in backend (if not - then unique page_id) which will become a selected dynamic option, depending on current visited page. Sending email would be trivial, as after submitting form the email will be available as frm_location variable.

As long as the form is embedded into multitude of pages on website (footer or header seemingly?), then variable email will match only for one of the 'location' pages (from opt_values). For the rest of the website dropdown will ask for users's input instead.

Hope it helps.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Thank you so much trendoman!
3 posts Page 1 of 1