Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Registrations Activation

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

Page: 1 2 3
Go to End
Author Topic: 1280 Views
  • FireDevil
    Avatar
    Community Member
    12 Posts

    Registrations Activation Link to this post

    Hello SilverStripe Users,

    I hope man can me help here.

    I have me build a registrationForm without modul and will now a activation build but will not work i have problems with my $_GET.

    But here my Datas:

    My Test URL : http://localhost.com/silverstripe2.4/Activate?email=demo@localhost.com&code=d8f631b75ef4961c1ff1a7ccba933e9726d98c4e

    with my RegistrationForm I make me a random code in my Database, now i will in my ActivateForm check E-mail Adress and the Code what is generated.

    Here my ActivateForm:

    <?
    // INTERFACES:
    // - Form
    // - Form_Controller

    //==============================================================================
    // Form
    //==============================================================================
    class ActivatePage extends Page {
    public static $db = array();
    public static $has_one = array();
    public static $has_many = array();
    public static $many_many = array();
    public static $can_be_root = true;
    public static $icon = 'themes/immofuchs24/images/treeicons/security';
    //----------------------------------------------------------------------------
    }
    //==============================================================================
    // Form_Controller
    //==============================================================================
    class ActivatePage_Controller extends Page_Controller {

    public static $allowed_actions = array (
    'ActivateForm'
    );
    function ActivateForm() {

    if(!isset($_GET['email'])) {
    $Active->sessionMessage(
    'Fehler: Unvollständige Daten übergeben - E-mail fehlt.',
    'bad'
    );
    return Director::redirectBack();
    } elseif(!isset($_GET['Code'])) {
    $Active->sessionMessage(
    'Fehler: Unvollständige Daten übergeben - Code fehlt.',
    'bad'
    );
    return Director::redirectBack();
    } else {
    if(!$Email = DataObject::get_one("Email", "`Email` = '". Convert::raw2sql($data['Email']) . "'")) {
    $Active->AddErrorMessage('Email', 'Fehler: E-mail Adresse exestiert nicht.', 'bad');
    return Director::redirectBack();
    } elseif(!$Code = DataObject::get_one("Code")) {
    $Active->AddErrorMessage('Code', 'Fehler: Code ist nicht korrekt.', 'bad');
    return Director::redirectBack();
    } else {
    $Code = 0;
    $Code = new Code();
    $ActiveCode->saveInto($Code);
    $ActiveCode->write;
    }
    }
    }
    }
    ?>

    I hope a Member here show my Problem and can help me Thanks.

    PS: my englisch is not best

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Registrations Activation Link to this post

    There are a couple of problems there.

    First, this is not a form at all. This is a submit method, right? I'd recommend to post the complete form, so that we can see what you want to accomplish.

    ~~

    If you want to use $_GET parameters in the submit method, you need to tell your form to use $form->setFormMethod('get') instead of $_POST.

    function GetForm() {
       $fields = new FieldSet(
          new EMailField('Email')
       );
       $actions = new FieldSet(
          new FormAction('GetForm_submit', 'Submit')
       );
       $form = new Form($this, 'GetForm', $fields, $actions);
       $form->setFormMethod('get');

       return $form;
    }

    function GetForm_submit($data, $form) {
       print_r($_GET);
       print_r($data); // same as $_GET
    }

  • FireDevil
    Avatar
    Community Member
    12 Posts

    Re: Registrations Activation Link to this post

    Hello Devlin,

    Thanks for your reply that what you see is my Active.php and my complete code for this, the URL comes from my Registration.php
    with Email.

    i will when the Member my Link from the Email Klicked that checked automatical is a Email in the URL, and a Code in the URL.
    When a Email and a Code is in the URL so i will this Check with my Database Member then the member Table i have extended with Code and status, and there is then from my URL the Random Code where you see on this URL Code=here is the Code

    Is the Email and the Code from the Link Correct so i will update Code = 0 and status what is inaktiv update to aktiv.

    Thanks

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Registrations Activation Link to this post

    Ah ok. So this is really no form at all.

    But as I mentioned, your code has many problems. First you should activate proper error_reporting:
    Set "Director::set_environment_type("dev");" in "mysite/_config.php".

    To call the method, you've to use the following URL:
    http://localhost.com/silverstripe2.4/Activate/ActivateForm/?email=demo@localhost.com&code=d8f631b75ef4961c1ff1a7ccba933e9726d98c4e

    As a alternative, you can use the old URL but call ActivateForm in the init method:

    class ActivatePage_Controller extends Page_Controller {
    function init() {
    parent::init();

    $this->ActivateForm();
    }
    }

    The ActivateForm():
    - [Notice] Undefined variable: Active
    - [Notice] Undefined variable: data
    - [Notice] Undefined variable: ActiveCode

  • FireDevil
    Avatar
    Community Member
    12 Posts

    Re: Registrations Activation Link to this post

    Hello Devlin,

    Thanks to much, But now I understand only station in my config I'm on dev.
    In my URL, the word ActivateForm is not with me is against but only Activate?Email ?? where did you get the ActivateForm ?? for although I have to admit though I'm already a few weeks with SS but am unfortunately not so well versed in it yet maybe you can give me to write down a solution which I understand?

    Thank you in advance for your efforts so maybe you could also write a small explanation to

    Edit:

    I have a .ss Data with name ActivatePage.ss, and in this stay my variable $ActivateForm

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Registrations Activation Link to this post

    ~~ Let's switch to german. ~~

    I have a .ss Data with name ActivatePage.ss, and in this stay my variable $ActivateForm

    Wenn du den Methodennamen direkt in die URL schreibst, dann würde die Methode automatisch aufgerufen werden, da du sie ja unter $allowed_actions definiert hast. Aber so wie du es machst ist es auch ok.

    Aber was passiert denn nu, wenn du die URL aufrufst?
    Wenn du das Dev Enviroment aktiviert hast, dann solltest du eine Fehlermeldungen angezeigt bekommen.
    Wenn du eine weiße Seite bekommst, dann ist Dev Enviroment nicht aktiviert.
    Wenn gar nichts passiert und die Seite normal gerendert wird, dann ist das Template noch nicht im System registriert -- immer wenn du neue Dateien hinzufügst, dann musst du http://localhost.com/silverstripe2.4/dev/build/ aufrufen, damit das Manifest neu erstellt wird.

    Als nächstes solltest du probieren, ob alle $_GET Parameter in der ActivateForm() Methode ankommt.
    function ActivateForm() {
    print_r($_GET);
    // array(email=>demo@localhost.com,code=>d8f631b75ef4961c1ff1a7ccba933e9726d98c4e)
    }

  • FireDevil
    Avatar
    Community Member
    12 Posts

    Re: Registrations Activation Link to this post

    Da bin ich wiedermal xD

    Ja Deutsch ist eine gute Idee ;-)

    Also ich habe jetzt mal dies in meinen Code eingefügt um es zu testen wie du sagtest:

    class ActivatePage_Controller extends Page_Controller {

    function ActivateForm() {
    print_r($_GET);
    // array(email=>demo@localhost.com,code=>d8f631b75ef4961c1ff1a7ccba933e9726d98c4e)
    }
    }

    dann habe ich nochmal dev/build gemacht und die seite mit ?flush=1 aktualisiert.

    Dann hab ich den Link im Browser versucht aufzurufen und es kommt nur ein Fehler der mir sagt Netzwerküberschreitung es passiert also garnichts

    Du hast geschrieben so wie ich es mache geht es auch, aber wie geht es denn noch gibt es vielleicht noch eine einfachere methode ?

    EDIT: Man bin ich blöd ich kann keine Meldung bekommen wenn meine Url Falsch ist meine locale URL ist ja nur http://localhost,
    habe aber in meinem E-mail versand http://localhost.com drin stehen

    habe das .com weg gemacht und bekomme diese aussage :
    Array ( => /silverstripe2.4/Activate [email= => [email=demo@localhost.com]demo@localhost.com] => [email=demo@localhost.com]demo@localhost.com[/email] [code] => d8f631b75ef4961c1ff1a7ccba933e9726d98c4e )

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Registrations Activation Link to this post

    Netzwerküberschreitung wird angezeigt, wenn die URL falsch ist, der Server gerade nicht läuft oder die Route zum Server unterbrochen wurde.

    Vielleicht mal mit http://localhost/silverstripe2.4/Activate?email=demo@localhost.com&code=d8f631b75ef4961c1ff1a7ccba933e9726d98c4e probieren?

    1280 Views
Page: 1 2 3
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.