Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » TextField with $var - simple Captcha?

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

Page: 1
Go to End
Author Topic: 1214 Views
  • yaizo
    Community Member
    19 Posts

    TextField with $var - simple Captcha? Link to this post

    hello folkz,

    following this tutorial -> http://www.ssbits.com/creating-a-simple-contact-form i have made a new form in my page.
    this works very well but what i need is one further TextField('SpamProtect') witch is given an variable.
    normally i would put some vars and if else query but i don't know how to put this in here??? because this is an db-Field array?

    so this is the code i use: mysite/code/ContactForm.php

    class ContactPage extends Page{

    static $db = array(
    'Mailto' => 'Varchar(100)',
    'SubmitText' => 'Text'

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.OnSubmission", new TextField('Mailto', 'Email submissions to'));
    $fields->addFieldToTab("Root.Content.OnSubmission", new TextareaField('SubmitText', 'Text on Submission'));

    return $fields;

    class ContactPage_Controller extends Page_Controller{

    function ContactForm() {
    // Create fields
    $fields = new FieldSet(
    new TextField('Name', 'Name*'),
    new EmailField('Email', 'Email*'),
    new TextareaField('Message','Ihr Anliegen*'),
    //the next Fild i set is my Spam protector,this here must given an variable but how?
    new TextField('SpamProtect', 'Anti-Spam*')

    // Create action
    $actions = new FieldSet(
    new FormAction('SendContactForm', 'Send')

    // Create Validators
    $validator = new RequiredFields('Name', 'Email', 'Message', 'SpamProtect');

    //i think here must be an variable witch is connected with 'SpamProtect'
    $spamProtector = "anti-spam-code-hier";

    return new Form($this, 'ContactForm', $fields, $actions, $validator);


    function SendContactForm($data) {

    //Set data
    $From = $data['Email'];
    $To = $this->Mailto;
    $Subject = "Website Contact message";
    $email = new Email($From, $To, $Subject);
    //set template
    //populate template
    //send mail
    //return to submitted message
    Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");

    public function Success(){
    return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";

    //here have to be a further query: success ==1 and $spamProtector == "anti-spam-code" -> send message.
    return (isset($_REQUEST['success'] == "1) && ($spamProtector == "???SpamProtector???"));

    if anyone can give me an helping hand i would be very thankful.
    ps. i tested userforms and mellom an so on, but this things are to big for me and my know-how.
    0.O m.the.green

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.