Password protecting contact form

Creating and modifying plugins.
Post Reply
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Password protecting contact form

Post 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
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Password protecting contact form

Post 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
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Re: Password protecting contact form

Post by d_cee »

Thanks YL

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

Dave
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Re: Password protecting contact form

Post 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
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Password protecting contact form

Post by Don Chambers »

I think what YL intended was {$plugin_contactform_pagetitle}, which should be equal to "URL shorthand name".
=Don=
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Re: Password protecting contact form

Post by d_cee »

Thanks Don

that works too!

Dave
Post Reply