complete CustomerCreation form
This commit is contained in:
@@ -50,6 +50,7 @@ class Customer implements EventSubscriberInterface
|
||||
if ($form->isValid()) {
|
||||
echo "ok"; exit;
|
||||
} else {
|
||||
|
||||
$event->setFormError($form);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,10 @@ namespace Thelia\Form;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\ExecutionContext;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
|
||||
class CustomerCreation extends BaseForm
|
||||
@@ -46,13 +49,6 @@ class CustomerCreation extends BaseForm
|
||||
),
|
||||
"label" => "lastname"
|
||||
))
|
||||
->add("email", "email", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Email()
|
||||
),
|
||||
"label" => "email"
|
||||
))
|
||||
->add("address1", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
@@ -77,15 +73,74 @@ class CustomerCreation extends BaseForm
|
||||
),
|
||||
"label" => "country"
|
||||
))
|
||||
->add("email", "email", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Email(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
$this,
|
||||
"verifyExistingEmail"
|
||||
)
|
||||
))
|
||||
),
|
||||
"label" => "email"
|
||||
))
|
||||
->add("email_confirm", "email", array(
|
||||
"constraints" => array(
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
$this,
|
||||
"verifyEmailField"
|
||||
)
|
||||
))
|
||||
),
|
||||
"label" => "email confirmation"
|
||||
))
|
||||
->add("password", "password", array(
|
||||
"constraints" => array(
|
||||
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4)))
|
||||
)
|
||||
),
|
||||
"label" => "password"
|
||||
))
|
||||
->add("password_confirm", "password", array(
|
||||
"constraints" => array(
|
||||
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))),
|
||||
new Constraints\Callback(array("methods" => array(
|
||||
array($this, "verifyPasswordField")
|
||||
)))
|
||||
),
|
||||
"label" => "password confirmation"
|
||||
))
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
public function verifyPasswordField($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
|
||||
if ($data["password"] != $data["password_confirm"]) {
|
||||
$context->addViolation("password confirmation is not the same as password field");
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyEmailField($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
|
||||
if ($data["email"] != $data["email_confirm"]) {
|
||||
$context->addViolation("email confirmation is not the same as email field");
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyExistingEmail($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (CustomerQuery::create()->filterByEmail($value)->exists()) {
|
||||
$context->addViolation("This email already exists");
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "customerCreation";
|
||||
|
||||
@@ -18,4 +18,5 @@ use Thelia\Model\om\BaseCustomer;
|
||||
*/
|
||||
class Customer extends BaseCustomer
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -18,4 +18,5 @@ use Thelia\Model\om\BaseCustomerQuery;
|
||||
*/
|
||||
class CustomerQuery extends BaseCustomerQuery
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{include file="includes/header.html"}
|
||||
|
||||
{form name="thelia.customer.creation"}
|
||||
<form method="post" action="index_dev.php?action=createCustomer" {form_enctype form=$form} >
|
||||
<form method="post" action="index_dev.php?action=createCustomer&view=connexion" {form_enctype form=$form} >
|
||||
|
||||
{form_field_hidden form=$form}
|
||||
{form_field form=$form.firstname}
|
||||
@@ -66,6 +66,34 @@
|
||||
<br />
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form.email}
|
||||
{form_error form=$form.email}
|
||||
{#message}
|
||||
{/form_error}
|
||||
<label><span>{intl l="{$label}"}</span></label><input type="email" name="{$name}" {$attr} ><br />
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form.email_confirm}
|
||||
{form_error form=$form.email_confirm}
|
||||
{#message}
|
||||
{/form_error}
|
||||
<label><span>{intl l="{$label}"}</span></label><input type="email" name="{$name}" {$attr} ><br />
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form.password}
|
||||
{form_error form=$form.password}
|
||||
{#message}
|
||||
{/form_error}
|
||||
<label><span>{intl l="{$label}"}</span></label><input type="password" name="{$name}" {$attr} ><br />
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form.password_confirm}
|
||||
{form_error form=$form.password_confirm}
|
||||
{#message}
|
||||
{/form_error}
|
||||
<label><span>{intl l="{$label}"}</span></label><input type="password" name="{$name}" {$attr} ><br />
|
||||
{/form_field}
|
||||
|
||||
<input type="submit" value="valider">
|
||||
</form>
|
||||
{/form}
|
||||
|
||||
Reference in New Issue
Block a user