adjusting the contactform-plugin

Creating and modifying plugins.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Where does that stuff above kontaktformular come from? Where did you enter it?

Best 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/
proberlin
Regular
Posts: 23
Joined: Wed Aug 02, 2006 8:59 pm
Location: Berlin, Germany

Post by proberlin »

i have no idea where it comes from, but it is first a list of all my static pages and then the main text from my startpage (one of the static pages).

but i never changed the contactform_plugin to show this stuff...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Does this text also show up when you view your contactform page? Or is it only shown on the next submit page?

It might be caused by the "startpage" behaviour of the plugin. In some cases it cannot detect that the target page is not a "startpage". You could try to add some variables to the POST target of your form so try to circumvent the startpage detection? Adding variables like "index.php?/bla.httml" or so might already prevent the startpage detection in the target of your contactform <form> tag...

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/
proberlin
Regular
Posts: 23
Joined: Wed Aug 02, 2006 8:59 pm
Location: Berlin, Germany

Post by proberlin »

hi garvin,

no, this text doesn't show up when i view the contactform-page.

here is my event_contactform.php:


<?php # $Id: serendipity_event_contactform.php,v 1.18 2006/06/08 18:14:59 garvinhicking Exp $

// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
include $probelang;
}

include dirname(__FILE__) . '/lang_en.inc.php';

class serendipity_event_contactform extends serendipity_event {
var $title = PLUGIN_CONTACTFORM_TITLE;
function introspect(&$propbag) {
global $serendipity;

$propbag->add('name', PLUGIN_CONTACTFORM_TITLE);
$propbag->add('description', PLUGIN_CONTACTFORM_TITLE_BLAHBLAH);
$propbag->add('event_hooks', array('entries_header' => true, 'entry_display' => true, 'genpage' => true));
$propbag->add('configuration', array('permalink', 'pagetitle', 'email', 'intro', 'sent', 'articleformat'));
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.7');
$propbag->add('requirements', array(
'serendipity' => '0.7',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('stackable', true);
$propbag->add('groups', array('FRONTEND_FEATURES'));
}

function introspect_config_item($name, &$propbag)
{
global $serendipity;

switch($name) {
case 'permalink':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_CONTACTFORM_PERMALINK);
$propbag->add('description', PLUGIN_CONTACTFORM_PERMALINK_BLAHBLAH);
$propbag->add('default', $serendipity['rewrite'] != 'none'
? $serendipity['serendipityHTTPPath'] . 'pages/contactform.html'
: $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/pages/contactform.html');
break;

case 'email':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_CONTACTFORM_EMAIL);
$propbag->add('description', '');
$propbag->add('default', '');
break;

case 'intro':
$propbag->add('type', 'html');
$propbag->add('name', PLUGIN_CONTACTFORM_INTRO);
$propbag->add('description', '');
$propbag->add('default', '');
break;

case 'sent':
$propbag->add('type', 'html');
$propbag->add('name', PLUGIN_CONTACTFORM_SENT);
$propbag->add('description', '');
$propbag->add('default', PLUGIN_CONTACTFORM_SENT_HTML);
break;

case 'pagetitle':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_CONTACTFORM_PAGETITLE);
$propbag->add('description', '');
$propbag->add('default', PLUGIN_CONTACTFORM_TITLE);
break;

case 'articleformat':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_CONTACTFORM_ARTICLEFORMAT);
$propbag->add('description', PLUGIN_CONTACTFORM_ARTICLEFORMAT_BLAHBLAH);
$propbag->add('default', 'true');
break;

default:
return false;
}
return true;
}

function sendComment($to, $fromName, $fromEmail, $comment) {
global $serendipity;

if (empty($fromName)) {
$fromName = ANONYMOUS;
}

$title = $this->get_config('pagetitle');

$subject = NEW_COMMENT_TO . ' ' . $title;
$text = sprintf(A_NEW_COMMENT_BLAHBLAH, $serendipity['blogTitle'], $title)
. "\n"
. "\n" . USER . ' ' . IP_ADDRESS . ': ' . $_SERVER['REMOTE_ADDR']
. "\n"
. "\n" . USER . ' ' . NAME . ': ' . $fromName
. "\n" . USER . ' Strasse: ' . $serendipity['POST']['strasse']
. "\n" . USER . ' PLZ: ' . $serendipity['POST']['plz']
. "\n" . USER . ' Ort: ' . $serendipity['POST']['ort']
. "\n" . USER . ' Tel.: ' . $serendipity['POST']['tel']
. "\n" . USER . ' Fax: ' . $serendipity['POST']['fax']
. "\n" . USER . ' ' . EMAIL . ': ' . $fromEmail
. "\n"
. "\n" . USER . ' Tiere: ' . $serendipity['POST']['tiere']
. "\n"
. "\n" . USER . ' Ferienhaus: ' . $serendipity['POST']['ferienhaus']
. "\n" . USER . ' Ferienwohnung: ' . $serendipity['POST']['ferienwohnung']
. "\n" . USER . ' Bungalow: ' . $serendipity['POST']['bungalow']
. "\n" . USER . ' Doppelzimmer: ' . $serendipity['POST']['doppelzimmer']
. "\n" . USER . ' Einzelzimmer: ' . $serendipity['POST']['einzelzimmer']
. "\n"
. "\n" . COMMENTS . ': '
. "\n" . $comment
. "\n"
. "\n" . '----';

return serendipity_sendMail($to, $subject, $text, $fromEmail, null, $fromName);
}

function checkSubmit() {
global $serendipity;

if (empty($serendipity['POST']['commentform'])) {
return false;
}

if (empty($serendipity['POST']['name']) || empty($serendipity['POST']['email'])) {
$serendipity['smarty']->assign(
array(
'is_contactform_error' => true,
'plugin_contactform_error' => PLUGIN_CONTACTFORM_ERROR_DATA
)
);

return false;
}

// Fake call to spamblock/captcha and other comment plugins.
$ca = array(
'id' => 0,
'allow_comments' => 'true',
'moderate_comments' => false,
'last_modified' => 1,
'timestamp' => 1
);

$commentInfo = array(
'type' => 'NORMAL',
'source' => 'commentform',
'name' => $serendipity['POST']['name'],
'url' => $serendipity['POST']['url'],
'comment' => $serendipity['POST']['comment'],
'email' => $serendipity['POST']['email']
);
serendipity_plugin_api::hook_event('frontend_saveComment', $ca, $commentInfo);

if ($ca['allow_comments'] === false) {
$serendipity['smarty']->assign(
array(
'is_contactform_error' => true,
'plugin_contactform_error' => PLUGIN_CONTACTFORM_ERROR_DATA
)
);

return false;
}
// End of fake call.

if ($this->sendComment(
$this->get_config('email'),
$serendipity['POST']['name'],
$serendipity['POST']['email'],
$serendipity['POST']['comment'])) {

$serendipity['smarty']->assign('is_contactform_sent', true);
return true;
} else {
// Unkown error occurred.
$serendipity['smarty']->assign(
array(
'is_contactform_error' => true,
'plugin_contactform_error' => PLUGIN_CONTACTFORM_ERROR_HTML
)
);
}

return false;
}

function show() {
global $serendipity;

if ($this->selected()) {
if (!headers_sent()) {
header('HTTP/1.0 200');
}

if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init();
}
$serendipity['smarty']->assign('staticpage_pagetitle', preg_replace('@[^a-z0-9]@i', '_',$this->get_config('pagetitle')));

$this->checkSubmit();

$serendipity['smarty']->assign(
array(
'plugin_contactform_articleformat' => $this->get_config('articleformat'),
'plugin_contactform_name' => PLUGIN_CONTACTFORM_TITLE,
'plugin_contactform_pagetitle' => $this->get_config('pagetitle'),

'plugin_contactform_preface' => $this->get_config('intro'),
'plugin_contactform_sent' => $this->get_config('sent', PLUGIN_CONTACTFORM_SENT_HTML),
'plugin_contactform_message' => PLUGIN_CONTACTFORM_MESSAGE,
'commentform_action' => $serendipity['baseURL'],
'commentform_sname' => $serendipity['GET']['subpage'],
'commentform_name' => htmlspecialchars(strip_tags($serendipity['POST']['name'])),
'commentform_email' => htmlspecialchars(strip_tags($serendipity['POST']['email'])),
'commentform_data' => htmlspecialchars(strip_tags($serendipity['POST']['comment'])),
'comments_messagestack' => $serendipity['messagestack']['comments'],
'commentform_entry' => array(
'timestamp' => 1, // force captchas!
)
)
);

$tfile = serendipity_getTemplateFile('plugin_contactform.tpl', 'serendipityPath');
if (!$tfile) {
$tfile = dirname(__FILE__) . '/plugin_contactform.tpl';
}
$inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
$serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
$content = $serendipity['smarty']->fetch('file:'. $tfile, null, null, false);
$serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion;

if ($this->get_config('markup') == TRUE) {
$entry = array('body' => $content);
serendipity_plugin_api::hook_event('frontend_display', $entry);
echo $entry['body'];
} else {
echo $content;
}
}
}

function selected() {
global $serendipity;

if (!empty($serendipity['POST']['subpage'])) {
$serendipity['GET']['subpage'] = $serendipity['POST']['subpage'];
}

if ($serendipity['GET']['subpage'] == $this->get_config('pagetitle') ||
preg_match('@^' . preg_quote($this->get_config('permalink')) . '@i', $serendipity['GET']['subpage'])) {
return true;
}

return false;
}

function generate_content(&$title) {
$title = PLUGIN_CONTACTFORM_TITLE.' (' . $this->get_config('pagetitle') . ')';
}

function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;

$hooks = &$bag->get('event_hooks');

if (isset($hooks[$event])) {
switch($event) {
case 'genpage':
$args = implode('/', serendipity_getUriArguments($eventData, true));
if ($serendipity['rewrite'] != 'none') {
$nice_url = $serendipity['serendipityHTTPPath'] . $args;
} else {
$nice_url = $serendipity['serendipityHTTPPath'] . '?/' . $args;
}

if (empty($serendipity['GET']['subpage'])) {
$serendipity['GET']['subpage'] = $nice_url;
}

if ($this->selected()) {
$serendipity['head_title'] = $this->get_config('pagetitle');
$serendipity['head_subtitle'] = $serendipity['blogTitle'];
}
break;

case 'entry_display':
if ($this->selected()) {
if (is_array($eventData)) {
$eventData['clean_page'] = true; // This is important to not display an entry list!
} else {
$eventData = array('clean_page' => true);
}
}

if (version_compare($serendipity['version'], '0.7.1', '<=')) {
$this->show();
}

return true;
break;

case 'entries_header':
$this->show();

return true;
break;

default:
return false;
break;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */


i am very sorry, but i was glad to insert these buttons and now i am a bit lost where to change something to prevent the weird page, that is shown if one clicks on "send" :(
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Okay, but I'm sorry that you would need some PHP knowledge to adapt this plugin. :)

Are you earning money with the page you are creating? If so, I could offer you to patch the plugin for you, when you in return make a donation to my Amazon wishlist. :)

If you are not earning money with your page (and you are not lying to me *g*) I can patch the plugin for free. Butin both cases you need to wait until after the weekend, because I'm gone now until monday. :-)

(Please also do not post so much code here, use services like http://nopaste.php-q.net/ for showing sourcecode :-) )

Best 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/
Post Reply