Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Widget Newsletter post error

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

Page: 1
Go to End
Author Topic: 441 Views
  • tiloud
    Community Member
    3 Posts

    Widget Newsletter post error Link to this post

    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 = 'https://api.netscoop.ca/service.asmx/saveContact?userkey='.$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?

  • tiloud
    Community Member
    3 Posts

    Re: Widget Newsletter post error Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.