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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Registrations Activation


Go to End


19 Posts   4464 Views

Avatar
FireDevil

Community Member, 13 Posts

28 August 2013 at 10:57pm

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

Avatar
Devlin

Community Member, 344 Posts

28 August 2013 at 11:48pm

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
}

Avatar
FireDevil

Community Member, 13 Posts

29 August 2013 at 1:37am

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

Avatar
Devlin

Community Member, 344 Posts

29 August 2013 at 2:05am

Edited: 29/08/2013 2:23am

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

Avatar
FireDevil

Community Member, 13 Posts

29 August 2013 at 2:47am

Edited: 29/08/2013 2:49am

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

Avatar
Devlin

Community Member, 344 Posts

29 August 2013 at 3:06am

~~ 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)
}

Avatar
FireDevil

Community Member, 13 Posts

29 August 2013 at 3:24am

Edited: 29/08/2013 3:34am

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 )

Avatar
Devlin

Community Member, 344 Posts

29 August 2013 at 3:28am

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?

Go to Top