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

I am trying to modify the code for 1 template in particular (clonable pages), that would send an email to some persons, depending on who's selected in that page (a region with a list of different email addresses), when being created the first time.

It's a proposal system, and there's a list of different workers available.
If I create a proposal, and that in the "Workers" region I have checked "John Doe" and "Marc Doe", then click "SAVE" to create the entry, I would like to send an email to these 2, saying "Your name has been added on a proposal sent to "X" client. We will update you on the status of this proposal and will send you more details if the client selects you for the job"

So I thought of using a custom admin theme, and editing the "content_form.html" page (of course, duplicating it and changed the name to "content_form_proposal-php.html" so that if affects only the Proposal.php page).

I'm not sure though how to change the behavior of the "SAVE" button, to add more actions to it than just saving the entry.
It is important that it does not send an email every single time I click SAVE too.

Any idea how to approach this?
Thanks a lot!
Hi,

You are on the right tack.
In the overridden content_form template, locate the following code -
Code: Select all
<cms:if k_success >
    <cms:if k_redirect_link >
        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_redirect_link />
    </cms:if>
</cms:if>

You may put your custom code just above the <cms:if k_redirect_link > statement so that it executes immediately before the page refreshes after getting saved-
Code: Select all
<cms:if k_success >
   
    ... put your code here...
   
    <cms:if k_redirect_link >
        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_redirect_link />
    </cms:if>
</cms:if>

Regarding the requirement that the code needs to execute only when a new page is being saved, you can put in the following check -
Code: Select all
<cms:if k_success >
   
    <cms:if k_page_id='-1'>
        ... put your code here...
    </cms:if>
   
    <cms:if k_redirect_link >
        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_redirect_link />
    </cms:if>
</cms:if>

Hope this helps.
Thanks KK,
Works great. But the thing is that I need to put some variables in the email that needs to be sent when creating a new entry.

Here's my example code:

Code: Select all
<cms:if k_success >
            <cms:if k_page_id='-1'>
        <cms:send_mail from='admin@mysite.com' to="info@test.ca" debug="1">
        Hello! <cms:show k_page_title/>
</cms:send_mail>

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


When I click "SAVE", it sends the email, but it seems like it can't find the value of the "k_page_title" variable.
Probably because it sends the email without sending the data to the database first.

Any way I can include variables inside of that email when creating a new entry?
Thanks!
Probably because it sends the email without sending the data to the database first.

Actually that data has been send to the database (that is what <cms:db_persist_form> does) - problem is that the variables have not been refreshed with values from the newly created page (we are refreshing the page so there is no need for this).

The <cms:db_persist_form>, however, does make available the 'id' of the page it just created as a variable named 'k_last_insert_id'. We can use this id to explicitly fetch the page and then we have full access to all the variables.

Please try the following -
Code: Select all
<cms:if k_success >
    <cms:if k_page_id='-1'>
        <cms:pages id=k_last_insert_id limit='1' show_future_entries='1'>
            .. all variables of the newly inserted page available here..
        </cms:pages>
    </cms:if>
   
    <cms:if k_redirect_link >
        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_redirect_link />
    </cms:if>
</cms:if>

You may place the email sending code at the spot marked above (within the <cms:pages> block).

Hope this helps.
Thanks KK!

Working perfectly :)
5 posts Page 1 of 1
cron