Complete registration.

- Fix db.php functions
- Improve validations and status modal message on registerform.js
IS NEEDED SOME MINOR GRAPHICAL MODIFICATIONS IN FRON-PAGE
This commit is contained in:
German Correa 2017-12-09 12:12:50 -03:00
parent 507ea9a7ac
commit 0752ec35ef
5 changed files with 139 additions and 91 deletions

View File

@ -1,4 +1,4 @@
<?php
<?php
class DB{
private $pdo;
@ -12,13 +12,15 @@
}
public function insert($registro){
$columns = implode(",", array_keys($registro));
echo $columns;
$sql = "INSERT INTO Registro ($columns)"
$sql = 'INSERT INTO Registro (nombre,apellido,titulo,afiliacion,ciudad,'
.'pais,email,fechaLlegada,fechaPartida,financiacion,'
."invitado,cartaInvitacion,roomingPref,roommate,fechaRegistro)"
.' VALUES (:nombre,:apellido,:titulo,:afiliacion,:ciudad,:pais,:email,:fechaLlegada,'
.':fechaPartida,:financiacion,:invitado,:cartaInvitacion,:roomingPref,:roommate,:fechaRegistro);';
echo $sql;
$stmt = $this->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);
}
}
?>

Binary file not shown.

View File

@ -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('<strong><span class="glyphicon glyphicon-remove-sign">'
+'</span>Error! </strong><br/>'+msg);
}
else{
msgTxt.removeClass("alert-danger");
msgTxt.addClass("alert-success");
msgTxt.html('<strong><span class="glyphicon glyphicon-ok-sign">'
+'</span>Success! </strong><br/>'+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+"<ul>";
$.each(data.errors, function(k,v){
errMsg+="<li>"+v+"</li>";
});
errMsg+="</ul>";
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 = $("<span class='glyphicon glyphicon-remove form-control-feedback'></span>");
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("<span class='glyphicon glyphicon-ok form-control-feedback'></span>");
label.before("<span class='glyphicon glyphicon-ok form-control-feedback'></span>");
}
},
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");
});
});

View File

@ -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;
});
});

View File

@ -163,8 +163,8 @@
<!--Captcha -->
<div class="row">
<div class="form-group col-xs-12">
<div id="testing" class="g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div>
<!--<div class="g-recaptcha" data-sitekey="6LesRDsUAAAAAJvyoODvjiza9u75qEGJmbKHEV6s"></div>-->
<div id="testing" class="input-container g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div>
<!--<div class="input-container g-recaptcha" data-sitekey="6LesRDsUAAAAAJvyoODvjiza9u75qEGJmbKHEV6s"></div>-->
</div>
</div>
@ -175,36 +175,41 @@
</div>
</div>
</form>
<div id="statusmsg" class="alert alert-error">
</div>
<!--{% if flash("submit-register-err") %}-->
<!--{% if flash("submit-register-err") %}
<div id="statusmsg" class="alert alert-error">
<strong>Error!</strong>
{% for msg in flash("submit-register-err") %}
<kbd>{{ msg }}.</kdb>
{% endfor %}
</div>
<!-- {% endif %}-->
<!--<div id="myModal" class="modal fade" role="dialog">
{% endif %}-->
<div id="msgModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Revise sus datos cuidadosamente y confirme</h4>
<h4 class="modal-title">GGDWorkshop Registration</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
<div class="alert">
</div>
</div>
<div class="modal-footer">
<!--<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No
</button>
</div>
</div>-->
</div>
</div>
</div>-->
</div>
{% endblock %}