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

I've build a website with a single contact form that is included on 3 separate clonable pages.
The contact form has it's own template named contact.php.

After submitting the form the form returns to contact.php but I want it to redirect back to the last page: info.php?p=46.

Redirect seems to be the solution but I can't get it to work properly.
Any help is much appreciated.

Thanks.

Code: Select all
<cms:pages masterpage='contact.php'>
   <div class="contactform">
      <cms:form anchor='0' method="post">
         <cms:show_repeatable 'form' >
            <cms:php>
               global $FUNCS, $CTX;
               $name = $FUNCS->get_clean_url( $CTX->get('title') );
               $CTX->set( 'name', $name );
            </cms:php>
            <label for="<cms:show title />"><cms:show title /></label>
            <cms:input
               type="<cms:if type='email'>text<cms:else /><cms:show type /></cms:if>"
               name="<cms:show name/>"
               id="<cms:show name/>"
               required="<cms:show required />"
               validator="<cms:if type='email'>email</cms:if>"
               validator_msg="<cms:if text>required=<cms:show text /><cms:if type='email'> | email=<cms:show text /></cms:if></cms:if>"
               opt_values="<cms:show options />"
            />
            <cms:set my_error="<cms:get "k_error_<cms:show name/>" />" />
            <cms:if my_error>
               <h6 class="alert" id="<cms:show name/>_error" class="alert"><cms:show my_error /></h6>
            </cms:if>
         </cms:show_repeatable>
         <label class="required" for="human">* Anti-spam question:<br />The sky is: <strong>blue</strong> or red?</label>
         <cms:input type="text" required='1' validator='regex=/^blue$/i' class="input-text required-entry" id="human" name="human"/>
         <cms:if k_error_human>
            <h6 class="alert_human">Type "<strong>blue</strong>" as the answer.</h6>
         </cms:if>
         <button type="submit" value="Submit"/>Send</button>
         <cms:if k_success>
            <cms:send_mail from=k_email_from to=k_email_to bcc=frm_emailadres subject='Contactform website'>
               The email has been send from Contactform: <cms:show k_page_title /> :
               <cms:each k_success sep='\n'>
                  <cms:show item /><br>
               </cms:each>
            </cms:send_mail>
            <cms:redirect k_page_link />
         </cms:if>
      </cms:form>
   </div>
</cms:pages>
Hi :)
The problem is here
Code: Select all
<cms:pages masterpage='contact.php'>
..
<cms:redirect k_page_link /> 
..
</cms:pages>

k_page_link is a variable that get's its scope from contact.php template.
So, try setting your personal variable with k_page_link before you start showing this contact form. Then use this saved value in redirect. Do you need help to manage it?
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
Yes Trendoman, I could need some help with this.
Not sure if I need to set a cookie, use gpc or something else.

*EDIT
I've added the following code at the start of this code
Code: Select all
<cms:capture into='my_variable' scope='global'>
    <cms:show k_page_link />
</cms:capture>


and replaced
Code: Select all
<cms:redirect k_page_link />

with
Code: Select all
<cms:redirect my_variable />


Everything works now as intended.
Glad it helped.
Code: Select all
<cms:capture into='my_variable' scope='global'>
    <cms:show k_page_link />
</cms:capture>

This can be also done the other way
Code: Select all
<cms:set my_variable=k_page_link scope='global' />

:)
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
That's even better :D

I've also added a succes message. The user will see a message appear after sending a succesfull email. The solution can be used together with the info in this post http://www.couchcms.com/forum/viewtopic.php?f=8&t=7998

The working code now looks like this:
Code: Select all
<cms:set my_variable=k_page_link scope='global' />
<cms:pages masterpage='contact.php'>
   <div class="contactform">
      <cms:form anchor='0' method="post">
         <cms:show_repeatable 'form' >
            <cms:php>
               global $FUNCS, $CTX;
               $name = $FUNCS->get_clean_url( $CTX->get('title') );
               $CTX->set( 'name', $name );
            </cms:php>
            <label for="<cms:show title />"><cms:show title /></label>
            <cms:input
               type="<cms:if type='email'>text<cms:else /><cms:show type /></cms:if>"
               name="<cms:show name/>"
               id="<cms:show name/>"
               required="<cms:show required />"
               validator="<cms:if type='email'>email</cms:if>"
               validator_msg="<cms:if text>required=<cms:show text /><cms:if type='email'> | email=<cms:show text /></cms:if></cms:if>"
               opt_values="<cms:show options />"
            />
            <cms:set my_error="<cms:get "k_error_<cms:show name/>" />" />
            <cms:if my_error>
               <h6 class="alert" id="<cms:show name/>_error" class="alert"><cms:show my_error /></h6>
            </cms:if>
         </cms:show_repeatable>
         <label class="required" for="human">* Anti-spam question:<br />The sky is: <strong>blue</strong> or red?</label>
         <cms:input type="text" required='1' validator='regex=/^blue$/i' class="input-text required-entry" id="human" name="human"/>
         <cms:if k_error_human>
            <h6 class="alert_human">Type "<strong>blue</strong>" as the answer.</h6>
         </cms:if>
         <button type="submit" value="Submit"/>Send</button>
         <cms:if "<cms:get_flash 'submit_success' />" >
            <h6 class='succes' <cms:show email_message /></h6>
         </cms:if>
         <cms:if k_success>
            <cms:send_mail from=k_email_from to=k_email_to bcc=frm_emailadres subject='Contactform website'>
               The email has been send from Contactform: <cms:show k_page_title /> :
               <cms:each k_success sep='\n'>
                  <cms:show item /><br>
               </cms:each>
               </cms:send_mail>
               <cms:set_flash name='submit_success' value="1" />
               <cms:redirect my_variable /> 
         </cms:if>
      </cms:form>
   </div>
</cms:pages>
5 posts Page 1 of 1