Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Widget Newsletter post error

Go to End

2 Posts   880 Views


Community Member, 3 Posts

23 June 2012 at 8:17am

Hi everyone,
I'm trying to make a widget for users to subscribe to a newsletter.
Here's the code:

 * Widget form the NETForms Newsletter 
 * the user only need to input his email adress
class NewsletterWidget extends Widget {
	static $db = array(
		"TitleNLW" => "Text",
		"TextNLW" => "Text",
		"PlaceHolderTextNLW" => "Text",
		"SubmitButtonTextNLW" => "Text",
		"UserKeyNLW" => "Text",
		"MailingListKey" => "Text"
	static $cmsTitle = "Widget NewsletterWidget";
	static $description = "Widget for a user to subscribe to the NETForms newsletter";
	function getCMSFields() {
		return new FieldSet(
			new TextField("TitleNLW", "Title on top of widget"),
			new TextField("TextNLW", "Text description under the title"),	
			new TextField("PlaceHolderTextNLW", "Text inside the submit field that will disapear when the user put something else"),
			new TextField("SubmitButtonTextNLW", "Text for the submit button"),
			new TextField("UserKeyNLW", "NETForms user key"),
			new TextField("MailingListKey", "NETForms mailing list key")

class NewsletterWidget_Controller extends Widget_Controller {
	public static $allowed_actions = array(
	function NewsletterForm() {		
		$header = '';
		$textButton = '';
		$fields = new FieldSet(
			new HeaderField($header, $header, 4),
			new EmailField('Email')
		$actions = new FieldSet(
			new FormAction('SendNewsletterForm', $textButton)
		$validator = new RequiredFields('Email');
		return new Form($this, 'NewsletterForm', $fields, $actions, $validator);
	function SendNewsletterForm($data, $form) {
		$userKeyTest = 'a1434f';
		$mailListKeyTest = '98550b77-4e';

		// get email from user entry
		// $email = $data['Email'];
		$url = ''.$userKeyTest.'&greeting=&firstname=&lastname=&email='.$email.'&externalkey=&mailinglistkey='.$mailListKeyTest;

		// create a new cURL resource
		$curl = curl_init();

		// set URL and other appropriate options
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_HEADER, false);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
		curl_setopt($curl, CURLOPT_CAINFO, getcwd() . "/somesite/somecertificate.crt");
		// grab URL and pass it to the browser
		// go back to home page

When I try to submit an email, I get this (in dev mode)

[User Error] No widget found
POST /widget/58/NewsletterForm

Line 247 in C:\web\sitename\sapphire\core\control\ContentController.php

239 		// find widget
240 		$widget = null;
241 		foreach($widgetAreaRelations as $widgetAreaRelation) {
242 			if($widget) break;
243 			$widget = $this->dataRecord->$widgetAreaRelation()->Widgets(
244 				sprintf('"Widget"."ID" = %d', $SQL_id)
245 			)->First();
246 		}
247 		if(!$widget) user_error('No widget found', E_USER_ERROR);
249 		// find controller
250 		$controllerClass = '';
251 		foreach(array_reverse(ClassInfo::ancestry($widget->class)) as $widgetClass) {
252 			$controllerClass = "{$widgetClass}_Controller";
253 			if(class_exists($controllerClass)) break;


    No widget found
    Line 247 of ContentController.php
    Line 143 of RequestHandler.php
    Line 147 of Controller.php
    Line 199 of ContentController.php
    Line 67 of ModelAsController.php
    Line 282 of Director.php
    Line 125 of Director.php
    Line 127 of main.php

I've seen a lot of people struggling with form inside a widget ... anyone have any idea?


Community Member, 3 Posts

23 June 2012 at 8:35am

for whom ever struggle with that kind of problem, simply add at the end of your Widget_Controller

function Link() {
	    return $this->class;

and it'll do the tricks.