I have a page that call "plans.php" and a page that call "register.php". In "plans.php" page i have the code below:
<?php
session_start();
$_SESSION['quarterly'];
$_SESSION['annual'];
?>
**Quarterly submit button**
<form method="post" action="register.php" >
<input type="hidden" name="quarterly" value="">
<input type="submit" class="btn btn-success btn-lg" href="register.php" name="quarterly" value="Quarterly Plan" />
</form>
**Anual submit button**
<form method="post" action="register.php" >
<input type="hidden" name="annual" value="">
<input type="submit" class="btn btn-success btn-lg" href="register.php" name="annual" value="Annual Plan" />
</form>
And in "register.php" page i have the code below:
<?php session_start(); ?>
<?php
if (isset($_SESSION['quarterly'])) {
echo '<div class="alert alert-success" role="alert">You selected Quarterly Plan - CHANGE</div>';
}
if (isset($_SESSION['annual'])) {
echo '<div class="alert alert-success" role="alert">You selected Annual Plan - CHANGE</div>';
}
?>
When user click on quarterly or annual submit button in plans.php page, the register.php page display 2 Bootstrap alerts instead one alert related with user click and, in this same page, when user refresh register.php page, both of alerts continue appear.
I've also tried inserting the code below to see if terminating one of the sessions only shows one alert instead of two but no success:
<?php
if (isset($_SESSION['quarterly'])) {
echo '<div class="alert alert-success" role="alert">You selected Quarterly plan - CHANGE</div>';
session_unset('annual');
}
if (isset($_SESSION['annual'])) {
echo '<div class="alert alert-warning" role="alert">You selected Annual plan - CHANGE</div>';
session_unset('annual');
}
?>
How can i show just one alert without this alert disappear when the same page were refreshed?
The problem is that you are setting those $_SESSION values, so your session will contain them. The solution is to check which of those $_POST is containing via isset. If you want to store this into the session, then you can override the value in $_SESSION for the one which was posted and remove the other.
Simplifying your code.... Try something like that.
Make it simple.
plans.php
<form method="post" action="register.php" >
<input type="submit" class="btn btn-success btn-lg" name="submit" value="Quarterly Plan" />
</form>
<form method="post" action="register.php" >
<input type="submit" class="btn btn-success btn-lg" name="submit" value="Annual Plan" />
</form>
register.php
session_start();
if(isset($_POST['submit'])){
$_SESSION['plan'] = $_POST['submit'] ;
}
if (isset($_SESSION['plan'])){
echo '<div class="alert alert-success" role="alert">You selected '.$_SESSION['plan'].' - CHANGE</div>';
}else{
echo '<div class="alert alert-success" role="alert">You don\'t have any plan, Please - Select</div>';
}
Good programmer always avoid to use much If_Else, Loops, and unnecessary code.
Related
i have a simple delete button in PHP which uses simple SQL query to delete the data from database, I have used the following code:
$myid = $this->uri->segment('3');
if (isset($_POST['submit'])){
$ret = mysqli_query($con,"delete * from smart_category where name='$myid'");
header("Location: https://cloudclassmate.com/jewelry-catalogue/admin/viewcategory");
}
<div style="margin-left:38%" class="clearfix">
<a href="https://cloudclassmate.com/jewelry-catalogue/admin/viewcategory">
<button type="button" class="cancelbtn bemine">Cancel</button></a>
<form action="" method="post" ><button type="submit" name="submit" class="deletebtn bemine">Delete</button></form>
</div>
the problem here is if I click the delete button, its not responding, nothing is happening. the button is like static. can anyone please tell me what could be wrong here
If any Javasscript is not involved, than just put form action.
Also send myid in the request or in URI.
please see below:
<div style="margin-left:38%" class="clearfix">
<button type="button" class="cancelbtn bemine">Cancel</button>
<form action="abc.php" method="post" ><button type="submit" name="submit" class="deletebtn bemine">Delete</button></form>
</div>
You should add an action url/path to where your PHP file is located and add a Method to your form. Also, I noticed you deleting an entry where "name" is equal to $myid please check if that is correct.
<div style="margin-left:38%" class="clearfix">
<button type="button" class="cancelbtn bemine">Cancel</button>
<form action="url-to-server.php" method="post" >
<button type="submit" name="submit" class="deletebtn bemine">Delete</button>
</form>
</div>
$myid = $this->uri->segment('3');
if (isset($_POST['submit'])){
$ret = mysqli_query($con,"delete * from smart_category where name='$myid'");
header("Location: https://cloudclassmate.com/jewelry-catalogue/admin/viewcategory");
}
I need one help.I need to totally remove the submit button after submit the form and when it will be submitted the button will display to user.I am explaining my code below.
<form name="billdata" id="billdata" enctype="multipart/form-data" method="POST" onSubmit="javascript:return checkForm();" action="complain.php">
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px"> Name :</span>
<input type="text" name="u_name" id="name" class="form-control" placeholder="Add Name" onKeyPress="clearField('name');">
</div>
<input type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit"/>
</form>
complain.php:
require_once("./include/dbconfig.php");
if(isset($_REQUEST['complainSubmit']))
{
// ......data is collecting here....
}
when data are submitted successfully the below part is executing.
<script type="text/javascript">
var phpVar = "<?php echo $_GET['success'];?>";
//console.log('php',phpVar=='');
if(phpVar == 1 && phpVar!=''){
alert('Submitted successfully.');
//var subButton=document.getElementById('addProfileData');
//subButton.disabled=false;
}
else if(phpVar == 0 && phpVar!=''){
alert('Unable to add.\\nTry again.');
}
else{
// nothing
}
</script>
<script>
function checkForm(){
var s=document.billdata;
if(s.u_name.value==''){
alert('Please enter name');
s.u_name.focus();
s.u_name.style.borderColor = "red";
return false;
}
}
</script>
Here i need to button hide when the data is going to submit and it will again display after the submit.Please help me.
A javascript code such as:
document.getElementById("your_div").innerHTML = "";
will erase the content of your div.
So, byt tagging the entire form, then erasing its contents, you can "hide" it.
Why you dont add a hide CSS-Selector or remove it by checking via if-statement?
CSS-Version:
<input type="submit" class="btn btn-success <?php ($isSubmitted ? ' hideme' : '')?>" name="complainSubmit" id="addProfileData" value="Submit">
Except a new CSS-Selector: .hideme { display:none }
Via PHP/Template:
html...
<?php if(!$isSubmitted) : ?>
<input type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit">
<?php endif; ?>
html...
Dont forget: You dont need close input html-tag: <input/> just <input>
And what is wrong to hide the button via JS?
document.getElementById("addProfileData").style.display = "none";
UPDATE:
Prompt hiding after clicking:
<button onclick="javascript:this.style.display='none'">
Submit Button
</button>
in your example:
<input onclick="javascript:this.style.display='none'" type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit"/>
I'm trying to disable a submit button when I get some trigger from the database that tells me I should disable it, I added some code in the echo line in PHP but it didn't work, what am I doing wrong?
PHP CODE
$tries= CCL::Triescount($userip)->NumofTries;
if ($tries > 2 ) //Check wheter they have tried more than 2 times then block them
{
$msg = "More than 2 attempts, block user";
echo '<input type="submit" disabled="disabled" />';
}
else
{
$tries++;
$msg = "Less than 2 attempts";
CCL::Updatetries($userip,$tries,0);
//insert into the DB
}
HTML FORM
<div class="ui-body ui-body-c ui-corner-all">
<h1>Forgot Password</h1>
<form>
<label for="emailpassdlbl"> Please enter the e-mail associated with your account, and a new auto-generated password will be sent to this e-mail account.</label>
<input type="text" id="email"><BR>
<div class="right">
<input type="submit" data-inline="true" value="Submit" disabled="disabled">
</div>
</form>
<br/>
<div data-role="popup" class="ui-body ui-body-c ui-corner-all">
<h2 id="result"></h2>
OK
</div>
If you're changing the entire code with PHP to disable it, why not remove the submit functionality altogether?
For example:
if ($tries > 2 ) //Check wheter they have tried more than 2 times then block them
{
$msg = "More than 2 attempts, block user";
echo '<button type="button" disabled" />';
}
As you can see we have actually removed the type="submit" and replaced it with type="button" it should still look like the same button however it wont submit the form (in addition to the disabled attribute).
I'm including a a php code with angular ui routing
the problem is if the millitary.php :
`
<div class="jumbotron">
<div class="page-header">
<h1>Millitary Loot Table</h1>
</div>
<?php
$MillitaryLoot = array(
'M4A4' => 47,
'AWP' => 2,
'Karambit' => 1,
'Famas' => 50
);
$newMillitaryLoot = array();
foreach ($MillitaryLoot as $item=>$value)
{
$newMillitaryLoot = array_merge($newMillitaryLoot, array_fill(0, $value, $item));
}
$myLoot = $newMillitaryLoot[array_rand($newMillitaryLoot)];
if (isset($_POST['submit']))
{
echo "\n" . "<h2 style='display:inline;'>Item: </h2>" . '<p class="text-center text-danger">' . $myLoot . '</p>' . "</br>";
}
?>
<form name="Gamble" action="" method="post" target="_self">
<button name="submit" type="submit" class="btn btn-primary">Gamble</button>
</form>
</br>
</div>
`
the include app.js
$stateProvider
.state('millitary', {
url: '/millitary',
templateUrl: 'inc/millitary.php'
})
is included into the index.php the submit button basicly not executes the code above the form
so basically i want the php code to execute in the index.php to keep the ui instead of jumping into the executing php file and losing the index.php linked styles and navigation
edit : if i run the code normaly it works but it doesn't if it gets included
edit2 : everything outside the if statement works basically if i add a echo "test"; it outputs but inside the if it does not so the problem is the form and the connection to the if statement
kind regards, daniel
Change your HTML to the following:
<form id="form" name="Gamble" method="post">
<button id="form" name="submit" type="submit" class="btn btn-primary">Gamble</button>
</form>
You can submit your form with a button with HTML5 but it must share the same ID of the form. Also keep in mind this will only be supported with browsers that support HTML5 so if not they won't be able to submit the form.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
The other alternative is to use...
<input name="submit" type="submit" class="btn btn-primary" value="Gamble">
as #gbestard suggested.
Change
<button name="submit" type="submit" class="btn btn-primary">Gamble</button>
to
<input name="submit" type="submit" class="btn btn-primary" value="Gamble" />
In order to submit you need a type submit input or use some client side script as javascript
Im having a problem displaying a php function. Its for an admin log in form.
The Function Look Like this -
function displayAdmin(){
//test if login is valid
if (isset($_SESSION['adminLogin'])){
if($_SESSION ['adminLogin']=="valid"){
?>
<script type="text/javascript">location.replace('addproduct.php')</script>
<?php
}
else {
// test if login is invalid
// display error message and login form
if($_SESSION['adminLogin']=="invalid") {
echo "<div>Incorrect User ID and/or password provided</div>";
?>
<form name="adminLogin" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div id="sign_up_form">
<label><strong>Username:</strong> <input type = "text" name="userID" class="sprited"/></label>
<label><strong>Password:</strong> <input type="password" name="passWord" class="sprited"/></label>
<div id="actions">
<a class="close form_button sprited" id="cancel" href="#">Cancel</a>
<a type ="submit" name="adminSignin"class="form_button sprited" id="log_in" href="">Sign in</a>
</div>
</div>
</form>
<?php
}
}
?>
<form name="adminLogin" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div id="sign_up_form">
<label><strong>Username:</strong> <input type = "text" name="userID" class="sprited"/></label>
<label><strong>Password:</strong> <input type="password" name="passWord" class="sprited"/></label>
<div id="actions">
<a class="close form_button sprited" id="cancel" href="#">Cancel</a>
<a type ="submit" name="adminSignin"class="form_button sprited" id="log_in" href="">Sign in</a>
</div>
</div>
</form>
<?php
}
} // end of function
And on my page where I am wanting the function to sit the code looks like this -
<?php
session_start();
// Test that page title has been created
if (!isset($pageTitle)) {
$pageTitle = '<< Page title not set >>';
}
// include the myFunctions file
include('includes/myFunctions.php');
// test if login details have been keyed in
if(!empty($_POST["userID"])) {
// Store userID and passWord in local variables
$userID=$_POST["userID"];
$passWord=$_POST["passWord"];
// check database for valid customer
checkValidAdmin($userID, $passWord);
}
?>
and then -
<div id="sign_up">
<h3 id="see_id">Administration Log in</h3>
<span>Please sign in using the form below</span>
<div><?php displayAdmin(); ?></div>
<a id="close_x" class="close sprited" href="#">close</a>
</div>
I have searched long and hard for this problem but can not seem to find the issue, if the issue jumps out at anyone I would love to hear from you!
Thank you so much in advance!!
Definitely your $_SESSION ['adminLogin']=="valid" condition is not true. Check it is set properly or session_start(); is called at beginning of the script.
The problem is you did'nt return the html string.
You should assign the form to a variable, and at the end of the function , return this variable.
$_SESSION['adminLogin'] value is empty i.e. not set or null. that is the reason function inside condition not satisfied.