I have the following:
a login route in app.js that sets success: false if invalid password or username.
but for some reason in the actual login html the authentication process is completely ignored.
Am I missing something?
You are using an href. You need to have a button of a submit type to submit the form.
Change your <div class="form-login" ng-submit="login()"> line to:
<form class="form-login" ng-submit="login()">. That will tell Angular this is a form. Then, change your closing </div> to </form> as well.
<span class="group-btn">
<button type="submit" class="btn btn-primary btn-md">
login <i class="fa fa-sign-in"></i>
</button>
</span>
Related
I'm trying to log into a site using Phantom JS so I can keep on top of my suppliers prices.
Username and password are being entered but the login button is not pressing.
If the login button is a <input> instead of <button>, .click() should work, however I cannot find a way to press the <button>.
The Log in form has no ID,NAME or ACTION to target a submit.
If anyone knows a solution I would be very grateful
thanks
Phantom JS
//username entered automatically on load
document.getElementById("password").value="1234";
document.getElementById('btn-login').click();
Login Form
<form onsubmit="return false;" method="post">
<fieldset class="customer-login">
<div class="form-group">
<label for="name">Email Address</label>
<input type="username" class="form-control" id="username" placeholder="Enter your email address">
</div>
<div class="form-group">
<label for="name">Password</label>
<input type="password" class="form-control" id="password" placeholder="Enter your password">
</div>
<button type="submit" id="btn-login" class="btn btn-primary btn-block">
Log In
</button>
<hr>
<button type="button" id="btn-signup" class="btn btn-default btn-block">
Sign Up
</button>
<button type="button" id="btn-reset" class="btn btn-default btn-block">
Forgotten your password?
</button>
</fieldset>
</form>
result after running script
UPDATE
document.getElementsByClassName('btn btn-primary btn-block')[0].click();
works however as nothing returns and it redirects, it stops the program before it goes back to the home page logged in.
Has anyone got a solution to get the program to wait (when it doesnt know its redirecting.)?
i tried
do { phantom.page.sendEvent('mousemove'); } while (page.loading);
When submitting the form, nothing was returned, so the program stopped.
The program did not wait for the page to load as it took a few seconds for the redirect to begin.
telling it to move the mouse until the URL changes to the home page gave the browser as much time as it needed to change. then telling it to wait for the page to finish loading allowed the page to full load before the content was grabbed.
page.evaluate(function () {
document.getElementsByClassName('btn btn-primary btn-block')[0].click();
});
do { phantom.page.sendEvent('mousemove'); } while (page.evaluate(function()
{
return document.location != "https://www.bestwaywholesale.co.uk/";
}));
do { phantom.page.sendEvent('mousemove'); } while (page.loading);
I have create a simple form validation which uses validator.js
What actually happens after the user presses the register button data is sent and user stays on the same page.
What i really want to get is that after user pressing register button it will be redirected to other page that is info.html which shows the message thank you for registration, Check mail for confirmation etc.
Here is the button I want to have a redirect function
<form>
<div class="form-group">
<button class="btn btn-primary" type="submit">
Submit
</button>
</div>
</form>
I tried this in the following way
<div class="form-group">
<button class="register100-form-btn">
<a class="fa fa-long-arrow-right m-l-7" href="/info.html">Submit</a>
</button>
</div>
it's now redirecting it to the other page but without a check validation form
All fields can remain empty which makes no sense for register form.
one way would be to add a click event listener to the button and redirect to your desired view once clicked. Have your html as:
<div class="form-group">
<button id="submit" class="btn btn-primary" type="submit">
Submit
</button>
</div>
and then the following JS,
document.getElementById("submit").addEventListener("click", function(event){
let url = "http://mybaseurl/info.html"
window.location.href = url;
});
I have these html button:
<form ngNativeValidate (ngSubmit)="onSubmit()" #add_form="ngForm">
<button class="btn btn-primary " type="submit[disabled]="!add_form.valid">ADD</button>
<button class="btn btn-default" (click)="back()">Back</button>
</form>
And I obtain this warning in the console:
Form submission canceled because the form is not connected
Anyone can help me to resolve this warning?
For your Back button, add type="button" to the declaration, like this:
<form ngNativeValidate (ngSubmit)="onSubmit()" #add_form="ngForm">
<button class="btn btn-primary " type="submit[disabled]="!add_form.valid">ADD</button>
<button type="button" class="btn btn-default" (click)="back()">Back</button>
</form>
What's happening, is that Angular interprets the second button as another submit button, and so you're effectively navigating in the middle of a submit. That's why the messages tells you that form submission is being cancelled.
i am trying to destroy session of a user by clicking logout button it works there is a problem I have to press twice in order to log out/destroy the session.
any kind of help will be appreciated.
using following code
<form role="form" method="post">
<div class="pull-right-container">
<i class="icon fa fa-user">
<input type="submit" value="logout" class="btn btn-danger" name="logout"
onclick="sessionend()" >
</i>
</div>
</form>
<script type="text/javascript">
function sessionend()
{
<?php
if (isset($_POST["logout"]))
{
session_destroy();
}
?>
}
</script>
There is no need for onclick() in submit button. Try the following code:-
<?php
if (isset ( $_POST ["logout"] )) {
session_destroy();
$redirectPageUrl= "http://xxxx/home.php";
header("Location: ".$redirectPageUrl);
}
?>
<form role="form" method="post">
<div class="pull-right-container">
<i class="icon fa fa-user">
<input type="submit" value="logout"
class="btn btn-danger" name="logout" />
</i>
</div>
</form>
You might need to unset $_SESSION variables, if you have any, then call the function session_destroy(). After doing this, you can try and test for any session variables and possibly add a redirection page.
Try with this code. You need to call the session_unset() and session_destroy(), I've also added the action to your form, make sure that it will point to the same page where the form is located. Assuming that your page is named logout.php, your form action will point to logout.php. See the code below as an example.
<?php
if (isset ( $_POST ["logout"] )) {
session_unset();
session_destroy();
header("Location: https://yourpage.com");
}
?>
<form role="form" method="post" action="logout.php">
<div class="pull-right-container">
<i class="icon fa fa-user">
<input type="submit" value="logout"
class="btn btn-danger" name="logout" />
</i>
</div>
</form>
Just to make you clear what happens:
When you open your page the first time, PHP will be immediately executed.
In your case checking for $_GET. Since at this moment $_GET has no values your if block will not be excecuted and PHP prints out nothing.
Your onclick Function look at the moment like this. Blank with no functionality. Take a look at the executed code after opening the first time.
OnCkickFn (){
}
When you submit now, I think your page is reloading, keep the blank Function in mind, but now having the $_GET value.
PHP is now executing immediately your session destroy, but returning nothing. Your onClickFn is still empty
Now you are thinking that your first click did nothing, but in the back PHP did it before.
When you now click once again your onClickFn then the page reloads again an you are seeing the result of session_destroy from the last time!
Please use the example of #nandal, (fast and easy) this is the way it is working, or change your code to make an API call (more complex)
I am new to angular js and I am developing a form which has many input fields and two buttons- one for cancel and another one for submitting the form.
i am having a ng-submit="" on the form tag to recognize if the form is submitted and show some error messages.
Problem i am facing is when i click on enter 'cancel' button is triggered. How do i prevent this?
I tried adding type=input on the button but it does not work.
<button type="button" ng-click="function">Cancel</button>
I cannot change the button tag to input tag as i am applying some styles and i am losing them if i change the tag.
How do I achieve this?
Thanks in advance.
UPDATE:
below is the code for button.
<div class="button-group-right" style="width:49%; float:left">
<button class="btn btn-large btn-tertiary btn-right" ng-click="subnmitPage()">
<span class="btn-text">
<span class="btn-text-container">Submit</span>
</span>
<span class="btn-icon">
<i class="navigateright button-icon"></i>
</span>
</button>
</div>
i fixed it by adding $event in my function and saying preventDefault().
code below.
in html:
<button ng-click="subnmitPage($event)"/>
and in controller
$scope.subnmitPage=function(event){
event.preventDefault();
}