Hi,
modifying the contactform using a dynamic template with the setting "custom" is very easy and convenient.
I now would like to add a hidden field with a counter (as ticket#) to the contactform and write the field to the mail. The counter should be increased after each submit of the form.
Is there a easy way to implement such funktion?
Greetings Konrad
need help with counter in plugin_contactform
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: need help with counter in plugin_contactform
Hi!
For someone that knows the s9y API that might be work of 1 or 2 hours tops, and actually this is a pretty simple and great task for anyone that wants to try using the s9y Event-API for the first time....
Regards,
Garvin
That depends on your reception of "easy". I would make use of the fact, that the contactform allows you to call the frontend_comment event hook (for spamblock integration, mostly). So I'd create an event plugin that simply listens on frontend_comments, emits the hidden input field and per each submit (event frontend_saveComment) increase a database-counter for one.Is there a easy way to implement such funktion?
For someone that knows the s9y API that might be work of 1 or 2 hours tops, and actually this is a pretty simple and great task for anyone that wants to try using the s9y Event-API for the first time....
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/
# 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/
Re: need help with counter in plugin_contactform
Garvin, thank you for your very fast answer!
Wouldn'd a plugin whitch is generally listening to the frontend_comment event hook, start every time the hook is called (also increase the counter during normal commenting too) and not only after calling from plugin_contactform?
I am wondering why are you suggesting a new plugin? I was thinking it would be "easier" to enhance the serendipity_event_contactform plugin to accept the new field? The only drawback I see, that it would be necessary to update the field right bevor the moment of sending, and not during page creation to ensure having an unique ID.
I imagine that I could try to change the plungin in this way, but since I don't know php very well I have no idea of how to read and write to a custom database field. Are there any examples in one of the plugins already?
Wouldn'd a plugin whitch is generally listening to the frontend_comment event hook, start every time the hook is called (also increase the counter during normal commenting too) and not only after calling from plugin_contactform?
I am wondering why are you suggesting a new plugin? I was thinking it would be "easier" to enhance the serendipity_event_contactform plugin to accept the new field? The only drawback I see, that it would be necessary to update the field right bevor the moment of sending, and not during page creation to ensure having an unique ID.
I imagine that I could try to change the plungin in this way, but since I don't know php very well I have no idea of how to read and write to a custom database field. Are there any examples in one of the plugins already?
Author von Dresden für Kinder
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: need help with counter in plugin_contactform
Hi!
Regards,
Garvin
Sure, the plugin would need to check for specific contactform variables, to make sure that it only fires up when a contactform is called. I think that should be doable through pagetitle or special contactform template variables.Wouldn'd a plugin whitch is generally listening to the frontend_comment event hook, start every time the hook is called (also increase the counter during normal commenting too) and not only after calling from plugin_contactform?
Its much easier to create a new small plugin for that, than to make the whole thing customizable with config options etc. And patching the contactform plugin should never be an option, as you can then no longer easily upgrade to new versions of the plugin.I am wondering why are you suggesting a new plugin? I was thinking it would be "easier" to enhance the serendipity_event_contactform plugin to accept the new field? The only drawback I see, that it would be necessary to update the field right bevor the moment of sending, and not during page creation to ensure having an unique ID.
That can be done easily within the plugin:I imagine that I could try to change the plungin in this way, but since I don't know php very well I have no idea of how to read and write to a custom database field. Are there any examples in one of the plugins already?
Code: Select all
$this->set_config('counter', $this->get_config('counter')+1);
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/
# 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/
Re: need help with counter in plugin_contactform
Do you even have an example for this?garvinhicking wrote: Sure, the plugin would need to check for specific contactform variables, to make sure that it only fires up when a contactform is called. I think that should be doable through pagetitle or special contactform template variables.
Sorry for asking again. I would like to try it by myself and learn it, but I feel like a pig looking into a watch.
Author von Dresden für Kinder
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: need help with counter in plugin_contactform
Hi!
Regards,
Garvin
Sadly not out of the top of my head, no. Maybe you could check to use $serendipity['smarty']->get_template_vars('commentform_action') - and then check if that variable contains anything. It should only be set, when the contactform is being executed.Do you even have an example for this?
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/
# 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/
Re: need help with counter in plugin_contactform
Garvin, thank you for your fast answer!
Sorry for bothering again with questions but I am a beginner and really would like to learn it by myself. I now need to solve the next problem. Garmin wrote
How could the plugin emit a input field witch would by send by mail afterwards? I found out, that serendipity_event_contactform calls the hook with
$commentInfo ['comment'] is filled with $comment and consists all the information which are send by mail afterwards. My idea was to modify $commentInfo to add the desired information. But after some testing, it looks like that serendipity_event_contactform does not use the returned value. The Mail is created with the original variable $comment instead.
So how could I add a field to the mail without changing the serendipity_event_contactform-plugin? Is there a way to change the value of $comment directly?
Sorry for bothering again with questions but I am a beginner and really would like to learn it by myself. I now need to solve the next problem. Garmin wrote
So I'd create an event plugin that simply listens on frontend_comments, emits the hidden input field and...
How could the plugin emit a input field witch would by send by mail afterwards? I found out, that serendipity_event_contactform calls the hook with
Code: Select all
serendipity_plugin_api::hook_event('frontend_saveComment', $ca, $commentInfo);So how could I add a field to the mail without changing the serendipity_event_contactform-plugin? Is there a way to change the value of $comment directly?
Author von Dresden für Kinder
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: need help with counter in plugin_contactform
Hi!
Hm, I see, it could be that you cannot modify $commentInfo because that variable is not passed by reference. You would need to use an "earlier" event hook to overwrite the contents of $serendipity['POST']['comment'] to append your variable that has been emitted using frontend_comment.
"frontend_config" is one of the earlist event hooks, you could try that. Use a check to see if $serendipity['POST']['yourhiddenfieldname'] is set.
So if you use frontend_comment with
you could use this on frontend_config:
HTH,
Garvin
Hm, I see, it could be that you cannot modify $commentInfo because that variable is not passed by reference. You would need to use an "earlier" event hook to overwrite the contents of $serendipity['POST']['comment'] to append your variable that has been emitted using frontend_comment.
"frontend_config" is one of the earlist event hooks, you could try that. Use a check to see if $serendipity['POST']['yourhiddenfieldname'] is set.
So if you use frontend_comment with
Code: Select all
echo '<input type="hidden" name="serendipity[contactcounter]" value="' . $this->get_Config('counter') . '" />';
Code: Select all
if (isset($serendipity['POST']['contactcounter'])) {
$serendipity['POST']['comment'] = 'Counter: ' . $serendipity['POST']['contactcounter'] . "\n" . $serendipity['POST']['comment'];
$this->set_config('counter', $this->get_Config('counter')+1);
}
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/
# 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/
Re: need help with counter in plugin_contactform
Sorry, I have two new problems:
1. setting $serendipity['POST']['comment'] as suggested does not help. Even $serendipity['POST']['comment'] = 'Blahblah' has no effect.
2. The suggested method also counted normal comments. To distict between normal comments and the contactform-comments I checked the page-title with
Within contactform-comments it works nice, but within article-comments it doesn't. After sending the article-comment (and calling the abouve if-statement) the resulting page is empty, no feedback.
I even tested $test = $serendipity['smarty']->get_template_vars('head_title') , but with no luck - empty page after article-comment sending.
1. setting $serendipity['POST']['comment'] as suggested does not help. Even $serendipity['POST']['comment'] = 'Blahblah' has no effect.
2. The suggested method also counted normal comments. To distict between normal comments and the contactform-comments I checked the page-title with
Code: Select all
if "my nice pagetitle" == $serendipity['smarty']->get_template_vars('head_title') )I even tested $test = $serendipity['smarty']->get_template_vars('head_title') , but with no luck - empty page after article-comment sending.
Author von Dresden für Kinder
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: need help with counter in plugin_contactform
Hi!
applies?
Regards,
Garvin
Did you try $GLOBALS['serendipity']['POST']['comment'] instead?konus wrote:Sorry, I have two new problems:
1. setting $serendipity['POST']['comment'] as suggested does not help. Even $serendipity['POST']['comment'] = 'Blahblah' has no effect.
Maybe instead only issue the hidden input field when2. The suggested method also counted normal comments. To distict between normal comments and the contactform-comments I checked the page-title withWithin contactform-comments it works nice, but within article-comments it doesn't. After sending the article-comment (and calling the abouve if-statement) the resulting page is empty, no feedback.Code: Select all
if "my nice pagetitle" == $serendipity['smarty']->get_template_vars('head_title') )
Code: Select all
if ($serendipity['smarty']->get_template_vars('commentform_action') != '') {
echo ...
}
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/
# 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/