username and password help in joomla - php

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;?>

Related

php form post array order

In php, if you name your form fields using numerical indexes, they work as arrays in the $_POST object.
<form method="post" action="post.php">
<input type="text" name="question[0][name]" />
<input type="text" name="question[0][email]"/>
<input type="text" name="question[0][password]" />
<hr>
<input type="text" name="question[1][name]" />
<input type="text" name="question[1][email]"/>
<input type="text" name="question[1][password]" />
<hr>
<input type="submit" value="Add" />
<hr>
<p><?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo json_encode($_POST, JSON_NUMERIC_CHECK);
}
?></p>
</form>
outputs
{"question":[{"name":"a","email":"aa","password":"aaa"},{"name":"b","email":"bb","password":"bbb"}]}
If the ordering of the fields is not sequential starting at zero and incrementing by only one each time the name is repeated, then they are all interpreted as keys instead. So
<form method="post" action="post.php">
<input type="text" name="question[1][name]" />
<input type="text" name="question[1][email]"/>
<input type="text" name="question[1][password]" />
<hr>
<input type="text" name="question[0][name]" />
<input type="text" name="question[0][email]"/>
<input type="text" name="question[0][password]" />
<hr>
<input type="submit" value="Add" />
<hr>
<p><?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo json_encode($_POST, JSON_NUMERIC_CHECK);
}
?></p>
</form>
outputs
{"question":{"1":{"name":"a","email":"aa","password":"aaa"},"0":{"name":"b","email":"bb","password":"bbb"}}}
Is there a way to get $_POST to ignore the order of arrays of post keys so they are interpreted as an array?
Please check if helpful or not :
<form method="post" action="#">
<input type="text" name="question[1][name]" />
<input type="text" name="question[1][email]"/>
<input type="text" name="question[1][password]" />
<hr>
<input type="text" name="question[0][name]" />
<input type="text" name="question[0][email]"/>
<input type="text" name="question[0][password]" />
<hr>
<input type="submit" value="Add" />
<hr>
<p>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
ksort($_POST['question']);
print_r($_POST['question']);
}
?>
</p>
</form>

php variable gets echoed twice

I am trying to echo a form when a function is called. My code is as follow :
function add_post(){
....
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories().'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
}
but wp_dropdown_categories() is displayed twice. Here is the HTML output:
<div class="entry-content">
<!-- this should not be displayed -->
<select class="postform" id="cat" name="cat">
<option value="9" class="level-0">Entertainment</option>
</select>
<!-- form starts here -->
<form action="" method="post">
<input type="text" id="input-title" size="45" name="post_title">
<textarea id="text-desc" cols="66" name="post_content" rows="5"></textarea>
<select class="postform" id="cat" name="cat">
<option value="9" class="level-0">Entertainment</option>
</select>
<input type="hidden" value="1" name="new_post">
<input type="submit" value="Post" name="submit" class="subput round">
</form>
</div>
any idea why wp_dropdown_categories() is called twice?
By default, wp_dropdown_categories() echos the result. So you should either break your code in the following way:
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>
';
wp_dropdown_categories();
echo '<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
or pass the echo variable to the function as zero as such:
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories('echo=0')).'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
Try this...
See the documentation for this function wp_dropdown_categories()
function add_post(){
....
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories(array('echo'=>0)).'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
}

php forms: value="<?php=$_POST['total_amount']?> vs. value="<?=$_POST['total_amount']?>

My form is generating an error when I use:
<input type="hidden" name="total_amount" value="<?php=$_POST['total_amount']?>" />
however it works fine when I use:
<input type="hidden" name="total_amount" value="<?=$_POST['total_amount']?>" />
I thought it was insecure to use <?= instead of <?php.
Here is the complete form:
<form name="save_file" action="cyprus_funds_transfer.php" method="post" enctype="multipart/form-data">
<? if($_POST['value_type'] == 1) {?>
<input type="hidden" name="amount" value="<?php=$_POST['account_number']?>" />
<input type="hidden" name="value_type" value="1" />
<input type="hidden" name="total_amount" value="<?php=$_POST['total_amount']?>" />
<? } else { ?>
<input type="hidden" name="amount" value="<?php=$_POST['amount']?>" />
<input type="hidden" name="value_type" value="0" />
<? } ?>
<input type="hidden" name="to" value="<?php=$_POST['send_to']?>" />
<input type="hidden" name="from" value="<?php=$_POST['send_from']?>" />
<input type="hidden" name="message" value="<?php=$_POST['message']?>" />
<input type="hidden" name="mode" value="save" />
<input type="hidden" name="order_id" value="<?php=$order_id?>" />
<input type="hidden" name="email_id" value="<?php=$_POST['email_id']?>" />
</form>
This is wrong way
<?php=$_POST['send_to']?>
this is correct way
<?=$_POST['send_to']?> is similar to <?php echo $_POST['send_to']; ?>
Codepad
Try to replace
<?php=$_POST['send_to'];?>
to this
<?=$_POST['send_to'];?>
or with this
<?php echo $_POST['send_to'];?>

Auto populate form and auto submit with URL Parameters

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

HTML input field jumps

I have 2 text fields, user and password. When I enter the password, it jumps to the first one. I have no idea why that is happening. I couldn't find why it is jumping. How do I change it so the password form doesn't jump? Here is the code:
<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
</form>
<?php
}else{
?>
<form name="login_form" method="post" action="login2.php">
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
<input type="submit" name="login" id="login" action="index.php" value="Login">
</label>
</p>
</form>
<form name="Register" method="post" action="reg.php">
<input type="submit" name="register" id="register" value="Register">
</form><br />
<form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
?>
You have both of the inputs wrapped in one label. The browser is getting confused and it thinks that that entire content is a label for the first input (that's how labels work, apparently). You should only use <label> to wrap text for input.
This:
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
Should be this:
<input name="user" type="text" id="user">
<label for="user">ID</label><br />
<input name="pass" type="password" id="pass">
<label for="pass">Password</label><br />

Categories