Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi KK,
I made with couch a link exchange form, which check existing reciprocal for each submitted link.

I got one problem, though: I need to check if the website link submitted already exist in the database before adding it. I tried many solution, but can't make it work. If you can help, I would really appreciate it, I'm sure there's a simple solution, but I can't put my finger on it.

The template is link.php, the variable to check is weburl. I got:

<cms:if k_success >

<cms:set my_var=weburl />
<cms:set goturl='0' />
<cms:pages masterpage='link.php'>
<cms:if my_var==weburl><cms:set goturl='1' /></cms:if>
</cms:pages>

<cms:if goturl=='0' >
<cms:check_spam email=frm_email />

<cms:db_persist_form
_invalidate_cache='0'
_auto_title='1'
/>

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

</cms:if>

It should work, I don't understand why it doesn't...
Thanks
Hi Paolo,

I think the problem is that the following code -
<cms:pages masterpage='link.php'>
<cms:if my_var==weburl><cms:set goturl='1' /></cms:if>
</cms:pages>

- should have been as follows
<cms:pages masterpage='link.php'>
<cms:if my_var==weburl><cms:set goturl='1' scope='global' /></cms:if>
</cms:pages>

Without the global scope, the 'goturl' variable gets set to '1' only within the enclosing cms:pages block. Once outside, the outer value of 0 is always found.

That said, instead of looping through all the pages to find the duplicate link, it'd be much more effective to use the 'custom_field' parameter of cms:pages tag to do the heavy lifting.
For example the following code will loop only once if the url exists -
Code: Select all
<cms:pages masterpage='link.php' custom_field="weburl==<cms:show my_var />">
    <cms:set goturl='1' scope='global' />
</cms:pages>

Hope this helps.
still doesn't work.

Ok, it's not very important anyway.
Thanks for trying.
That's fine if it is not important.
Nevertheless it should work.

You should try and debug it by removing all variables and testing with known values.
For example, assuming 'weburl' is an editable region in link.php and one page of it contains the value 'http://www.somesite.com/', place the following code in your template (outside the form)
Code: Select all
<cms:set my_var='http://www.somesite.com/' />

<cms:pages masterpage='link.php' custom_field="weburl==<cms:show my_var />">
    <h2>Page found: <cms:show k_page_title /><h2>
    <cms:set goturl='1' scope='global' />
</cms:pages>
     
<cms:if goturl >
    <h3>Page found</h3>
<cms:else />
    <h3>Page not found</h3>
</cms:if>

It should display the name of the page found. If not we can dig further as we only have a finite bit of code to debug.

With this version going you can make incremental changes to make it work with the form.
4 posts Page 1 of 1