Not going to specific URL this.router.navigate() in AngularJs - html

I am making a registration form in angularJS and I use the bootstrap template for design.
This is my form and path to the form page is http://localhost:4200/signup
<form method="post" (submit)='register(username.value,email.value,password.value)'>
<div class="form-group">
<label for="name">Full name</label>
<input type="text" id="name" #username class="form-control" placeholder="Enter your name">
</div>
<div class="form-group">
<label for="remail">Email address</label>
<input type="email" id="remail" #email class="form-control" placeholder="Enter email">
</div>
<div class="form-group">
<label for="rpassword">Password</label>
<input type="password" #password class="form-control" id="rpassword" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
But the problem is that it when I click submit button or hit enter, It automatically refresh the page and shows Cannot POST /signup.
As this is my component.ts file
register(name,email,password) {
this.userService.registerUser(name, email, password).subscribe(data => {
if (data.success) {
console.log('reaches');
this.router.navigate(['user']);
} else {
console.log('error');
}
});
}
It is trying to go to the /signup path in post method but in component.ts file I give the path to '/user'
How can it automatically go-to /signup? And how to stop that.

Your form is trying to post data to a server. It sounds like you don't have a server which can handle the post, so you get the error.
To fix the problem, you need a server which can handle the form post.

Related

nodejs not listening to post requests and returns error 505

i'm just a begineer to nodejs and I am trying to complete this project and i have been stuck since almost 2 days and i'm unable to figure this out.
it seems nodejs is not listening to POST requests, I am console logging but it instead returns 405 error page.
Here's the code:
import express, { urlencoded } from 'express';
import path, {dirname} from 'path';
import { fileURLToPath } from 'url';
import mysql from 'mysql';
const app = express();
app.use(express.json());
app.use(urlencoded({ extended : true}));
app.use(express.static('public'));
// const __dirname = path.dirname(fileURLToPath(import.meta.url));
app.post('/' , (req, res)=>{
console.log(req.body);
// res.sendFile(path.join(__dirname ,'/public/index.html'));
});
app.listen(5501, ()=>{
console.log('Server is running at port 5501')
})
<form action="/" method="post" id="cont-form">
<h1 class="contact-h1">Contact us</h1>
<div>
<input type="text" name="name" placeholder="Your name" autocomplete="off">
</div>
<div>
<input type="text" name="subject" placeholder="Subject" autocomplete="off">
</div>
<div>
<input type="email" name="email" placeholder="Email" autocomplete="off">
</div>
<div>
<label for="name">
<textarea name="message" placeholder="Type your message" cols="30" rows="10"></textarea>
</label>
</div>
<input type="submit" name="submit" id="submit-ms" value="Send message">
</form>
<div class="buy">
<div class="quantity">
<i class="fa-solid fa-xmark close-buy"></i>
Select Quantity
</div>
<form action='/buy' method="post" >
<div class="inputs">
<div class="buy-input-div" style="margin-top:16px">
<box-icon name='user'></box-icon>
<input type="text" class="buy-input" name="title" id="title-text"></div>
<div class="buy-input-div" >
<box-icon name='user'></box-icon>
<input type="text" class="buy-input" placeholder="Full Name" name="fullname" id="person-name"></div>
<div class="buy-input-div">
<box-icon name='phone'></box-icon>
<input type="text" class="buy-input" placeholder="Phone Number" name="phone" id="phone"></div>
<div class="buy-input-div">
<box-icon name='envelope'></box-icon>
<input type="text" class="buy-input" placeholder="Email" name="email" id=""></div>
<div class="buy-input-div">
<box-icon name='building'></box-icon>
<input type="text" class="buy-input" placeholder="Address" name="address" id=""></div>
<div class="buy-input-div">
<box-icon name='plus'></box-icon>
<input type="number" class="buy-input" placeholder="Quantity" name="quantity" id="">
</div>
<button class="buy-btn">Buy</button>
</div>
</form>
</div>
my file structure:
--root
--node_modules
--public
--index.html
--AdminPanel.html
--styles.css
--script.js
--index.js
--package-lock.json
--package.json
This is how it looks like:
You've got only one endpoint using POST method. Browsers sends only GET requests. (405 means Method not allowed).
You need to define a GET endpoint which will serve the html code. And in browser you have to access that endpoint. When you'll press the submit from you server html it will send a POST request.
Edited: If you access that file statically (opening the html file in a browser) then you need to specify in action property of form tag the full address, since / will simply try the location on your machine

How does this HTML block the auto insertion of my email address from chrome?

At first I thought it was some jerk move to make me type my username for added "security" on top of 2FA so I decided to fix it with tampermonkey and remove the autocomplete="off" attribute only to discover that there wasn't one.
Why does Chrome not offer to autofill the email input in this form? This is a link to the site.. But this is the form that is blocking autocomplete on the email address.
<form method="post" class="form-horizontal">
<h1 class="paste-page-header">Log in</h1>
<div class="form-group">
<div class="col-md-24">
<label class="paste-input-label">Email</label>
<div class="paste-input-wrapper">
<input type="text" id="email" name="email" placeholder="Email" tabindex="1" required="true" class="paste-input sl_whiteout" autofocus="autofocus" maxlength="255">
</div>
</div>
</div>
<div class="form-group col-md-24">
<button role="login-button" type="submit" tabindex="2" class="paste-primary-button" data-loading-text="<i class='icon icon-spinner icon-spin'></i>" value="Log in">Next
</button>
</div>
<span class="paste-text">Don’t have an account yet? Sign up for free.</span>
<input inert="" readonly="true" type="password" id="password" name="password" tabindex="50" style="opacity: 0.02;" aria-label="This is a hidden password field for compatibility with password managers. Please ignore this field.">
<input type="hidden" name="g" value="/console/sms/dashboard?" class="sl_whiteout">
<input type="hidden" name="t" value="182b71c36e3bb0a0a788ab671fbe875c7b46602de5f49fb3e441645b8848a76a" class="sl_whiteout">
<input type="hidden" name="CSRF" value="2869689c41323f2456ec6558c8ee7f3e4c409eda3bbed69bf10228f752a293e4" class="sl_whiteout">
</form>
After you type your email address, it will allow you to autocomplete the password, it's just this field that is a problem. And I tried this:
> x = document.getElementById('email')
<input type=​"text" id=​"email" name=​"email" placeholder=​"Email" tabindex=​"1" required=​"true" class=​"paste-input sl_whiteout" autofocus=​"autofocus" maxlength=​"255">​
> x = document.getElementById('email')
x.autocomplete
''
So, they aren't disabling it with JS (at least not in any way that I can see.....
I'm asking so that I don't make this mistake on any of my sites and because I'm really curious how they pulled this off.

how to auto fill like #gmail.com in html form

i have a form where every email is registered with #scoops.com but every time i have to enter #scoops.com i want that user just enter email name and #scoops.com auto fill and it will also show at the end of input field ? here it is my code
<div class="form-group" autocomplete="off">
<label>Email <span style="opacity: 0.5; font-style: italic;">(Required)</span></label>
<input autocomplete="nope" type="text" name="email" id="email" class="form-control input-lg"
placeholder="Enter Email" name="name" required=""/>
<span id="error_email"></span>
#if($errors->has('email'))
<div class="alert alert-danger">
{{ $errors->first('email') }}
</div>
#endif
</div>
i want something like this
Since you use Bootstrap: Try to wrap your mail input into an Inputgroup.
And then append the mail ending(by grouping your inputs). Also im not sure if 'autocomplete="nope"' is a state for this attribute. You should consider "off" if nope means no.
<div class="input-group">
<input autocomplete="off" type="text" name="email" id="email" class="form-control input-lg" placeholder="Enter Email" name="name" required=""/>
<div class="input-group-append">
<span class="input-group-text">#scoops.com</span>
</div>
</div>
Adding to what´s been said above, you can do something like the code below to submit the user-typed value appended with whatever text you want:
<input id="myInput">
<button onclick="submit(document.getElementById('myInput').value)"></button>
<script>
function submit(inputValue) {
const email = inputValue + "#scoops.com"
// insert here the code (like a POST request) to send the 'email' constant to wherever you want
}
</script>

Unable to submit form to freecodecamp mock url

I'm unable to submit the form
I've checked my code thoroughly for hours and looked at posts on freecodecamp forums but it seems to me I still cannot submit the form and I can't pinpoint the problem.
<form action="https://www.freecodecamp.org/email-submit" id="form">
<div class="email-box">
<label for="email">Email: </label>
<input type="email" id="email" name="email" placeholder="Enter your email here.." required>
</div>
<div id="submit-box">
<input type="submit" id="submit" name="submit">
</div>
</form>
When I click the #submit element, the email is submitted to a static page (use this mock URL: https://www.freecodecamp.com/email-submit) that confirms the email address was entered (and that it posted successfully)
The error states:
AssertionError: The #email input should have a name attribute : expected false to equal true
So, add name attribute:
<input type="email" placeholder="Enter email address"id="email" name="email" required><br>
For any help check here.

Chrome warning "[DOM] Password forms should have (optionally hidden) username fields for accessibility" in console even with hidden username field

When visiting the "reset password" route of my single-page app and looking at the Chrome browser console, I am greeted with the follwing warning:
[DOM] Password forms should have (optionally hidden) username fields for accessibility: (More info: goo.gl/9p2vKq)
Helpfully, the html of the form in question is also printed to the console in the next line, and quite clearly contains a hidden username field:
<form data-ember-action data-ember-action-436=​"436">​
<div class=​"form-group">
<label for=​"newpasswordone">​Password​</label>​
<input type=​"password" autocomplete=​"new-password" placeholder=​"Enter your new password" id=​"ember437" class=​"form-control ember-text-field ember-view" data-op-id=​"0">​
<label for=​"newpasswordtwo">​Password (again)​</label>
​<input type=​"password" autocomplete=​"new-password" placeholder=​"Re-enter your new password" id=​"ember438" class=​"form-control ember-text-field ember-view" data-op-id=​"1">​
<input type=​"hidden" name=​"username" autocomplete=​"username" value=​"a_b">
​</div>​
<button disabled type=​"submit" class=​"btn btn-default">​Reset password​</button>​​
</form>​
I tried some minor variations -- unhiding the username field, marking it readonly, moving it outside the div -- without affecting the warning.
How does Chrome expect to be served the username?
Problem occurs with Chrome 63 and 64.
I had the same problem. After some digging, I found that it needs to be an input element with the type text. By "optionally hidden" they mean that you may hide it with CSS.
If you just add an input with the name email or username chrome gives you another warning saying that input elements should have autocomplete attributes. So this is what I came up with to fix these errors:
<input
type="text"
name="email"
value="..."
autocomplete="username email"
style="display: none;"
>
You will need to manually render the actual username or email into the elements value attribute.
Also, keep in mind that inline styles are not a very good practice.
Use the hidden attribute instead of type="hidden"
<input hidden type="text" autocomplete="username" value="{{...}}">
I had this same situation.
Everything seemed be ok but I still got this verbose.
On my case helped me a relocate this userName input from end of form to begin of that.
It was my code before my changes:
<form id="changePass">
<div class='modal-dialog'>
<input type="password" class="form-control" id = "changePasswordOldPassword" autocomplete="current-password"/>
<input type="password" class="form-control" id = "changePasswordNewPassword" autocomplete="new-password"/>
<input type="password" class="form-control" id = "changePasswordNewPassword2" autocomplete="new-password"/>
<div class="modal-footer">
<button type="button" id="change-password-ok-button">Ok</button>
<button type ="button" data-dismiss="modal">Close</button>
</div>
</div>
<input id="userName" name="username" autocomplete="username" value="">
</form>
And this is current code:
<form id="changePass">
<input id="userName" name="username" autocomplete="username" value="">
<div class='modal-dialog'>
<input type="password" class="form-control" id = "changePasswordOldPassword" autocomplete="current-password"/>
<input type="password" class="form-control" id = "changePasswordNewPassword" autocomplete="new-password"/>
<input type="password" class="form-control" id = "changePasswordNewPassword2" autocomplete="new-password"/>
<div class="modal-footer">
<button type="button" id="change-password-ok-button">Ok</button>
<button type ="button" data-dismiss="modal">Close</button>
</div>
</div>
</form>
you must put the input tag inside another tag for example:
<form action="">
<div>
<input type="text" autocomplete="username">
</div>
<div>
<input type="password" autocomplete="password">
</div>
<div>
<input type="password" autocomplete="password">
</div>
I had this same situation in VueJs when i use rendering conditional v-if v-else and i try put input tag inside new tag and it's work for me
Though I know that this question is quite old but thought maybe it may be useful for someone .I also faced the same issue with my React app update user password and this worked for me just above the password fields without label.Excuse me for writing the React way .
<input hidden type='text' name='email' autoComplete='email' />
Basic usage :-
<form>
<input hidden type='text' name='email' autoComplete='email' />
<label htmlFor="oldPass">Enter your current password</label>
<input id="oldPass" type="password" />
<label htmlFor="newPass">Enter your new password</label>
<input id="newPass" type="password" />
</form>
After reading Jonas comment I rebuilt the project and the warning went away
I had the same warning showing in the console and this is how I fixed it:
<input hidden autocomplete="username" name="username" type="text" value="{{..}}"/>
<input hidden autocomplete="email" name="email" type="text" value="{{..}}"/>