diff --git a/db/db.php b/db/db.php
index 7ff3b06..1d975f0 100644
--- a/db/db.php
+++ b/db/db.php
@@ -1,4 +1,4 @@
-pdo->prepare($sql);
+
+ $stmt = $this->pdo->prepare($sql);
$stmt->execute([
':nombre' => $registro['nombre'],
':apellido' => $registro['apellido'],
@@ -27,17 +29,17 @@
':ciudad' => $registro['ciudad'],
':pais' => $registro['pais'],
':email' => $registro['email'],
- ':fechaLlegada' => $registro['fechaLlegada'],
- ':fechaPartida' => $registro['fechaPartida'],
+ ':fechaLlegada' => $registro['bda'],
+ ':fechaPartida' => $registro['eda'],
':financiacion' => $registro['financiacion'],
- ':invitado' => $registro['invitado'],
- ':cartaInvitacion' => $registro['cartaInvitacion'],
- ':roomingPref' => $registro['roomingPref'],
- ':roommate' => $registro['roommate'],
- ':fechaRegistro' => $registro['fechaRegistro']
+ ':invitado' => $registro['invited'],
+ ':cartaInvitacion' => $registro['letterinvited'],
+ ':roomingPref' => $registro['roomtype'],
+ ':roommate' => $registro['roomate'],
+ ':fechaRegistro' => $date = date('Y-m-d H:i:s'),
]);
return $this->pdo->lastInsertId();
-
+
}
public function getAll(){
$stmt = $this->pdo->prepare("SELECT * FROM Registro");
@@ -45,6 +47,13 @@
return $stmt->fetchAll(\PDO::FETCH_BOTH);
}
- }
+ public function findByMail($email){
+ $stmt = $this->pdo->prepare("SELECT * FROM Registro WHERE email=:email");
+ $stmt->bindParam(":email",$email);
+ $stmt->execute();
+ return $result = $stmt->fetch(\PDO::FETCH_ASSOC);
+
+ }
+
+ }
?>
-
diff --git a/db/ggdworkshop.db b/db/ggdworkshop.db
index ebf6556..daa8ecd 100644
Binary files a/db/ggdworkshop.db and b/db/ggdworkshop.db differ
diff --git a/public/js/registerform.js b/public/js/registerform.js
index 59ba031..a072fc4 100644
--- a/public/js/registerform.js
+++ b/public/js/registerform.js
@@ -1,30 +1,57 @@
+function showMsg(error,msg){
+
+ var msgTxt = $("#msgModal .modal-body .alert");
+ if(error){
+ msgTxt.removeClass("alert-success");
+ msgTxt.addClass("alert-danger");
+ msgTxt.html(''
+ +'Error!
'+msg);
+ }
+ else{
+ msgTxt.removeClass("alert-danger");
+ msgTxt.addClass("alert-success");
+ msgTxt.html(''
+ +'Success!
'+msg);
+ }
+ $("#msgModal").modal({show:true})
+}
$().ready(function(){
$("#statusmsg").hide();
-
$("#txtbda,#txteda").datepicker({
dateFormat: "dd/mm/yy",
minDate:new Date(2018,6,23),
maxDate:new Date(2018,6,27)
});
-
+
$("#pais").select2({
data: data.paises,
placeholder: "Select Country",
width: "100%",
+ });/*.one('select2-focus', select2Focus).on("select2-blur", function () {
+ $(this).one('select2-focus', select2Focus)
});
-
+
+function select2Focus() {
+ var select2 = $(this).data('select2');
+ setTimeout(function() {
+ if (!select2.opened()) {
+ select2.open();
+ }
+ }, 0);
+ }*/
+
$("#roomtype").select2({
data: data.roomtypes,
placeholder: "Select Rooming Preference",
width:"100%",
minimumResultsForSearch: -1,
dropdownCssClass: "bigdrop",
-
+
});
-
+
$('#registerform').on('submit',function(e) {
e.preventDefault();
@@ -47,6 +74,7 @@ $().ready(function(){
invited:{required:true},
financiacion:"required",
letterinvited:"required",
+ "g-recaptcha-response":"required"
},
@@ -62,26 +90,38 @@ $().ready(function(){
email: "Please enter a valid e-mail address",
invited: "Select one option please",
financiacion: "Select one option please",
- letterinvited: "Select one option please"
+ letterinvited: "Select one option please",
+ 'g-recaptcha-response': "Please validate reCAPTCHA",
+
-
},
submitHandler: function(form){
var formdata = $(form).serializeArray();
formdata.find(item => item.name === "pais").value = $("#pais").select2("data")[0].text;
formdata.find(item => item.name === "roomtype").value = $("#roomtype").select2("data")[0].text;
var parameters = $.param(formdata);
- console.log(parameters);
+
var post = $.post('api/register', parameters);
post.done(function(data){
- console.log(data);
- });
- //console.log(parameters);
+ if(data.success){
- },
+ showMsg(false,data.msg);
+ }
+ else{
+ var errMsg = data.msg+"
";
+ $.each(data.errors, function(k,v){
+ errMsg+="- "+v+"
";
+ });
+ errMsg+="
";
+ console.log(errMsg);
+ showMsg(true,errMsg);
+ }
+ });
+
+ },
errorElement: "em",
errorPlacement: function ( error, element ) {
- // Add the `help-block` class to the error element
+ // Add the `help-block` class to the error element
error.addClass("help-block");
var esradio = $(element).prop("type") == "radio";
var padre = element.parents(".input-container");
@@ -89,20 +129,20 @@ $().ready(function(){
padre.append(error);
var iconstatus = $("");
if(!$.contains(padre,"span.glyhpicon")){
- error.before(iconstatus);
+ error.before(iconstatus);
}
if(esradio){
error.css("display", "inline");
$(iconstatus).css("display", "inline");
$(iconstatus).css("position", "initial");
- }
+ }
},
success: function(label,element){
var esradio = $(element).prop("type") == "radio";
var padre = $(element).parents(".input-container");
- var iconstatus = padre.children("span.glyphicon");
+ var iconstatus = padre.children("span.glyphicon");
if(!iconstatus){
- label.before("");
+ label.before("");
}
},
highlight: function ( element, errorClass, validClass ) {
@@ -110,32 +150,19 @@ $().ready(function(){
var iconstatus = padre.children("span.glyphicon");
padre.addClass("has-error").removeClass("has-success");
iconstatus.addClass( "glyphicon-remove" ).removeClass( "glyphicon-ok" );
- padre.addClass( "has-error" ).removeClass( "has-success" );
+ padre.addClass( "has-error" ).removeClass( "has-success" );
},
unhighlight: function (element, errorClass, validClass) {
- var padre = $(element).parents(".input-container");
+ var padre = $(element).parents(".input-container");
var iconstatus = padre.children("span.glyphicon");
- padre.addClass("has-success").removeClass("has-error");
+ padre.addClass("has-success").removeClass("has-error");
iconstatus.addClass( "glyphicon-ok" ).removeClass( "glyphicon-remove" );
- padre.addClass( "has-success" ).removeClass( "has-error" );
- }
- });
+ padre.addClass( "has-success" ).removeClass( "has-error" );
+ },
+ //});
+
+ });
+
- var finan;
- $('input:radio[name="financiacion"]').change(function(){
- finan=true;
- if($(this).is(':checked') && $(this).val() == "si"){
- $("#detallefinan").show();
- $("#detallefinan textarea").addClass("has-error");
- }
- else
- $("#detallefinan").hide();
-
- $('#sifinan').tooltip("hide");
- $('#sifinan').tooltip("destroy");
- });
-
-
});
-
diff --git a/src/routes.php b/src/routes.php
index a2dc701..ac4c334 100644
--- a/src/routes.php
+++ b/src/routes.php
@@ -62,24 +62,24 @@ $app->group('/api', function($app){
});
$app->post('/register', function (Request $request, Response $response, array $args) {
- // Sample log message
- //$this->logger->debug(var_dump($request->getParsedBody()));
$db = new DB($this->db);
$data = $request->getParsedBody();
$messages = $this->flash;
- if(!isset($data['nombre']))
- $messages->addMessageNow("submit-register-err", "First Name could not be empty");
- if(!isset($data['apellido']))
- $messages->addMessageNow("submit-register-err", "Last Name could not be empty");
- if(!isset($data['email']))
+ if(!isset($data['nombre'])||empty($data['nombre']))
+ $messages->addMessageNow("submit-register-err", "First name could not be empty");
+ if(!isset($data['apellido'])||empty($data['apellido']))
+ $messages->addMessageNow("submit-register-err", "Last name could not be empty");
+ if(!isset($data['email'])||empty($data['email']))
$messages->addMessageNow("submit-register-err", "E-mail could not be empty");
- if(!isset($data['financiacion']))
+ if(!isset($data['financiacion'])||!is_numeric($data['financiacion']))
$messages->addMessageNow("submit-register-err", "Question about financial support must have a selected answer");
- if(!isset($data['invited']))
+ if(!isset($data['invited'])||!is_numeric($data['invited']))
$messages->addMessageNow("submit-register-err", "Question about 'invited to participate in this conference' must have a selected answer");
- if(!isset($data['letterinvited']))
+ if(!isset($data['letterinvited'])||!is_numeric($data['letterinvited']))
$messages->addMessageNow("submit-register-err", "Question about needing a letter of invitation must have a selected answer");
- if(!isset($data['g-recaptcha-response'])){
+
+ //ReCaptcha Validation
+ if(!isset($data['g-recaptcha-response'])||empty($data['g-recaptcha-response'])){
$messages->addMessageNow("submit-register-err", "Please validate captcha!");
}
else {
@@ -89,27 +89,34 @@ $app->group('/api', function($app){
if(!$resp->isSuccess()){
$messages->addMessageNow("submit-register-err", "ReCaptcha validation error " . implode($resp->getErrorCodes()));
}
+ else {
+ unset($data['g-recaptcha-response']);
+ }
+ }
+
+ try{
+ if($db->findByMail($data['email']))
+ $messages->addMessageNow("submit-register-err", $data['email']." is already registered");
+ else
+ $db->insert($data);
+ }
+ catch (Exception $e){
+ $this->logger->debug("Submit register DB error: ".$e->getMessage());
+ $messages->addMessageNow("submit-register-err", "DB error: ".$e->getMessage());
}
if($messages->hasMessage("submit-register-err")){
-
- $arrayresponse = array("success" => false, "errors"=>$messages->getMessage("submit-register-err"), "data"=>$data);
- $newres = $response->withJson($arrayresponse);
- return $newres;
+ $arrayresponse = array("success" => false,
+ "msg"=>"You registration could not be completed:\n",
+ "errors"=>$messages->getMessage("submit-register-err"), "data"=>$data);
}
else {
-
- /*try{
- $db->insert($data);
- }
- catch (Exception $e){
- $this->logger->debug($e->getMessage());
- return $e->getMessage();
- }*/
- echo "todo ok";
+ $arrayresponse = array("success" => true,
+ "msg"=>"You have been successfully registered to the GGDWorkshop",
+ "data"=>$data);
}
-
-
+ $newres = $response->withJson($arrayresponse);
+ return $newres;
});
});
diff --git a/templates/registration.html b/templates/registration.html
index a96b84c..67f8f05 100644
--- a/templates/registration.html
+++ b/templates/registration.html
@@ -163,8 +163,8 @@
@@ -175,36 +175,41 @@
+
+
+
-
+
-
+
-
Some text in the modal.
+
+
+
-
-
-->
+
{% endblock %}