forked from afup/aperophp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request afup#12 from Koin/master
Inscription des membres : formulaire, actions.
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ composer.phar | |
nbproject/ | ||
app/config.php | ||
deps.lock | ||
.buildpath | ||
.project | ||
.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |