Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spamprotection "white screen of death"?!? #15

Closed
mhenden opened this issue Jul 21, 2014 · 10 comments
Closed

spamprotection "white screen of death"?!? #15

mhenden opened this issue Jul 21, 2014 · 10 comments
Labels

Comments

@mhenden
Copy link

mhenden commented Jul 21, 2014

This module has great promise -- I REALLY HATE SPAM -- but I think I'm doing something wrong? Have loaded "spamprotection" and "recaptcha" directories in site root directory and dev/build/ as well as ?flush=1 and ?flush=all (nothing actually seemed to happen), then opened ContactForm.php and, within the public function _construct string I added the following:

$recaptchaField = new RecaptchaField('MyCaptcha');
$recaptchaField->jsOptions = array('theme' => 'clean'); // optional

So far so good. It's when I include:

   $form->enableSpamProtection();

and flush again that I get the white screen of death.

Am I placing this code in the right place? I don't think so!

@mhenden
Copy link
Author

mhenden commented Jul 21, 2014

Thought I'd include complete (non working) code. Comment out the enableSpamProtection command and everything works?!

<?php
//
class ContactForm extends Form{

public function __construct($controller, $name) {

$fields = new FieldList(
    $dataFields = new CompositeField(
    TextField::create("Name", _t('ContactForm.YOURNAME', 'Your name'))
        ->setCustomValidationMessage(_t('ContactForm.YOURNAME_MESSAGE_REQUIRED', 'Please enter your name'))
        ->setAttribute('data-message-required', _t('ContactForm.YOURNAME_MESSAGE_REQUIRED', 'Please enter your name')),

    EmailField::create("Email", _t('ContactController.EMAILADDRESS', "Your email address"))
        ->setCustomValidationMessage(_t('ContactForm.EMAILADDRESS_MESSAGE_REQUIRED', 'Please enter your email address'))
        ->setAttribute('data-message-required', _t('ContactForm.EMAILADDRESS_MESSAGE_REQUIRED', 'Please enter your email address'))
        ->setAttribute('data-message-email', _t('ContactForm.EMAILADDRESS_MESSAGE_EMAIL', 'Please enter a valid email address')),


    TextareaField::create("Comment", _t('ContactController.COMMENTS', "Comments"))
        ->setCustomValidationMessage(_t('ContactForm.COMMENT_MESSAGE_REQUIRED', 'Please enter your comment'))
            ->setAttribute('data-message-required', _t('ContactForm.COMMENT_MESSAGE_REQUIRED', 'Please enter your comment'))
    ),          

    HiddenField::create("ReturnURL")            
);

$dataFields->addExtraClass('data-fields');

$form->enableSpamProtection();

$recaptchaField = new RecaptchaField('MyCaptcha');
$recaptchaField->jsOptions = array('theme' => 'clean'); // optional

// save actions
$actions = new FieldList(
    new FormAction("doPostContact", _t('ContactForm.POST', 'Post'))
);

// required fields for server side
$required = new RequiredFields(array(
    'Name',
    'Email',
    'Comment'
));

$this->setAttribute('novalidate','novalidate');

// Set it so the user gets redirected back down to the form upon form fail
//$this->setRedirectToFormOnValidationError(true);      



    parent::__construct($controller, $name, $fields, $actions, $required);
}

    /**
 * Process which creates a {@link Comment} once a user submits a comment from this form.
 *
 * @param array $data 
 * @param Form $form
 */
public function doPostContact($data, $form) {       

    // extend hook to allow extensions. Also see onAfterPostComment
    //$this->extend('onBeforePostComment', $form);          


    $config = SiteConfig::current_site_config();

    // send  mail
    $email = $config->MailTo;
    $from = $data['Email'];
    $to = $email;


    $config->Title;
    $subject = "Contact Form - ".$config->Title;
    $email = new Email($from, $to, $subject);
    $email->setTemplate('ContactEmail');
    $email->populateTemplate($data);
    $email->send();    

    // set session
    Session::set('MailSent', true);     

    // extend hook to allow extensions. Also see onBeforePostComment
    //$this->extend('onAfterPostComment', $contact);                    


    $url = (isset($data['ReturnURL'])) ? $data['ReturnURL'] : false;

    return Controller::curr()->redirectBack($url);


    //return ($url) ? $this->redirect($url) : $this->redirectBack();    


}

public function forTemplate() {
    return $this->renderWith(array($this->class, 'Form'));
}   

public function SuccessMessage(){

  if(Session::get('MailSent')){
    $config = SiteConfig::current_site_config();
    $message = $config->SubmitText;
    Session::clear('MailSent');         
    return $message;
  }   
  return null;

}

}

@wilr
Copy link
Member

wilr commented Jul 21, 2014

Check your error logs for the actual error message? If you're in a dev environment you can turn on display_errors.

http://doc.silverstripe.org/framework/en/topics/debugging

@mhenden
Copy link
Author

mhenden commented Jul 21, 2014

Thanks Will. Nope, just getting a white screen -- going into dev mode doesn't tell me any more. However Firebug tells me it's a 500 error:

"NetworkError: 500 Internal Server Error - http://localhost/mysite-SS-v3.1.5/index.php/Security/login?BackURL=%2Fmysite-SS-v3.1.5%2Findex.php%3Fflush%3Dall"

Any tips?

@wilr
Copy link
Member

wilr commented Jul 21, 2014

Yes the 500 error means this is a issue with the server. More details will be available in your PHP or apache error logs.

@mhenden
Copy link
Author

mhenden commented Jul 21, 2014

OK, found my error logs. php error log tells me:

[21-Jul-2014 23:24:42 Europe/Berlin] PHP Fatal error: Call to a member function enableSpamProtection() on a non-object in /Users/mike/Sites/mysite-SS-v3.1.5/contact/code/ContactForm.php on line 29

So the problem is not the command itself, something's not set right that's stopping command from executing?

@tractorcow
Copy link
Contributor

Try adding php_value display_errors On to your .htaccess. Makes it easier to debug. :)

@tractorcow
Copy link
Contributor

Change $form->enableSpamProtection(); to $this->enableSpamProtection();

@mhenden
Copy link
Author

mhenden commented Jul 21, 2014

Thanks for your comments tractorcow -- think your update is an improvement! Now I have the following log error:

[22-Jul-2014 01:20:30 Europe/Berlin] PHP Warning: file_get_contents(): Filename cannot be empty in /Users/mike/Sites/mysite-SS-v3.1.5/framework/view/SSViewer.php on line 1042

It actually brought up the default SS error page this time... hmm?

@hp7
Copy link

hp7 commented Oct 3, 2014

you get this to work?
I have same issue with register page using member profiles module and mollom. (must not be logged in as admin)

@robbieaverill
Copy link
Contributor

Closing, originally reported issue was due to incorrect implementation and the issue has had no feedback in three years.

If anyone is still having issues with this please open a new issue which correctly identifies the new problem =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants