Recent Topics

1 Nov 23, 2007 09:46    

My b2evolution Version: 1.10.x

Hi all,

I've managed to figure out how to add the code to show a new field on the contact form page, but have no idea how to get the inputted text to send with the email. When I tested it, the text of the subject and the message sends, but not my extra field.

I have added this code:

$Form->textarea( 'i', '', 1, T_('Would you like to be added to our mailing list'), T_(''), 40, 'bComment' );

to the appropriate place in skins/_msgform.php

Anyone have any ideas how I can get this to work?

Thanks,

Na3

2 Nov 23, 2007 10:12

THe most robust way is to code a plugin that hooks into the following events :

function DisplayMessageFormFieldset( $params ) // use this to add your extra field

function MessageFormSent( $params ) // use this to grab your value and add it to the email

¥

3 Nov 23, 2007 10:39

Thanks Yabba - but I'm a bit lost as to how to do this. I've never coded a plugin before. And don't know how to get the plugin to be called by the message form.

A little bit more help needed please!

Thanks,

Na3

4 Nov 23, 2007 11:09

Here's an example of a plugin that should work for you, note, it's totaly untested

<?php
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


class yourplugin_plugin extends Plugin
{
	var $name = 'Mailing List';
	var $code = 'mail_list';
	var $priority = 50;
	var $version = 1;
	var $author = 'Your name';
	var $group = 'Your group name';
	var $help_url = 'http://yourdomain.com/';

	function PluginInnit()
	{
		$this->short_desc = 'short description for your plugin';
		$this->long_desc = 'long description for your plugin';
		return $this;
	}

	/**
	 * add your field to the message form
	 *
	 * @param mixed $params
	 */
	function DisplayMessageFormFieldset( $params )
	{
		$params['Form']->checkbox( $this->get_class_id().'_subscribe', true, 'Join mailing list', 'would you like to be added to our mailing list?' );
	}


	/**
	 * Add the answer to the email
	 *
	 * @param mixed $params
	 */
	function MessageFormSent( & $params )
	{
		if( param( $this->get_class_id().'_subscribe',  'boolean' ) )
		{	// visitor wishes to be added
			$params['message'] .= 'Add me to your mailing list';
		}
		else
		{	// visitor doesn't wish to be added
			$params['message'] .= 'Don\'t add me to your mailing list';
		}
		return $params;
	}

}
?>

Important bit :
You need to name the file to match whatever plugin name you choose, so if your plugin is called yourplugin in the code

class yourplugin_plugin extends Plugin

then your file must be named
yourplugin.plugin.php

Obviously you need to upload it to your plugins folder and install it. It will automatically be called at the right moments by the message form and when the message form is submitted

¥

5 Nov 23, 2007 11:53

Thanks Yabba.

The code works fine, up until I press send. I got the following errors (both ticking the checkbox, and without):

Warning: Cannot modify header information - headers already sent by (output started at /home//public_html/sal/plugins/_mailinglist.plugin.php:1) in /home//public_html/sal/inc/_misc/_misc.funcs.php on line 2886

Warning: Cannot modify header information - headers already sent by (output started at /home//public_html/sal/plugins/_mailinglist.plugin.php:1) in /home//public_html/sal/inc/_misc/_misc.funcs.php on line 2887

Warning: Cannot modify header information - headers already sent by (output started at /home//public_html/sal/plugins/_mailinglist.plugin.php:1) in /home//public_html/sal/inc/_misc/_misc.funcs.php on line 2888

Warning: Cannot modify header information - headers already sent by (output started at /home//public_html/sal/plugins/_mailinglist.plugin.php:1) in /home//public_html/sal/inc/_misc/_misc.funcs.php on line 2889

Warning: Cannot modify header information - headers already sent by (output started at /home//public_html/sal/plugins/_mailinglist.plugin.php:1) in /home//public_html/sal/inc/_misc/_misc.funcs.php on line 2984

Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/sal/plugins/_mailinglist.plugin.php:1) in /home//public_html/sal/inc/_misc/_misc.funcs.php on line 2987

And I'm getting this error in the backend:

Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/sal/plugins/_mailinglist.plugin.php:1) in /home//public_html/sal/inc/VIEW/_menutop.php on line 39

6 Nov 23, 2007 11:59

Oh, I lie. The errors do appear, but the email does actually come through...

7 Nov 23, 2007 14:03

Warning: Cannot modify header information - headers already sent by (output started at /home//public_html/sal/plugins/_mailinglist.plugin.php:1

Open the file in notepad and check for any whitespace/blank lines before the first <?php at the top of the file ;)

¥

8 Nov 23, 2007 15:07

I checked the file, and there was one space before the <?php at the top. I removed it, but I'm still getting errors.

9 Nov 23, 2007 15:12

There will probably be one space after the closing ?> also. I tested this and it works without errors when you are done with the whitespace.
Only yesterday did I wrote about this in the docs: [url=http://manual.b2evolution.net/FAQ_:_After_Installation#I_get_this_error:_.22Warning:_Cannot_modify_header_information_-_headers_already_sent_by_.28output_started_at_....22] I get this error: "Warning: Cannot modify header information - headers already sent by (output started at ..."[/url].

Good luck

10 Nov 24, 2007 09:19

Thanks Afwas and Yabba! That fixed it and all works fine now. Thanks again for all your help!

11 Nov 24, 2007 12:15

Hi Afwas you sent me over here as an answer to http://forums.b2evolution.net/viewtopic.php?t=13247 with my question on how to popup all users emails at once instead of clicking each email icon to get their email. Ive dont all this and installed the plugin. Now Im not even really sure what its suppose to do or what I should see!

12 Nov 24, 2007 12:19

I was not an answer but an idea. If your users contact you through the contact form, they now have an option to join the newsletter. That's on the email you get from them (I want to join, I do not want to join).
You still need to setup the newsletter yourself or mailinglist or whatever it is you want.

Good luck

13 Nov 24, 2007 12:21

OH ok. So maybe I should be requestion something some where on how to grab all emails at once?

14 Nov 24, 2007 12:31

I don't know how may you have, but they are in the database.
With your email client (Thunderbird is preferred, but Outlook will do) you can setup a group 'Bloggers' and write a newsletter every month. You send that to (ALWAYS in th BCC field) the group and everybody receives the newsletter.

New bloggers and others will contact you through email and you add them or not.

Good luck

15 Nov 24, 2007 22:09

One more thing. I made a tester account and I didnt see anywhere that asked about registering for my mailing list. What should I be seeing and where after installing the plugin?

(sorry m really novice at all this and just trying to figure it all out!)

thank you!


Form is loading...