Page 1 of 1

Password protecting contact form

Posted: Tue Aug 18, 2009 3:50 pm
by d_cee
Hi guys

I'm wondering if it would be possible to password protect a second iteration of the contact form so that only registered users could access it. If that's not possible, alternatively would it be possible to password protect the form using .htpasswd/.htaccess with mod rewrite enabled.

If neither of the above, I'm open to ideas

thanks

d_cee

Re: Password protecting contact form

Posted: Tue Aug 18, 2009 3:58 pm
by yellowled
d_cee wrote:I'm wondering if it would be possible to password protect a second iteration of the contact form so that only registered users could access it.
Registered as in "registered users of a s9y blog"? That's actually pretty easy:

Code: Select all

{if $is_logged_in} ... {/if}
Of course, this can also be combined with {else} as usual, i.e. to emit some kind of "Sorry, no content for non-registered users here" text.

The contact form plugin can be installed multple times, so that's not an issue. The tricky thing is to find out which contact form is the one (assuming all or most of them will use the same .tpl file). You could check that using {$plugin_contactform_name} -- of course you'll need to know the value of that variable.

Code: Select all

{if $plugin_contactform_name == 'NAME_OF_CONTACT_FORM'}
  {if $is_logged_in}
    YOU_FORM_CODE_HERE
  {else}
    <p>Nothing to see here.</p>
  {/if}
{/if}
NAME_OF_CONTACT_FORM is the name of the second iteration of the contact form, so what's inside the inner {if} statement will only be emitted in that particular form, and only for users logged in. The "Nothing to see here." part is optional, of course.

YL

Re: Password protecting contact form

Posted: Tue Aug 18, 2009 5:52 pm
by d_cee
Thanks YL

I'll give it a whirl tomorrow and see if I can make it work

Dave

Re: Password protecting contact form

Posted: Wed Aug 19, 2009 11:47 am
by d_cee
Hi YL

Code: Select all

$plugin_contactform_name
returned 'Contact Form' no matter which iteration of the form I was using, however I was able to use

Code: Select all

{if $head_title == 'My other Form'}
which did the trick.

thanks again

Dave

Re: Password protecting contact form

Posted: Wed Aug 19, 2009 4:45 pm
by Don Chambers
I think what YL intended was {$plugin_contactform_pagetitle}, which should be equal to "URL shorthand name".

Re: Password protecting contact form

Posted: Wed Aug 19, 2009 5:45 pm
by d_cee
Thanks Don

that works too!

Dave