password input on modal makes modal disappear - html

The html for a modal popup for a login is below (html). When a customer tries to login they must click on each input field, put the username and then password and click the submit submit button. If they click "enter" after inputting the username or login, the modal popup disappears.
Is there a way to have proceed to being logged in when clicking "enter/return" after in the password input box instead of clicking on the "Login" button. I would like both to work-- login button and hitting return after typing in the password.
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-forward"></span> Login
</li>
</ul>
<div class="modal fade" id="customer-login" tabindex="-1" role="dialog" aria-labelledby="customer-login-header" aria-hidden="true">
<div class="modal-dialog">
<form action="https_link" method="POST" name="log-in">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h2 id="customer-login-header">Customer Login</h2>
<p class="hidden-xs">Log in below to receive access to your existing policies and quotes. The log in information was emailed to your after purchasing your policy or saving a quote.</p>
</div>
<div class="modal-body">
<fieldset>
<input type="text" class="form-control" id="cl_username" name="username" placeholder="Username?">
<br>
<input type="password" class="form-control" id="cl_password" name="password" placeholder="Password?">
</fieldset>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<input type="submit" class="btn btn-primary" value="Login">
</div>
<div class="modal-footer">
<p>Forgot your Username or Password?<br><a class="forgot-password" href="https://www.mexpro.com/client_login/retrieve_password.mhtml?aff_id=2149&lang=en&agtdst=www">Click here to Retrieve »</a></p>
</div>
</div>
</form>
</div>
</div>

Here is a possible solution: https://jsfiddle.net/99x50s2s/73/
When the user clicks on the Login button, alert will be displayed if either User Name or Password is left blank.
I have made minor changes in your HTML and used jquery as shown below,
HTML:
<button type='button' data-toggle="modal" data-target="#customer-login" data-backdrop="static">Click here</button>
<div class="modal fade" id="customer-login" tabindex="-1" role="dialog" aria-labelledby="customer-login-header" aria-hidden="true">
<div class="modal-dialog">
<form action="https://www.mexpro.com/client_login/do/login.mhtml?aff_id=2149" method="POST" name="log-in">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h2 id="customer-login-header">Customer Login</h2>
<p class="hidden-xs">Log in below to receive access to your existing policies and quotes. The log in information was emailed to your after purchasing your policy or saving a quote.</p>
</div>
<div class="modal-body">
<div id='error' class='alert alert-warning hide'></div>
<fieldset>
<input type="text" class="form-control" id="cl_username" name="username" placeholder="Username?"/>
<br/>
<input type="password" class="form-control" id="cl_password" name="password" placeholder="Password?"/>
</fieldset>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<input type="submit" class="btn btn-primary" value="Login" id="SubmitBtn"/>
</div>
<div class="modal-footer">
<p>Forgot your Username or Password?<br/><a class="forgot-password" href="https://www.mexpro.com/client_login/retrieve_password.mhtml?aff_id=2149&lang=en&agtdst=www">Click here to Retrieve »</a></p>
</div>
</div>
</form>
</div>
</div>
JS
$('#SubmitBtn').on('click', function(event){
var errorDiv = $('#error');
errorDiv.addClass('hide').empty();
var userName = $('#cl_username').val();
var password = $('#cl_password').val();
if ($.trim(userName) == '' || $.trim(password) == '')
{
errorDiv.removeClass('hide').append('User Name and Password is required');
event.preventDefault();
}
});

1.) Is there a way to make an error show up if they hit return without typing anything?
Yes. Handle the onSubmit event on the form and validate that you have entries in the fields you want.
2.) Is there a way to have proceed to next step when clicking "enter/return" -- i.e. cursor moves to the password/and submit takes
place?
Change the Login button from type="submit" to type="button" and write javascript code to handle the onClick event. By having it as type="submit" the browser automatically submits the form when the Enter key is pressed.
Bear in mind that many users expect the Enter key to submit a login form, not move them between fields. What you are trying to do goes against expected browser behavior.

Related

Use of tags to send information to a function

I'm pretty new to HTML5 and have inherited someone else's code, which turns out not to be working.
I have a site with 8 different categories and 'add to email list' buttons, one for each category.
We use formspree to create the form code and then connect with our marketing systems. Instead of integrating 8 different forms, the previous coder added one from as a function*, then referred to that function on each of the 8 buttons.
Edit:*Its not actually a function, what is below is the only code involved.
To determine which of the categories the form came from, its meant to pass over a tag, but it's that tag that is not working and I would appreciate help on.
<!-- Waitlist modal -->
<div class="modal fade" id="waitlist-modal" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title heavy-text" id="modal-label">Request Access</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="contact-form" action="https://formspree.io/email#gmail.com" method="POST" >
<div class="form-group">
<label for="full-name">Full name</label>
<input type="text" class="form-control" id="full-name" name="name" placeholder="Enter name">
</div>
<div class="form-group">
<label for="email-address">Email address</label>
<input type="email" class="form-control" id="email-address" name="email" placeholder="Enter email">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="incubator" name="incubator">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="ip-address" name="ip-address">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" id="submit-form" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
The below code is for each of the 8 category's join buttons.
<a href="#" data-toggle="modal" data-target="#waitlist-modal" data-id="entrepreneur" class="yellow-link">
<p class="yellow-text call-to-action" style="font-size: 0.7rem;">JOIN THE WAITLIST ➞</p>
</a>
As far as I understand, its meant to collect the full name and email address visibly, then the IP and the "incubator" [category] silently. All but the "incubator" tag works fine, which never passes over anything. In the links, the previous coder uses data-id="entrepreneur" [a category] for example, which doesn't seem right to me.

Submit form to websocket

I'm trying to submit some simple log in data to a server. All of the requests and functions are working great for "testuser." I want people to be able to submit their username and password for consideration to the server (it all gets encrypted, and I can't see it.)
I can see where the registration request submits generic data "testuser" for username and pass. But I have no idea how to get it to accept user login information instead.
<!--This is where I'm attempting a login form-->
<form action="/action_page.php">
<div class="imgcontainer">
<img src="img_avatar2.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<input type="checkbox" checked="checked"> Remember me
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" class="cancelbtn">Cancel</button>
<span class="psw">Forgot password?</span>
</div>
</form>
<!-- This is rock-solid code from the gamesparks API. Works flawlessly. -->
<button onClick='gamesparks.registrationRequest("testuser", "testuser", "testuser", registerResponse)'>Register</button>
<button onClick='gamesparks.authenticationRequest("testuser", "testuser", loginResponse)'>Login</button>
<button onClick='gamesparks.accountDetailsRequest(accountDetailsResponse)'>Account Details</button>
<button onClick='customEvent()'>Custom Event</button>
<button onClick='customEvent2()'>Custom Event 2</button>
<button onClick='testRT()'>Test RT</button>
<i>Special thanks to the awesome team at GameSparks!</i>
<div id="messages"></div>
<br/>
<br/>
All of my buttons work, spitting out data from my backend regarding "testuser." I know it works because I can alter my data and verify.
You'll notice "testuser" occupies three spaces for one of the onClicks. One is username, the other is password, and the third is displayname (in that order.)
Displayname can equal Username...if anyone wants extra credit.
But mostly, I want my modal to input the data and submit it for my buttons.
Again, I solved my own question! What I did was put my gamesparks function inside of another function. I learned this was called "nesting." I also defined variables as part of the onClick, which were then used in the function. The solution I used is below. Forgive my n00bish comments. But they help me learn.
<div class="container">
<h2>Click To Login</h2> <!-- This is a label above the button -->
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Martial Parks</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><img src="http://martialparks.com/wp-content/uploads/2017/10/cropped-mp_logo01-2.png" class="center-block img-circle logo-margin-negative"></h4>
</div>
<div class="modal-body">
<form>
<div class="row">
<div class="form-group col-sm-5 col-sm-offset-4">
<label class="sr-only" for="exampleInputAmount">Username</label>
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div>
<input type="text" class="form-control" id="username" placeholder="Username">
</div>
</div>
<div class="form-group col-sm-5 col-sm-offset-4">
<label class="sr-only" for="exampleInputAmount">Password</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-key"></i></div>
<input type="text" class="form-control" id="password" placeholder="Password">
</div>
</div>
<button type="button" class="btn btn-danger btn-block" data-dismiss="modal" onClick="login()">Login</button>
<!-- There is a line of code that closes the modal once the button is clicked: data-dismiss="modal" I've removed it from the register button. -->
<!-- Also, I can call up multiple functions using this format: onclick="doSomething();doSomethingElse();" -->
<button type="button" class="btn btn-danger btn-block" onClick="register()">Register</button>
<script>
function login() {
var usernameinput = document.getElementById('username').value;
var passwordinput = document.getElementById('password').value;
console.log(usernameinput);
console.log(passwordinput);
gamesparks.authenticationRequest( usernameinput, passwordinput, loginResponse);
}
function register() {
var usernameinput = document.getElementById('username').value;
var passwordinput = document.getElementById('password').value;
console.log(usernameinput);
console.log(passwordinput);
gamesparks.registrationRequest( usernameinput, usernameinput, passwordinput, registerResponse)
}
</script>
</div>
</form>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-sm-5 col-sm-offset-4">
<div id="messages"></div>
<br/>
<br/>
You need to manually grab each of your fields values. The most direct way is via document.getElementById and value:
document.getElementById( "username" ).value
In your example:
<button onClick='gamesparks.authenticationRequest( document.getElementById( "username" ).value, document.getElementById( "password" ).value, loginResponse )'>Register</button>
I would, however, suggest calling a function instead of inlining it:
<button onclick="login()">Login</button>
⋮
⋮ // Before </body>
⋮
<script>
const fetchValue = id => document.getElementById( id ).value;
function login() {
const username = fetchValue( "username" );
const password = fetchValue( "password" );
gamesparks.authenticationRequest( username, password, loginResponse );
}
</script>
Also1: You should never need to place an api secret in client-facing HTML/JavaScript.
Also2: Regarding your these lines:
<var username = username>
<var password = password>
These are invalid. <var> provides styling and nothing else. It looks like you are attempting to place JavaScript there? To do so, you need to either use <script> tags or event handlers, such as onclick.

form not rendering correctly in modal

I try to render a form with ajax and show it in a modal.
But the fom tags in the modal just appears next to eachother when i check the source code in my browser. How can I resolve this?
Here is my written code of the modal in:
<!-- Modal Edit client -->
<div id="editClient" 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">Edit Client</h4>
</div>
<div class="modal-body">
<form id="editClientForm" action="{{ path('client_details') }}" method="POST">
{{ form_widget(form) }}
<br />
<input type="submit" class="btn btn-success" value="Save changes">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</form>
</div>
</div>
</div>
</div>
The modal opens with the form fields and closes when cancel is clicked.
Here is the source code from the browser:
<div class="modal-body">
<form id="editClientForm" action="/ruben/avr_symfony/web/app_dev.php/configurator/client/details" method="POST"></form>
=> here comes all the form fields and buttons.
</div>
As you can see, it closes the form tag before putting in the form fields.
I found the problem.
I hade a closing table tag wich i typed as < table > instead of < / table > in my code above the modal code.
This solved the issue.

can't set html form input file from modal / popover

I have an html form. For the image file input, I have a modal that pops up to set the input field but also allow the user to crop. When I submit the form, it says the input field is empty.
Here is the form with modal embedded:
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<h5>First Name</h5>
<div class="form-group">
{{ form.first_name|attr:"class:form-control"|attr:"placeholder:Enter Your First Name" }}
</div>
<h5>Profile Image (Square Image)</h5>
<div class="form-group">
<button data-toggle="tk-modal-demo" data-modal-options="slide-down" class="btn btn-primary">Upload</button>
</div>
{{ form.crop_coords }}
<!-- Create the modal dynamically via Handlebars -->
<script id="tk-modal-demo" type="text/x-handlebars-template">
<div class="modal fade" >
<div class="modal-dialog">
<div class="v-cell">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Upload Profile Image</h4>
</div>
<div class="modal-body container">
<div class="max-width: 560px;">
<div>
<img style="max-width: 100%;" id="tempImg" src="{% static 'app/images/default-team-large.jpg' %}"/>
<h5>Profile Image (Square Image)</h5>
<div class="form-group">
<input id="id_profile_image2" type="file" name="pic" accept="image/*">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Save</button>
</div>
</div>
</div>
</div>
</div>
</script>
<div class="form-group margin-none">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-sm btn-primary" href="nml-home.html"> Confirm User Changes<i class="fa fa-fw fa-arrow-right"></i></button>
</div>
</div>
</form>
To test, I click the data-toggle button to popup the modal. It then opens the tk-modal-demo which has a file upload. I upload an image and then I click the save button in tk-modal-demo to dismiss the modal. Then I submit the form with the bottom form submit button. My validator says that the field is empty.
How can I set this required form field from the modal and have it populated when I submit?
It might be that the modal input elements are not created inside the <form> element. Input elements outside of this container will not be sent to the server upon submit.
You can first check out what is actually transmitted with the development console of your browser (in Chrome it's the Network tab). If your fields aren't there, then you might need to write a bit of Javascript, to either:
copy the contents of the input elements inside the modal to hidden fields within the form, for using the regular submission process
or, hijack the submit event and manually compose which fields you want to send

how to pass data-target id to another jsp bootstrap

I am currently facing an issue that I want to display the dialog box using bootstrap by clicking on the button. I made the dialog box in html (.jsp), and the submit button in another .jsp but, after I click on the button, it just displays blank page instead of the dialog box.
SubmitForm.jsp
<form id="cusPayment" name="cusPayment" method="post" action="CusConfirmPayment.jsp">
<input id="accid" name="accid" type="hidden" value="<%=accno%>">
<input id="statid" name="statid" type="hidden" value="<%=ref%>">
<input id="amt" name="amt" type="hidden" value="<%=amt%>">
<input id="lflag" name="lflag" type="hidden" value="E">
</form>
<a data-toggle="modal" data-target="#loginModal" href="#" class="btn-green pay-btn" id='paynow'>Pay Bill Now<i class="fa fa-chevron-right"></i></a>
<div>
</div>
$(document).ready(function() {
$(".paynow,#paynow").click(function(event){
event.preventDefault();
$("#cusPayment").submit();
});
CusConfirmPayment.jsp
<div class="modal fade pay-now" id="loginModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-top">
<div class="modal-content self-content">
<div class="modal-header remove-border">
<button type="button" class="close-btn" data-dismiss="modal">×</button>
</div>
<div class="modal-body popup-copy">
<div class="col-sm-10 popup-title">Confirm Payment Amount</div>
</div>
</div>
</div>
</div>
I have made a plunkr for you to try
I had to disable the submit function of your javascript because you don't want to submit the form here you just want to show the modal window. If you do it this way you don't need to pass variables via hidden inputs either. it should be on the same page.
In the plunkr I have removed the other page and added its content on the same page so it can see it.
<form id="cusPayment" name="cusPayment" method="post" action="#">
<input id="accid" name="accid" type="hidden" value="<%=accno%>">
<input id="statid" name="statid" type="hidden" value="<%=ref%>">
<input id="amt" name="amt" type="hidden" value="<%=amt%>">
<input id="lflag" name="lflag" type="hidden" value="E">
</form>
<a data-toggle="modal" data-target="#loginModal" href="#" class="btn-green pay-btn" id='paynow'>Pay Bill Now<i class="fa fa-chevron-right"></i></a>
<div>
</div>
<div class="modal fade pay-now" id="loginModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-top">
<div class="modal-content self-content">
<div class="modal-header remove-border">
<button type="button" class="close-btn" data-dismiss="modal">×</button>
</div>
<div class="modal-body popup-copy">
<div class="col-sm-10 popup-title">Confirm Payment Amount</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$("#paynow").click(function(event) {
event.preventDefault();
//$("#cusPayment").submit();
//this submits the page, you want to show a modal window not another page
})
})
</script>