Contact form inside a post / insert post title in form

Creating and modifying plugins.
Post Reply
Huhu
Regular
Posts: 157
Joined: Tue Oct 04, 2011 3:22 pm

Contact form inside a post / insert post title in form

Post by Huhu »

Hello,

I just wondered whether there might be a possibility to auto-include Custom Fields or post titles into a contact form.

Example:
Reader reads one post called "Chocolate". Then he uses a contact button at the end of the post, which pops up the contact form.
Now, in the contact form, "Chocolate" should automatically be included in one of the contact form fields (like, "subject:" or "Post referred to:" ). Same with custom fields.

Any ideas? Thanks!
Last edited by Huhu on Tue Oct 04, 2011 3:48 pm, edited 2 times in total.
Post-apocalyptic Jugger sports: What is Jugger? Video I Free ebook on the sport
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Contact form inside a post / insert post title in form

Post by garvinhicking »

Hi!

You could change your entries.tpl file to forward your custom field variable to the contactform, something like

Code: Select all

<form action="/pages/contactform.html" method="post">
<input type="hidden" name="serendipity[commentform]" value="1" />
<input type="hidden" name="serendipity[customfield]" value="{$entry.properties.myCustomField|@escape}" />
<input type="submit" value="Open contact form" />
</form>
Then you simply setup a field "customfield" in your contact form, and setup a Custom Field "myCustomField" (or of course, change your names accordingly). This should then carry on the variables to the contact form...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Huhu
Regular
Posts: 157
Joined: Tue Oct 04, 2011 3:22 pm

Re: Contact form inside a post / insert post title in form

Post by Huhu »

Wow - that was fast! Impressive, thank you very much. I will give this a try.
Post-apocalyptic Jugger sports: What is Jugger? Video I Free ebook on the sport
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Contact form inside a post / insert post title in form

Post by garvinhicking »

Hi!

Sure, have a go. If that does not work, I'm sure there are a few other ways to get this to work (with plugin coding required then, though).

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Huhu
Regular
Posts: 157
Joined: Tue Oct 04, 2011 3:22 pm

Re: Contact form inside a post / insert post title in form

Post by Huhu »

Hello,

step by step, I am sure I missed something there:

If I would like to get the string "ITEM" into the contact form, after "Item: ____", I would

... in plugin_contactform.tpl

Code: Select all

 <tr>
            <td class="serendipity_commentsLabel"><label for="serendipity_commentform_item">{$CONST.ITEM}</label></td>
            <td class="serendipity_commentsValue"><input type="text" id="serendipity_commentformitem" name="serendipity[item]" value="{$commentform_item}" /></td>
        </tr>
... in Seredipity administration --> EventPlugins --> Contactform (which generates a form field called "Item", where the automatic input should go to):

Code: Select all

Item;text:required;
... and in entries.tpl

Code: Select all

	<form action="/pages/contactform.html" method="post">
<input type="hidden" name="serendipity[commentform]" value="1" />
<input type="hidden" name="serendipity[Item]" value="{$entry.properties.ep_Item|@escape}" />
<input type="submit" value="Contact" />
</form>
So I am missing something essential, right?
Post-apocalyptic Jugger sports: What is Jugger? Video I Free ebook on the sport
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Contact form inside a post / insert post title in form

Post by garvinhicking »

Hi!

When you add the "Item" to the configuration, you should use the dynamic contactform template. You should not need to modify that template, since the dynamic contactform should automatically place the input for "Item" in the form.

Also, note that the variables are case sensitive, so you need to use serendipity[item] and not serendipity[Item].

To start with, first make sure that the entries.tpl patch properly works, adn that your <form> will contain the output of the custom field value. If that is there, we can proceed to the next step, and make sure that it is properly transported to the contactform, and shown there.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Huhu
Regular
Posts: 157
Joined: Tue Oct 04, 2011 3:22 pm

Re: Contact form inside a post / insert post title in form

Post by Huhu »

Hej,

good; I already suspected that changing the plugin_contactform.tpl would be obsolete. So I touch neither this one nor the dynamic tpl.

Case sensitive means if I type

Code: Select all

Item;text:require;
in the Plug-In config screen than I have to insert

Code: Select all

<input type="hidden" name="serendipity[Item]" value="{$entry.properties.ep_Item|@escape}" />
right?

When using the contact button on the post site, I get the error message "Ein benötigtes Feld wurde nicht ausgefüllt." (a field required has not been supplied), and the form is still empty. As if the

Code: Select all

<form>
wanted to post the form right away, without supplying the custom field.

Same if I replace

Code: Select all

value="{$entry.properties.ep_Item|@escape}" 
with

Code: Select all

value="{$entry.title|@escape}"
(thus not using a custom field but just the title of the entry).


One thing: Could it be that the permalink might cause the trouble? I have to link ist to
/s9y/index.php?/pages/contact.html
instead of
/s9y/pages/contact.html

(last option hands out a 404).
Post-apocalyptic Jugger sports: What is Jugger? Video I Free ebook on the sport
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Contact form inside a post / insert post title in form

Post by garvinhicking »

Hi!

First things first. Does it properly work to populate your <form>? We'll continue from there.

If you're not using URL rewriting, yes, you need to post to s9y/index.php?/pages/contact.html.

It might be that we need to use name="serendipity[contactform][Item]" instead. If you view the HTML source of your actual contact form, you should see how s9y structures those input names; this is what you need to emulate.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Huhu
Regular
Posts: 157
Joined: Tue Oct 04, 2011 3:22 pm

Re: Contact form inside a post / insert post title in form

Post by Huhu »

Perfect! It works now!

Thanks so much. I think I will look up your wish list at amazon soon :)
Post-apocalyptic Jugger sports: What is Jugger? Video I Free ebook on the sport
Post Reply