adjusting the contactform-plugin

Creating and modifying plugins.
proberlin
Regular
Posts: 23
Joined: Wed Aug 02, 2006 8:59 pm
Location: Berlin, Germany

adjusting the contactform-plugin

Post by proberlin »

hi,

i am testing serendipity for a few weeks now and i want to use it as a small cms, which seems to work very well. so first of all thanks to all the developers for their amazing work!

the website i am building is for a friend, who has a small german travel-agency. i am using serendipity 1.0 with the contactform-plugin -> v 1.18 . this works very well. but now i would like to adust this form and i am - sadly - no php-freak, so i am a little bit lost.

i know that i "simply" have to modify:
serendipity_event_contactform.php

and i think also:
plugin_contactform.tpl

what i would like to have there is text-fields for:

Vorname:
Name:
Straße:
Postleitzahl:
Ort:
Telefon:
Telefax:
E-Mail:

Datum Ankunft:
Datum Abreise:
Anzahl Erwachsene:
Anzahl Kinder:

//and then a radio-button for:
Haustiere: "ja" / "nein"

Unterkunftsart:
//here now one radio-button for each text, with the possibilty to mark all buttons

- Ferienhaus
- Ferienwohnung
- Bungalow
- Doppelzimmer
- Einzelzimmer

Nachricht:
//here another long textfield

//and at the end of the form three buttons:

"Abbrechen" [link to index.php]
"Zurücksetzen" [Should reset the form]
"Senden" [should send the filled out form]


i know i can't expect that somebody writes this concrete stuff, but perhaps somebody can tell me in general, how to:

- insert more text-fields
- insert a yes/no-radio-button
- insert several radio-buttons, which you can mark all
- insert the two additional buttons at the end (cancel -> link to index.php/reset)

i would appreciate it a lot, if somebody would help me ;-)

peter
Harald Weingaertner
Regular
Posts: 474
Joined: Mon Mar 27, 2006 12:32 am

Post by Harald Weingaertner »

Have you tried to use the Plugin "Static Pages" for this kind of page? I'm not sure, if you can handle a form inside a static page, but i thing editing the plugin_contactform.tpl isn't the best way.
proberlin
Regular
Posts: 23
Joined: Wed Aug 02, 2006 8:59 pm
Location: Berlin, Germany

Post by proberlin »

hi harald,

yes, i am using the staticpage-plugin. so i can see the contact form under "static pages" and change it's position in the menu etc. but isn't the

serendipity_event_contactform.php

the file where i have to change the code?
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

As long as you only want the new fields in the email, it's not too tough. Here's Garvin's solution from an earlier post.

Of course, for the radio buttons, you use input type="radio" instead of text. You'll need new IDs for each field you want to add.

If you want to store the data in the database, it's going to be much more difficult. But for the email, this should get the job done.
Judebert
---
Website | Wishlist | PayPal
proberlin
Regular
Posts: 23
Joined: Wed Aug 02, 2006 8:59 pm
Location: Berlin, Germany

Post by proberlin »

hi judebert,

thanks a lot for your help. i only want the data in the email, so i'll try the suggested way...
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Great! We'll be here if you have any other questions.
Judebert
---
Website | Wishlist | PayPal
proberlin
Regular
Posts: 23
Joined: Wed Aug 02, 2006 8:59 pm
Location: Berlin, Germany

radio buttons in contactform plugin

Post by proberlin »

thanks to judebert it could insert radio buttons in my contactform by changing the plugin_contactform.tpl to:

<tr>
<td class="serendipity_commentsLabel"><label>Bungalow</label></td>
<td class="serendipity_commentsValue">Ja <input type="radio" id="serendipity_commentform_bungalow_yes" name="serendipity[bungalow]"

value="YES" {$commentform_bungalow_yes_checked}/></td>
<td class="serendipity_commentsValue">Nein <input type="radio" id="serendipity_commentform_bungalow_no" name="serendipity[bungalow]"

value="NO" {$commentform_bungalow_no_checked}/></td>
</tr>

and inserting the following into the serendipity_contactform.php:

. "\n" . USER . ' Bungalow: ' . $serendipity['POST']['bungalow']

this works very well. but now i have a "cosmetic" problem: the buttons for "yes" and "no" are in one line in the form (which is good), but the "yes" button is on the far left and the "no" button is on the far right.

what i would like to have is: both buttons next to each other, but on the left side, on the imaginary vertical line, where the text-fields begin (so no big distance in between the two buttons).

i guess i have to change the style.css, but what do i insert there?

would be great, if somebody could help.
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Post by d_cee »

Hi

If you could post a url I'll take a look and see

Dave
proberlin
Regular
Posts: 23
Joined: Wed Aug 02, 2006 8:59 pm
Location: Berlin, Germany

Post by proberlin »

hi dave,

i made a screenshot and marked, how i want it to look like:

Image

i also have the problem, that when you klick on "send", the index.php opens and you can read the "feedback-sentence" (->"thanks for your message. it has been sent") only at the textend of the index.php.

can i adjust it, so that a page is displayed, where only the "feedback-sentence" is displayed (of course with the menu on the left/right side etc.) ? i tried several templates, but it was the same with all of them...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

This layout is controlled by your stylesheet's definition of "input" fields. Presumably they have a fixed width, so you need to edit your CSS or make some new classes so that the fixed width is not used for your radio input fields.
can i adjust it, so that a page is displayed, where only the "feedback-sentence" is displayed (of course with the menu on the left/right side etc.) ? i tried several templates, but it was the same with all of them...
You should be able to do this with some smarty {if} checks in the template of the contactform?

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 »

hi garvin,

thanks for your help. i found the following in my tpl-file:

{if $is_contactform_sent}
<div class="serendipity_center serendipity_msg_notice">
{$plugin_contactform_sent}
</div>
{else}

{if $is_contactform_error}
<div class="serendipity_center serendipity_msg_important">
{$plugin_contactform_error}
</div>

am i right, when i delete "serendipity_center" in both "if's" and then the feedback sentence is displayed not under the index.php?

to the css: there is a lot of "input" stuff in my css (i am using "andreas00" at the moment) and i don't know where to change what to get my radiobuttons left-aligned. could you help?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

No, the center thing has nothing to do with it, this is a CSS attribute.

You must put your IF/ELSE things properly, so that only the rest of the stuff is shown when the one IF case happens. Currently, the whole process flow just goes on.

Just have a try, play around with the if-things, I am sure you'll find the solution :)
to the css: there is a lot of "input" stuff in my css (i am using "andreas00" at the moment) and i don't know where to change what to get my radiobuttons left-aligned. could you help?
Just add a "nowidth" class to your input radio fields, and in your css add a

Code: Select all

input.nowidth {
  width: auto;
  display: inline;
}
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 »

hi garvin,

thanks a lot for your help. i followed your instructions, and the "yes" buttons are perfect now. only the "no" buttons should be far more left and next to the radio button, not over it. at the moment it looks like this:

[img]http://www.kexy.de/screenshot_2.jpg[/img]

i marked red, how it should look like.

***
i also played around with the smarty "IF" tags and deleted all "index" commands, but that didn't help :( i still get the index.php over the "feedback-sentence". at the moment my .php-file looks in the smarty section like this:

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;
}
}
}

any clue where to change, that the feedback-page is displayed without the index.php on top?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

I'm sorry, but for the input buttuns you'll need to check/learn some CSS to see how to align that, I don't have the time right now to look into this.

What exactly do you mean with "index.php on top"? The page you submit the form to will always shown the serendipity layout around it; you cannot get rid of that, if you mean this. Why would you want that? IT's always nicer for the user to see feedback in the usual design?

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 »

hi garvin,

if you click on "send" the next page that opens looks like this at the moment:
Image

and i would like to get rid of the stuff above "Kontaktformular".

i am sure, this is possible, but i don't know how :(

and yes, i will take classes in .css-stuff :D
Post Reply