Skip to content

Commit

Permalink
Merge pull request afup#12 from Koin/master
Browse files Browse the repository at this point in the history
Inscription des membres : formulaire, actions.
  • Loading branch information
ubermuda committed Jan 29, 2012
2 parents 597ae97 + adc06c2 commit 9f93dce
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ composer.phar
nbproject/
app/config.php
deps.lock
.buildpath
.project
.settings/
1 change: 1 addition & 0 deletions app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
$app = require_once __DIR__.'/bootstrap.php';

$app->mount('/apero', new Aperophp\Provider\Controller\Aperos());
$app->mount('/member', new Aperophp\Provider\Controller\Member());

return $app;
49 changes: 49 additions & 0 deletions src/Aperophp/Form/Signup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Aperophp\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

use Symfony\Component\Validator\Constraints;

/**
* Signup form.
*
* @author Koin <[email protected]>
* @since 22 janv. 2012
* @version 1.0 - 22 janv. 2012 - Koin <[email protected]>
*/
class Signup extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('lastname', 'text')
->add('firstname', 'text')
->add('username', 'text')
->add('email', 'email')
->add('password', 'password');
}

public function getDefaultOptions(array $options)
{
$collectionConstraint = new Constraints\Collection(array(
'fields' => array(
'lastname' => new Constraints\MaxLength(array('limit' => 80)),
'firstname' => new Constraints\MaxLength(array('limit' => 80)),
'username' => new Constraints\MaxLength(array('limit' => 80)),
'email' => new Constraints\Email(),
'password' => new Constraints\NotNull(),
),
'allowExtraFields' => false,
));

return array('validation_constraint' => $collectionConstraint);
}

public function getName()
{
return 'signup';
}
}
60 changes: 60 additions & 0 deletions src/Aperophp/Provider/Controller/Member.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Aperophp\Provider\Controller;

use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;

/**
* Member controller.
*
* @author Koin <[email protected]>
* @since 22 janv. 2012
* @version 1.0 - 22 janv. 2012 - Koin <[email protected]>
*/
class Member implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = new ControllerCollection();

// *******
// ** Signup member
// *******
$controllers->get('signup.html', function() use ($app)
{
$form = $app['form.factory']->create(new \Aperophp\Form\Signup());

return $app['twig']->render('member/signup.html.twig', array(
'form' => $form->createView(),
));
})->bind('_signupmember');
// *******

// *******
// ** Create member
// *******
$controllers->post('create.html', function(Request $request) use ($app)
{
$form = $app['form.factory']->create(new \Aperophp\Form\Signup());

$form->bindRequest($request);
if ($form->isValid())
{
$data = $form->getData();
// TODO save member in database.
var_dump($data);
die;
}

return $app['twig']->render('member/signup.html.twig', array(
'form' => $form->createView(),
));
})->bind('_createmember');
// *******

return $controllers;
}
}
9 changes: 9 additions & 0 deletions src/Resources/views/member/signup.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<form method="post" action="{{ url('_createmember') }}" {{ form_enctype(form) }}>
{{ form_row(form.firstname) }}
{{ form_row(form.lastname) }}
{{ form_row(form.username) }}
{{ form_row(form.email) }}
{{ form_row(form.password) }}
{{ form_rest(form) }}
<button type="submit"><span>Signup</span></button>
</form>

0 comments on commit 9f93dce

Please sign in to comment.