R
Reactiflux

pepega1337. – 21-16 Aug 15

pepega1337. – 21-16 Aug 15

Ppepega페페가8/15/2023
Hi, I have a form that calls my PHP script on the server How can I prevent the page from re-directing to mypage.com/login.php when the submit button is pressed? When I use e.preventdefault() it's not even called obviously, but I want to stay on the same page.. <form action="login.php" method="POST" onSubmit={(e) => handleSubmit(e)}>
Gghardin1378/15/2023
You’d need to call PreventDefault on the event object
Ppepega페페가8/15/2023
Yeah ofc im doing that but when I preventDefault then my form is not even submitted, there is no api call not even in Fiddler, but when I remove preventDefault then it works... But it redirects me to mypage.com/login.php which i dont want... If I try to remove the form and make it a div, and manually fetch the api on button click then again it doesnt even try fetching, I have no idea tbh
Gghardin1378/15/2023
You’d have to submit it manually Like with fetch/axios Without PreventDefault it’s going to do what a form does in html which is do a full request And your js isn’t going to have time to do anything
Ppepega페페가8/15/2023
Fixed it all with manual fetching, ty a lot
SScriptyChris8/16/2023
And you should keep using <form> for forms - <div> is not the appropriate element to wrap a form (e.g it doesn't support built-in validation)
UUUnknown User8/17/2023
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

pepega1337. – 21-16 Aug 15

Join Server