{% extends 'base.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<style>
h4 {margin: 0;}
#send_verification_sms {
background-color: #337ab7;
border-color: #2e6da4;
}
#send_verification_sms:hover {color: #fff;}
#register_btn {display: none}
.errorCaptcha{ border: 1px solid #FF0000 }
.errorCaptchaMsg {color: #FF0000}
.tooltip-inner {color: #f00; border: 1px solid #f00}
input:invalid {color: #f00; border: 1px solid #f00}
input[type="text"]:valid {color: #008000; border: 1px solid #008000}
.red-bg{ background: #f6b3b3; color: #000 !important;}
/*input,
input:valid {
border-color: #ccc;
}*/
/*
input{color: #f00; border: 1px solid #f00}
*/
</style>
{% endblock %}
{% block page_title %}{{ 'register new account' | trans({}, 'clients') }}{% endblock %}
{% block flash_messages %}
{{ parent() }}
{# this is to display form global validation messages #}
{% if form_errors(form) is not empty %}
<div class="alert alert-danger" role="alert">
{{ form_errors(form) }}
</div>
{% endif %}
{% endblock %}
{% block body %}
<section class="section-padding error-page pattern-bg0 ">
<!-- Main Container -->
<div class="container">
<!-- Row -->
<div class="row">
<!-- Middle Content Area -->
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="form-grid required">{{ 'registration announcement message' | trans({'%{newline}':"<br />"}, 'clients')|raw }}</div>
<br />
<!-- Form -->
<div class="form-grid">
{{ form_start(form, {'attr': {'id': 'register_form'}} ) }}
<div class="row">
<div class="form-group col-md-4 col-xs-12">
{{ form_label(form.userIdentityInfo.firstnameAr, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
{{ form_widget(form.userIdentityInfo.firstnameAr) }}
{{ form_errors(form.userIdentityInfo.firstnameAr) }}
</div>
<div class="form-group col-md-4 col-xs-12">
{{ form_label(form.userIdentityInfo.fourthnameAr, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
{{ form_widget(form.userIdentityInfo.fourthnameAr) }}
{{ form_errors(form.userIdentityInfo.fourthnameAr) }}
</div>
<div class="form-group col-md-4 col-xs-12" id="id_num_div">
{{ form_label(form.userIdentityInfo.identificationNumber, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
{{ form_widget(form.userIdentityInfo.identificationNumber) }}
{{ form_errors(form.userIdentityInfo.identificationNumber) }}
</div>
</div>
<div class="row">
<div class="col-md-4 col-xs-12">
<div class="form-group col-md-6 col-xs-6">
<label>{{ 'enter the captcha code' | trans({}, 'clients') }}: <span class="required">*</span></label>
<input type="text" class="form-control {% if errorCaptcha %}{{ errorCaptcha }} {% endif %}" name="userCaptcha" id="userCaptcha" required="required" maxlength="4" validate-msg="{{ 'you should enter the captcha code' | trans({}, 'validators') }}" />
<span class="errorCaptchaMsg" style="font-size:12px;color:#e74c3c;display: {% if errorCaptcha %}{{ 'block' }} {% else %} {{ 'none' }} {% endif %}"> {{ 'captcha code is wrong' | trans({}, 'validators') }} </span>
</div>
<div class="form-group col-md-4 col-xs-4">
<label> </label>
<img id="captcha" src="{{ builder.inline }}" style="height: 50px !important; width: 115px !important;">
</div>
<div class="form-group col-md-2 col-xs-2">
<label> </label>
<p class="btn btn-light" id="refresh" style="padding:8px !important; margin-top:8px;">
<i class="fa fa-undo" style="font-size:14px" ></i>
</p>
</div>
</div>
<div class="form-group col-md-4 col-xs-12" id="mobile_num_div">
{{ form_label(form.mobileNumber, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
<div class="input-group">
{{ form_widget(form.mobileNumber) }}
<div class="input-group-btn">
<input type="button" name="send_verification_sms" id="send_verification_sms" value="{{ 'send verification' | trans({}, 'clients') }}" class="form-control btn btn-light">
</div>
</div>
{{ form_errors(form.mobileNumber) }}
</div>
<div class="form-group col-md-4 col-xs-12" id="verification_code" style="display: none">
<label>{{ 'enter verification code' | trans({}, 'clients') }}: <span class="required">*</span></label>
<input type="text" name="sms_code" id="sms_code" required maxlength="3" minlength="3" validate-msg="{{ 'you should enter the verification code' | trans({}, 'validators') }}" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-3 col-xs-12 pull-right">
<input type="submit" value="{{ 'register' | trans({}, 'clients') }}" id="register_btn" class="btn btn-theme btn-lg btn-block" style="width: 50% !important; margin: auto">
</div>
</div>
{{ form_end(form) }}
</div>
<!-- Form -->
</div>
<!-- Middle Content Area End -->
</div>
<!-- Row End -->
</div>
<!-- Main Container End -->
</section>
<div class="footer-area">
<div class="footer-copyright">
<div class="">
<a href="https://wa.me/966559661234" target="_blank" style="color: white;">
<div dir="ltr" style="direction: ltr;">
{{ 'support whatsapp contact' | trans}}
<br /><img src="{{ asset('w1.png')}}" width="40" />
+966-55-966-1234
</div>
</a>
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
$(function(){
//loop on all form input fields to set validation messages according to validate-msg attribute
$("form :input").each(function(){
var input = $(this);
var msg = input.attr('validate-msg');
input.on('change invalid input', function(){
input[0].setCustomValidity('');
if (! input[0].validity.valid) {
input[0].setCustomValidity(msg);
}
});
});
$('#send_verification_sms').click(function() {
$("#appbundle_users_registration_mobileNumber,#appbundle_users_registration_userIdentityInfo_identificationNumber,#userCaptcha").removeClass("red-bg");
//manually validating (on demand validation) form fields, except the sms_code field, before requesting a verification code on mobile
var block_send_sms= false;
$("form :input").not( "#sms_code" ).each(function(){
var input = $(this);
if (!input[0].checkValidity()) {
var msg = input.attr('validate-msg');
//manually marking the form field as invalid and immediately show validation message
input[0].reportValidity(msg);
block_send_sms= true;
}
});
//dont proceed if even a single field validation failed
if(block_send_sms){
return;
}
// clear error messages in order not to confused with the current sending verification SMS result
$("#mobile_num_div ul li").text( "" );
$("#id_num_div ul li").text( "" );
var mobileField = $('#appbundle_users_registration_mobileNumber');
if (mobileField[0].checkValidity()) {
// show remaining seconds count-down inside verification code button
var counter = 30;
var couterIntervalId = setInterval(function() {
counter--;
if (counter >= 0) {
$('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"+' ('+counter+')');
}
if (counter === 0) {
clearInterval(counter);
$('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}");
btn.prop('disabled', false);
}
}, 1000); // end counter
var mobileNumber = mobileField.val();
var btn = $(this);
check_ajax = false ;
captchaPhrase = '{{ app.session.get('captchaPhrase') }}';
btn.prop('disabled', true);
var request = $.ajax({
url:'{{ path('send_code_sms') }}',
type: "POST",
dataType: "json",
data: {
"mobileNumber": mobileNumber,
"identification": $("#appbundle_users_registration_userIdentityInfo_identificationNumber").val(),
"captchaPhrase": $("#userCaptcha").val()
},
async: true
});
request.done( function ( response ){
// check SMS Delivery Status
GetDeliveryStatus(response.mobileNumber,response.MessageID,couterIntervalId );
$("#verification_code").css("display", "block");
$("#register_btn").css("display", "block");
$("#appbundle_users_registration_mobileNumber,#appbundle_users_registration_userIdentityInfo_identificationNumber,#userCaptcha").removeClass("red-bg");
$(".errorCaptchaMsg").css("display",'none');
});
request.fail( function ( jqXHR ) {
//create a validation message container for mobile number field if none exist
if( $("#mobile_num_div ul li").length === 0){
$("#mobile_num_div").append('<ul><li></li></ul>');
}
//create a validation message container for id number (username) field if none exist
if( $("#id_num_div ul li").length === 0){
$("#id_num_div").append('<ul><li></li></ul>');
}
var mobile_validation_container= $("#mobile_num_div ul li");
var id_validation_container= $("#id_num_div ul li");
if (jqXHR.responseText == "illegal access") {
mobile_validation_container.text( "{{ 'illegal access' | trans({}, 'clients') }}" );
}
else if (jqXHR.responseText == "server error") {
mobile_validation_container.text( "{{ 'server error' | trans({}, 'clients') }}" );
}
else if (jqXHR.responseText == "invalid mobile number") {
mobile_validation_container.text( "{{ 'invalid mobile number' | trans({}, 'clients') }}" );
$("#appbundle_users_registration_mobileNumber").addClass("red-bg");
}
else if (jqXHR.responseText == "mobile number already registered") {
mobile_validation_container.html( "{{ 'mobile number already registered. click %{start_link}here%{end_link} to recover your password' | trans({'%{start_link}': '<a href=\'' ~ path("forgot_password") ~ '\'>', '%{end_link}': '</a>'}, 'clients')| raw }}" );
$("#appbundle_users_registration_mobileNumber").addClass("red-bg");
}
else if (jqXHR.responseText == "identification number already registered") {
id_validation_container.html( "{{ 'identification number already registered. click %{start_link}here%{end_link} to recover your password' | trans({'%{start_link}': '<a href=\'' ~ path("forgot_password") ~ '\'>', '%{end_link}': '</a>'}, 'clients')| raw }}" );
$("#appbundle_users_registration_userIdentityInfo_identificationNumber").addClass("red-bg");
}else if (jqXHR.responseText == "Error in captcha Phrase") {
$(".errorCaptchaMsg").css("display",'block');
$("#userCaptcha").addClass("red-bg");
}
else if (jqXHR.status == 403 || jqXHR.status == 404 ) {
//handle other unexpected errors
mobile_validation_container.text( "{{ 'error occured while sending verification code' | trans({}, 'clients') }}" );
}
clearInterval(couterIntervalId); //stop the send verification sms button counter
$('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"); //reset send verification sms button label
btn.prop('disabled', false);
});
} else {
var msg = mobileField.attr('validate-msg');
mobileField[0].reportValidity(msg);
}
});
});
function GetDeliveryStatus(mobileNumber,MessageID,couterIntervalId) {
$.ajax({
url: '{{ path('get_sms_status') }}',
type: "POST",
dataType: "json",
data: {
"mobileNumber": mobileNumber,
"MessageID" : MessageID,
},
success: function(result)
{
if(result == false){
setTimeout(function(){
GetDeliveryStatus(mobileNumber,MessageID,couterIntervalId)
}, 3000);
}else {
clearInterval(couterIntervalId); //stop the send verification sms button counter
$('#send_verification_sms').prop('value', "{{ 'verification code sent' | trans({}, 'clients') }}"); //set new label for send verification sms button
}
},
error: function(jqXHR) {
//create a validation container for mobile number field if none exist
if( $("#mobile_num_div ul li").length === 0){
$("#mobile_num_div").append('<ul><li></li></ul>');
}
var mobile_validation_container= $("#mobile_num_div ul li");
if (jqXHR.responseText == "invalid mobile number") {
mobile_validation_container.text( "{{ 'invalid mobile number' | trans({}, 'clients') }}" );
clearInterval(couterIntervalId); //stop the send verification sms button counter
$('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"); //reset send verification sms button label
btn.prop('disabled', false);
}
else if (jqXHR.responseText == "sms not delivered") {
mobile_validation_container.text( "{{ 'sms not delivered' | trans({}, 'clients') }}" );
}
clearInterval(couterIntervalId); //stop the send verification sms button counter
$('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"); //reset send verification sms button label
btn.prop('disabled', false);
}
});
}
$('#refresh').click(function() {
$.ajax({
url:'{{ (path('get_captcha_ajax')) }}',
type: "POST",
dataType: "json",
async: true,
success: function (data)
{
$("#captcha").attr('src',data.builder);
}
});
});
</script>
{% endblock %}