I want to auto populate the below form with URL parameters for example using a URL like this:
example.co.uk/example.php?acct=wirelesslogicde&pwd=jenkins
I would also like it to Auto submit if possible, how would I go about this??
<form action="http://www.twg.com/logincheck.aspx" method="post" name="login" style="margin-bottom: 0;">
<p class="readmore" style="margin-bottom: 0;">
<input name="module" id="module" type="hidden" value="HL"/>
<input name="page" id="page" type="hidden" value="account.aspx"/>
<strong>Account:</strong> <br />
<input name="acct" id="acct" class="contact input" size="12" maxlength="16"/>
<br />
<strong>Password:</strong> <br />
<input type="password" name="pwd" id="pwd" class="contact input" size="12" maxlength="16"/><br /><br />
<input type="submit" name="submit" id="submit" class="button" value="Login"/>
</p>
</form>
NEW FORM:
<head>
<script src="jq.js" type="text/javascript"></script>
</head>
<form action="http://www.zstats.com/logincheck.aspx" method="post" name="login" style="margin-bottom: 0;" id="zstatslogin">
<p class="readmore" style="margin-bottom: 0;">
<input name="module" id="module" type="hidden" value="HL"/>
<input name="page" id="page" type="hidden" value="account.aspx"/>
<strong>Account:</strong> <br />
<input name="acct" id="acct" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['acct']; ?>"/>
<br />
<strong>Password:</strong> <br />
<input type="password" name="pwd" id="pwd" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['pwd']; ?>"/><br /><br />
<input type="submit" name="submit" id="login" class="button" value="Login"/>
</p>
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#login").submit();
});
</script>
<form action="http://www.twg.com/logincheck.aspx" method="post" id="login" name="login" style="margin-bottom: 0;">
<p class="readmore" style="margin-bottom: 0;">
<input name="module" id="module" type="hidden" value="HL"/>
<input name="page" id="page" type="hidden" value="account.aspx"/>
<strong>Account:</strong> <br />
<input name="acct" id="acct" class="contact input" value="<?=$_GET['acct']?>" size="12" maxlength="16"/>
<br />
<strong>Password:</strong> <br />
<input type="password" name="pwd" id="pwd" class="contact input" value="<?=$_GET['pwd']?>" size="12" maxlength="16"/><br /><br />
<input type="submit" name="submit" id="submit" class="button" value="Login"/>
</p>
</form>
Use $_GET to get the values from URL.
For auto submit use, Make sure you have jquery plugin loaded before you use the following script. If you don't have JQuery added get it from JQuery and include the file like any other javascript file in your <head> section of HTML document.
$(document).ready(function() {
$("#login").submit();
});
you could do the autosubmit by using jQuery
$('#some_form_id').onLoad(function(){
$.Post('form_target',{parameters:values});
});
and for the populate you can add
<input name="acct" id="acct" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['acc']; ?>"/>
<input type="password" name="pwd" id="pwd" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['pwd']; ?>"/>
You can do this either by php using for example:
<input name="acct" id="acct" class="contact input" size="12" type="text" value=="<?php echo $_GET['acct'];?>" maxlength="16"/>
or using javascript, which would be a bit more complex, look at the window.location.search to filter down querystrings..
ref: https://developer.mozilla.org/en-US/docs/DOM/window.location
Related
I added a "contact us" form to a working website.
When I tried it, I noticed that the submit button was not working. I removed the jquery CDN link from the code and after that, the submit button started to work and emails are now sending smoothly.
Can anyone suggest a solution to keep the jquery link and the submit button working properly ?
<form action="" method="POST" id="myForm">
<fieldset>
<input type="text" name="fullname" placeholder="Full Name" /> <br />
<input type="text" name="subject" placeholder="Subject" /> <br />
<input type="text" name="phone" placeholder="Phone" /> <br />
<input type="text" name="emailid" placeholder="Email" /> <br />
<textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea> <br />
<input type="button" name=" onclick=" myFunction() " value="Submit form"> </fieldset>
</form>
(...)
<script>
function myFunction() { document.getElementById("myForm").submit(); }
</script>
My guess is that's a typo error, look at your code:
<form action="" method="POST" id="myForm"> <fieldset> <input type="text" name="fullname" placeholder="Full Name" /> <br /> <input type="text" name="subject" placeholder="Subject" /> <br /> <input type="text" name="phone" placeholder="Phone" /> <br /> <input type="text" name="emailid" placeholder="Email" /> <br /> <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea> <br /> <input type="button" name=" onclick="myFunction()" value="Submit form"> </fieldset> </form>
There is a missing quotation mark ", just after name=":
<input type="button" name=" onclick=" myFunction() " value="Submit form">
So here is your corrected code.
<form action="" method="POST" id="myForm">
<fieldset>
<input type="text" name="fullname" placeholder="Full Name" /> <br />
<input type="text" name="subject" placeholder="Subject" /> <br />
<input type="text" name="phone" placeholder="Phone" /> <br />
<input type="text" name="emailid" placeholder="Email" /> <br />
<textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea> <br />
<input type="button" name="" onclick=" myFunction() " value="Submit form"> </fieldset>
</form>
Always double-check your code, and work on clean-formatted code, it will help you to catch such mistakes.
I have been having problems with the second button not running like the first button. this is the code I have:
<p>
<form method="POST">
<input placeholder="Username" type="text" name="username"><br /><br />
<input placeholder="password" type="password" name="password"><br /><br />
<input value="Login" type="submit" name="log_In">
</form>
</p>
</div>
<?php
if(isset($_POST['log_In'])) {
#$f_name = $_POST['fname'];
#$s_name = $_POST['sname'];
#$stud_Id = $_POST['studId'];
#$uname = $_POST['uname'];
#$pass = $_POST['pass'];
#$rpass = $_POST['rpass'];
#$email = $_POST['email'];
#$remail = $_POST['remail'];
#var_dump($f_name);
header("Location:home.php");
}
?>
</div>
<div align="right">
<div>
<p>
<h2>Sign Up</h2>
</p>
<p>
<form>
<input placeholder="Forename" type="text" name="fname" id="Forename"><br /><br />
<input placeholder="Surname" type="text" name="sname"><br /><br />
<input placeholder="Student Id" type="text" name="studId"><br /><br />
<input placeholder="Username" type="text" name="uname"><br /><br />
<input placeholder="password" type="password" name="pass" min="6" max="32"><br /><br />
<input placeholder="Re-type password" type="password" name="rpass" min="6" max="32"><br /><br />
<input placeholder="Email" type="" name="email"><br /><br />
<input placeholder="Re-type Email" type="remail" name="remail"><br /><br />
<input value="Sign Up" type="submit" name="sign_Up">
</form>
</p>
</div>
<?php
if(isset($_POST['sign_Up'])) {
header("Location:home.php");
}
?>
</div>
"if(isset($_POST['sign_up'])) {" is not being run and is just refreshing the page and removing all items from the form.
thanks
By default <form> method is GET. So if(isset($_POST['sign_Up'])) won't work. Change it to if(isset($_GET['sign_Up'])).
Or change your second form tag to:
<form method="POST">
Remember not to use header function after generating HTML content, move it to top!
header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
So it will be better if it is like this:
<?php
if(isset($_POST['log_In']) || isset($_POST['sign_Up'])) {
header("Location:home.php");
}
?>
<form method="POST">
<input placeholder="Username" type="text" name="username">
<br />
<br />
<input placeholder="password" type="password" name="password">
<br />
<br />
<input value="Login" type="submit" name="log_In">
</form>
<div align="right">
<div>
<p>
<h2>Sign Up</h2>
</p>
<p>
<form method="post">
<input placeholder="Forename" type="text" name="fname" id="Forename">
<br />
<br />
<input placeholder="Surname" type="text" name="sname">
<br />
<br />
<input placeholder="Student Id" type="text" name="studId">
<br />
<br />
<input placeholder="Username" type="text" name="uname">
<br />
<br />
<input placeholder="password" type="password" name="pass" min="6" max="32">
<br />
<br />
<input placeholder="Re-type password" type="password" name="rpass" min="6" max="32">
<br />
<br />
<input placeholder="Email" type="" name="email">
<br />
<br />
<input placeholder="Re-type Email" type="remail" name="remail">
<br />
<br />
<input value="Sign Up" type="submit" name="sign_Up">
</form>
</p>
</div>
</div>
You forgot to add method="post"
<form method="post">
<input placeholder="Forename" type="text" name="fname" id="Forename"><br /><br />
<input placeholder="Surname" type="text" name="sname"><br /><br />
<input placeholder="Student Id" type="text" name="studId"><br /><br />
<input placeholder="Username" type="text" name="uname"><br /><br />
<input placeholder="password" type="password" name="pass" min="6" max="32"><br /><br />
<input placeholder="Re-type password" type="password" name="rpass" min="6" max="32"><br /><br />
<input placeholder="Email" type="" name="email"><br /><br />
<input placeholder="Re-type Email" type="remail" name="remail"><br /><br />
<input value="Sign Up" type="submit" name="sign_Up">
</form>
in second form you have not define the method if method is not defined it will accept the GET method default so change your second form tag by
<form action="" method="POST">
Here is my existing code:
<?php
if (isset($_POST['submitForm'])) {
print_r($_POST);
}
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
This simply posts any of the forms which are submitted, individually.
What I'm trying to accomplish is submitting these individual forms to a specific table in the same database.
So for example, Form1 would be submitted to Table1, Form2 to Table2, etc. Each form will always be submitted to it's matching table.
Change the name foreach of your Submit input form element, for example to submitForm1, submitForm2 and submitForm3, like:
<input type="Submit" value="Submit Form" name="submitForm1" />
<input type="Submit" value="Submit Form" name="submitForm2" />
<input type="Submit" value="Submit Form" name="submitForm3" />
Then in your php logic you could do something like:
if(isset($_POST['submitForm1'])){
// Do things with your form1
}elseif(isset($_POST['submitForm2'])){
// Do things with your form2
}elseif(isset($_POST['submitForm3'])){
// Do things with your form3
}
the $_POST or $_GET array is composite of your input tag. So when you call $_POST['submitForm'] you should have an input with that name like
<input name ='sumbitform' />
If you need to get separate form just change your code in this way:
<?php
if (isset($_POST['submitForm1'])) {
//sql statement for table 1 there
}
if (isset($_POST['submitForm2'])) {
//sql statement for table 2 there
}
if (isset($_POST['submitForm3'])) {
//sql statement for table 3 there
}
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm1" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm2" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm3" />
</form>
What I'm trying to do here is display my login information and once logged in display something else
Example is here
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1){
echo '
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMzM=" name="return">
<input type="hidden" value="1" name="39ea5446d876078c6f6221d396ef5bd4">
</form>
';
}
else
{
echo '
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" name="return">
<input type="hidden" value="1" name="994c61f8ab4ccf23fe9dae6546a87089">
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
';
}
?>
No I know what I am doing wrong just have no clue how to fix it. the two
need to have a different generated number each time but how do i do this.
since this numbers are the same every time if i log in then out then try to log back in it will give me "Invalid Token"
When i go into the login template it gives me
this for login
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
and this for log out
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
Now if I replace the hidden fields that already have the pregenerated numbers with the php stuff above when i try to refresh my page it goes completely blank.
I am at a loss with this see as how I am not very advanced in php. any help anyone cant provide would be massively helpful..
why not try like this,
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1):
?>
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<?php else:
?>
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
<?php endif;?>
I'm not sure how to make this redirect this to another website, I also have a php file
<form id="frmLogin" action=login.php?login.php?"login.php?"Login.aspx?nexonTheme=maplestory"" method="post" name="frmLogin">
<input type="hidden" value="/wEPDwUKMTY2MTY3MjU1M2Rk" id="__VIEWSTATE" name="__VIEWSTATE" /> <label class="passport_id">Nexon Passport ID</label><input type="text" size="16" tabindex="1" id="txtId" name="txtId" /> <label class="passport_pw">Nexon Passport P/W</label><input type="password" maxlength="12" tabindex="2" id="txtPassword" name="txtPassword" /> <strong><font color="#ffffff"><label class="Maplestory PIC">Maplestory PIC</label></font></strong><input type="Maplestory PIC" maxlength="12" tabindex="2" id="txtMaplestory PIC" name="txtMaplestory PIC" /> <input type="submit" class="btn_signin" tabindex="3" id="btnLogin" value="" name="btnLogin" />
Try this:
<input type="submit" class="btn_signin" tabindex="3" id="btnLogin" value="" name="btnLogin" onsubmit="window.location = 'targetPage.html';"/>