PHP show/hide form in a website maker platform - javascript

I am using this site to make a website. This website maker is easy to use because the elements are just drag and drop but you can also add your HTML code.
In one of my pages, I have inserted an HTML code which is a form. The form's process is to ask for a password, then with the GET method, it will check if the password is correct, if correct, another form will show. I use PHP language to process the checking of password. The problem that I encounter is, when the right password is entered, it does not show anything, even if I have put the right id. This is the preview site
HTML Code
<form name="password" id="password" style="width:300px;" method="get" action="http://link.co/transfer/password_protect_transfer.php">
<label for="password">
Enter password:
</label>
<input type="password" id="1151457790" name="password" required=""/>
<input type="submit" id="submit" name="submit" value="Submit"/>
</form>
<form name="transfer" id="transfer" method="POST" action="http://link.co/transfer/transfer.php" style="display: none;">
<select id="affAccts" name="affAccts" required="">
Select an account:
<option value="A">
A
</option>
<option value="B">
B
</option>
<option value="C">
C
</option>
</select>
<br/>
<label for="name">
Enter name:
</label>
<input type="text" id="name" name="name" required=""/>
<input type="submit" value="Join"/>
</form>
PHP
<?php
$pw = $_GET['password'];
if($pw == "Admin1234"){?>
<script type="text/javascript">
$('#password').hide();
$('#transfer').show();
</script>
<?php}else{?>
<script type="text/javascript">
alert("Access Denied!");
location.reload();
</script>
<?php
}
?>

Judging only from the preview site, I say it's a problem with the platform you are using. Once you submit a form with get method you should see the values in the URL. There is no change in the URL when I submit the password.

Part of the issue you're facing is that when the password is incorrect, you're calling location.reload(); to reload the page. GET is putting the password in the URL, so every time the page reloads, it will re-evaluate whether or not it's correct and reload again (because it's still incorrect). A loop.
I would suggest changing the form method from GET to POST.
To narrow down the issue further, simplify the JavaScript a bit. E.g. instead of calling some jQuery functions:
<script type="text/javascript">
$('#password').hide();
$('#transfer').show();
</script>
Maybe just try some simple alert statements (e.g. alert('password good');) until you know the right code is firing in the right places. I copied your code to a local test machine and I had to make quite a few adjustments to get things to work right.

You have some flaws in your PHP: if/else sets don't work outside of the PHP, they need to terminate. For example:
<?php
$pw = $_GET['password'];
if($pw == "Admin1234"){
echo '
<script type="text/javascript">
$("#password").hide();
$("#transfer").show();
</script>
';
}else{
echo '
<script type="text/javascript">
alert("Access Denied!");
location.reload();
</script>
';
}
?>

Related

Auto Login html for live.com account

Good Evening Everyone. I need some help with an auto login procedure.
Specific Question = How can I get initiate a 2nd form action within the same html page? I also need to create a 5 second delay so the 1st action can complete
The Result I'm looking for = I want to double click on saved .html file and then get automatically logged into my email
The Website =
HTML Code:
https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1489346474&rver=6.7.6640.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fauthRedirect%3dtrue%26nlp%3d1&id=292841&CBCXT=out&fl=wld&cobrandid=90015
How did I get this URL? = msn.com>clicked on outlook>clicked on sign in
The problem =
I have created a javascript function within a saved html page and I can get past the login in page. The issue is that I cannot get my password to be correctly placed in the password field and the submit button to work. For my live.com account it is a 2 page authentication. The first page is where you place your username and click next and then the 2 page is where you enter your password and click sign in.
What I have tried =
(1)Because there is a placeholder text, I've tried a POST method, but
I can't get it to work. POST would be best, but I can't figure it
out.
(2) I've tried get element by id and that does not work because
my password is just written on top of the placeholder text and does
not get replaced
(3) CURRENT STATE. What I have written now is 2 form
actions. The 1st form action (logonForm) enters my username and the
2nd form action (passForm) is supposed to enter my password and then
log me in. Is 2 form actions the best way to accomplish this?
WHAT I HAVE SO FAR =
<html>
<body style="display: none">
<form action="https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1485483982&rver=6.7.6640.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1&id=292841&CBCXT=out&fl=wld&cobrandid=90015" method="POST" name="logonForm" ENCTYPE="application/x-www-form-urlencoded"
id="loginForm">
<input type="hidden" name="destination" value="https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1485483982&rver=6.7.6640.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1&id=292841&CBCXT=out&fl=wld&cobrandid=90015">
<input type="hidden" name="username" value="this is my username#live.com" >
<input type="hidden" name="passwd" value="this is my password">
<input type="hidden" name="flags" value="4">
<input type="hidden" name="forcedownlevel" value="0">
<input type="radio" name="trusted" value="4" class="rdo" checked>
<input type="hidden" name="isUtf8" value="1">
</form>
<form action="https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1485483982&rver=6.7.6640.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1&id=292841&CBCXT=out&fl=wld&cobrandid=90015" method="POST" name="passForm" ENCTYPE="application/x-www-form-urlencoded"
id="passwordForm">
<input type="hidden" name="destination" value="https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1485483982&rver=6.7.6640.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1&id=292841&CBCXT=out&fl=wld&cobrandid=90015">
<input type="hidden" name="username" value="This is my username#live.com" >
<input type="hidden" name="passwd" value="this is my password">
<input type="hidden" name="flags" value="4">
<input type="hidden" name="forcedownlevel" value="0">
<input type="radio" name="trusted" value="4" class="rdo" checked>
<input type="hidden" name="isUtf8" value="1">
<input type="hidden" name="data-bind" value="this is my password">
</form>
<script type="text/javascript">
document.forms["logonForm"].submit();
document.forms["passForm"].submit();
</script>
</body>
</html>
I am a new student to java and I'm ambitious about coding, developing, and learning. I just can't seem to get this figured out. I'm sure my html/java looks like a jumbled mess but that's because I've been trying all types of things to see if anything would work and I got excited when i was able to get past the login page.
I do apologize for the long post, I just wanted to get as much info as I have out. I'm trying to be as specific as I can be. This is my first post in stack overflow and I couldn't be more excited to be part of this community.
Thanks in advance for your help!
TechStudent01
You cannot do this.
Once a <form> is sent (either as GET or POST), which is a synchronous action, your script basically stops executing, and unless the targeted webpage fails to load (and the browser doesn't display an error page, which can happen with severe network issues), .submit() is a no-return function : if it executed properly, you're not on the same page any more.
Letting you run scripts from a webpage onto a newly loaded other would be the open door to loads of security issues, so this, by design, is not allowed. As such, you can't get your password to be typed in automatically into the log-in form.
In addition, Microsoft account forms are subject to CSRF verification, preventing you from logging in from a page not sent by Microsoft, i.e. your HTML file.
Also, what you are trying to achieve is exactly the purpose of password managers that provide some sort of browser integration.

Display and Change HTML input fields

I have a PHP file where username and age are getting set. All I am trying to do right now is get their value to display it in an alert. I will be changing the values later (hence why you see the method="POST"). Right now I just want to grab the values and see what they are. But it looks like I am missing something or doing something wrong. Ultimately, I want to be able to change username, and age, and submit the form without user interaction (this is where I am really stuck). I'd appreciate any advice. Thank you very much.
In loaduser.php I have done the following:
<input id="username" type="text" name="username" value="<?php echo $username ?>">
<input id="age" type="number" name="age" value="<?php echo $age ?>">
Then in change.html I am doing the following:
<body onload="document.forms[0].submit()">
<form action="/loaduser.php" onsubmit="" method="POST">
</form>
<script type="text/javascript">
function submitform()
{
alert(document.getElementById('username').value);
alert(document.getElementById('age').value);
}
</script>
</body>
My hunch is that I may have used this line incorrectly, but I am not sure.
without the php it looks like this. When clicked on the submit button it will post your data to loaduser.php (tip : use F12 on your browser to see network traffic / errors on page) . Good luck
<form action="/loaduser.php" method="POST">
<input id="username" type="text" name="username" value="waarde">
<input id="age" type="number" name="age" value="leeftijd">
<input type='submit'>
</form>
https://plnkr.co/edit/rH6QunyZewm1MZbUYPAd?p=preview

Complete an url wtih the data given in boxes and go to that url

My workmates and I use the link below a couple of times in a day by clicking several pages to finally get this link:
http://eharita.mamak.bel.tr/imararsiv/test.aspx?f_ada=36391&f_parsel=4
What i want to do is, after test.aspx?_ada= you see 36391 this is my first number and &f_parsel= 4 this is the second one.
I want to create an HTML which consist of 2 boxes and a submit, sent button, in the very first box i want to write down a number (in the example it is : 36391) and in the second box another number (in the example it is : 4) and after that i ll click on Submit or Send button and this action will take me to the URL of
http://eharita.mamak.bel.tr/imararsiv/test.aspx?f_ada=36391&f_parsel=4
Maybe its easy or not but as a civil engineer i don't know how to make an HTML page like that.
It is quite easy, you just need a basic form.
<form action="http://eharita.mamak.bel.tr/imararsiv/test.aspx" method="GET">
<input type="text" name="f_ada" > <br>
<input type="text" name="f_parsel"> <br>
<button type="submit"> Submit</button>
</form>
You can try it out here http://jsfiddle.net/ea6heach/
<form action="http://eharita.mamak.bel.tr/imararsiv/test.aspx">
<input type="text" name="f_ada"/><br>
<input type="text" name="f_parcel"/><br>
<input type="submit" name="submit"/>
</form>
The demo doesn't work because Stackoverflow doesn't allow HTML redirecting but this is the idea of a simple form.
Following form write in particular html file.
<form action="action_page.php">
First number<br>
<input type="text" name="first_val" >
<br>
Second number<br>
<input type="text" name="second_val">
<br><br>
<input type="submit" value="Submit">
</form>
//following code write in the 'action_page.php' file.
<?php
//in the action_page.php file write following code
if(isset($_GET['first_val']) && isset($_GET['second_val'])
{
?f_ada=36391&f_parsel=4
$url = 'http://eharita.mamak.bel.tr/imararsiv/test.aspx/';
$url .= '?f_ada='.$_GET['first_val']&f_parsel['second_val'];
header('Location: $url);
}
?>

How to change div id name based on form value?

I have a couple forms on a page with a single button and a hidden input field with a value already pre-set:
<form action="product.html" method="get">
<fieldset>
<input style="display: none;" type="text" name="RSS" id="RSS" value="RSS" />
<input type="submit" value="Go"/>
</fieldset>
</form>
<form action="product.html" method="get">
<fieldset>
<input style="display: none;" type="text" name="RSS2" id="RSS2" value="RSS2" />
<input type="submit" value="Go"/>
</fieldset>
</form>
Once they hit the Go button on either form, it will redirect to the product.html page where a specific div loads based on the value above.
<div id="ID CHANGE TO OCCUR HERE to either be RSS or RSS2"></div>
My question is, how do I get that id to change on that div?
Thanks
PS: PHP is not enabled on the company servers...so yeah..yeah...
If I understand you correctly, when program control transfers over to product.html, you wish to discover which form value has come across (i.e. which form did the user click).
I cannot think how you would do this solely with HTML. This is a job for a server-side language like PHP or ASP .Net.
It's pretty simple in PHP. Note that you can take all your existing HTML files and simply rename them to .php (eg. product.php) and they will still work the same.
Just put this at the top of the file -- in fact, this is the complete file (just copy/paste to your server to test):
product.php
<?php
/* Below not required, but un-comment to see useful info:
echo '<pre>';
print_r($_REQUEST);
echo '<pre>';
*/
if (isset($_REQUEST['RSS'])) {
echo 'User clicked the RSS form';
} else if (isset($_REQUEST['RSS2'])) {
echo 'Sent here by the RSS2 form';
}
Since the name of the processing file has changed, remember to change the action= line in each of your forms before trying this:
<form action="product.php" method="get">
Explanation:
When a form is submitted, the form elements (input fields, radio buttons, checkboxes) are turned into variables and sent to the processing document (the target document specified in the action= attribute of the form tag).
For each element, the variable name is the name= attribute for that element, and the variable value is either the value= attribute, or, in the case of an input field for example, whatever the user typed into the field before pressing submit.
The is very little difference to the programming/functionality between sending the form as method="Get" or method="POST", but the post method is more secure and can transfer more information, so most of us use that.
Finally, on the other end, there are three ways to get the variable values (PHP Example):
$newvar = $_GET['varname']; //if method="GET" was used
$newvar = $_POST['varname']; //if method="post" was used
$newvar = $_REQUEST['varname']; //works for both
If you need more assistance with PHP, view some of the Alex Garret's free ten-minute videos on the New Boston or on his own site.
Re-reading your question, I put together the completed example. In your target page, you have two DIVs and you wish to display one or the other depending on what form the user clicked.
Here is a working example of the solution. Copy/Paste into two files called:
test.php -- this file can be renamed whatever you want
product.php -- if change this name, must also change name in both action= attributes of forms
test.php
<form action="product.php" method="get"> <!-- product.html -->
<fieldset>
<input type="hidden" name="RSS" id="RSS" value="RSS" />
<input type="submit" value="Go"/>
</fieldset>
</form>
<form action="product.php" method="get">
<fieldset>
<input type="hidden" name="RSS2" id="RSS2" value="RSS2" />
<input type="submit" value="Go"/>
</fieldset>
</form>
product.php
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var whichone = $('#xfer').val();
//alert( whichone );
$('#' + whichone).show();
});
</script>
</head>
<body>
<input type="hidden" id="xfer" value="<?php echo ( isset($_REQUEST['RSS']) ? 'RSS' : 'RSS2' ) ; ?>">
<div id="RSS" style="display:none;">
<h1>RSS DIV</h1>
Here is some information regarding the RSS div.
</div><!-- #RSS -->
<div id="RSS2" style="display:none;">
<h1>RSS2 DIV</h1>
<i>Here is some <strong>different </strong>information regarding the RSS2 div.</i>
</div><!-- #RSS -->
</body>
</html>
You can test your request with javascript:
if(location.href.indexOf("RSS=RSS") > 0) {
var element = document.getElementById('RSS')
element.id = "RSS2";
element.name = "RSS2";
element.value = "RSS2";
}
this is just an indexOf check, u could also parse the whole query string and associate the key/value pairs into an array. See How can I get query string values in JavaScript?

Mimicking a login form...

We have an internal application that requires the same username/password across the board.
However, if the login fails too many times, then the account is locked for that username.
We can't change the lockout because that will affect the public facing site as well.
I have been asked to come up with a way to essentially, click a button and auto-login.
Initial research has brought me to this script... (Credit)
<!doctype html>
<!-- saved from url=(0014)about:internet -->
<html>
<title>Auto Login</title>
</head>
<body>
<form id="loginForm" name="loginForm" method="post" action="http://mail.google.com">
<select name="uni_url" id="logServer" class="validate[required]">
<option class="" value="" fbUrl="" cookieName="" >
Test_en
</option>
</select>
<input id="loginName" name="name" type="text" value="Username" class="" />
<input id="loginPassword" name="password" type="password" value="ExamplePassword" class="" />
<input type="hidden" id="loginKid" name="kid" value=""/>
</form>
<script>document.loginForm.submit();</script>
</body></html>
...but I can't seem to get it to work for me.
So, I found another option where I can create a small html file (form) with a submit button, that does - onload="form1.submit();", and this could basically log me into this website without having to key in any login information.
Not sure where to start with mimicking a login form like this and need a good direction to get started in.
Thoughts?
Let's assume your existing login form looks like this:
<form action="/login.php" method="post" id="loginform">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" />
</form>
On your "auto-login" (which is really an auto-submit) page you want to mimic the same structure as before but:
Add in values to be submitted (static username and password?)
Optionally remove the submit button (if you know your users have JS enabled then you can get rid).
Add some JS that automagically submits the form for you.
That might give us something like this:
<form action="/login.php" method="post" id="loginform">
<input type="text" name="username" value="gvee" />
<input type="password" name="password" value="hunter2" />
</form>
<script type="text/javascript">document.forms[0].submit()</script>
The javascript will essentially look for the first form on the page (forms[0]) and submit that.
Update
Upon further inspection your existing login form is a bit of a funny onion. Instead of submitting the form directly, it's calling a function called doLogin() that sets certain hidden properties.
Therefore, instead of submitting the form, we should mimic the same behaviour (i.e. call doLogin() instead of .submit()).
One key thing here is that you'll want to only call the function after it has been declared. Simplest solution is to put our added bit of script at the very bottom of the HTML.
<script type="text/javascript">doSubmit();</script>

Categories