Edit: Apologies for the bad wording, a better version is below:
When the user first visits the site they see i.stack.imgur.com/7zbyv.png. They then have to enter a set password (PHP variable) and click submit. If it is correct i.stack.imgur.com/E78wK.png will show. If not, nothing will happen.
I am working on a script over at my development site. I am looking to replace the big green button with a text box and a submit button. The user must enter the correct password into the box and click the submit button before the green button is displayed. I cannot find a guide on how to do this anywhere. Can anyone help me? I have put the relevant code and screenshots below:
Green Button:
<?php
if(($xx != null) || $log != null)
{
echo "<a rel=\"tooltip\" title=\"Login via Instagram using your username\" class=\"btn btn-success\" href=\"$loginUrl\">Login with Instagram</a>";
}
?>
Login Form and Button
<form>
<br />
<input type="password" class="input-small" placeholder="Enter Code...">
<button type="submit" class="btn">Login</button>
</form>
it's very simple -- you output both the form and the button when the user is not logged in. You use CSS to hide the form, and only display the button. Then user jQuery click() (or simple javascript) handler to toggle the button with the form.
Here's a demonstartion of said technique with jQuery: http://jsfiddle.net/uHzfp/
<?php
if(($xx != null) || $log != null)
{
echo "<a id="login_button" rel=\"tooltip\" title=\"Login via Instagram using your username\" class=\"btn btn-success\" href=\"$loginUrl\" >Login with Instagram</a>";
}
?>
<form id="myform" style="display:none;">
<br />
<input type="password" class="input-small" placeholder="Enter Code...">
<button type="submit" class="btn">Login</button>
</form>
<script>
$("#login_button").click(function () {
$(this).css("display","none");
$('#myform').css("display","");
});
</script>
Related
I want to show a button in my page only if a certain condition is met.
Also i want to run a query (DELETE QUERY) when i press that button.
<?php if (isset($_POST['finduser_btn']) && $noerr) :
echo "<div class='green'>
<button type='submit' class='btn' name='scoreDel'>Delete scores</button>
</div>
endif ?>
I use $noerr as FLAG to display or not the button if another button is pressed (the other button is not shown in code)
Well, how do i use scoreDel button to run a query like:
DELETE FROM scores
WHERE name = '$username$;
I think i have some issue with " and ' into the PHP echoing html tags but i'm not sure... I hope in some help, i'm getting mad.
Thanks in advance
You need a form in order to submit your action.
echo '<form action="mypage.php" method="POST"><div class="green">
<button type="submit" class="btn" name="scoreDel">Delete scores</button>
</div></form>';
Try the following:
<?php if (isset($_POST['finduser_btn']) && $noerr) : ?>
<div class='green'>
<form method="post">
<input type="text" name="finduser">
<button type='submit' class='btn' name='scoreDel'>Delete scores</button>
</form>
</div>
<?php endif ?>
Use a form to submit the button tag. Also, write html outside of PHP code if possible.
I have a submit button named "details:, and a table which had radio buttons in each rows.
On selecting radio button and then clicking on my details button I want a popup to appear.
I have used something like this: I am not sure if the code I tried is really pathetic, but plz help me.
The form I used is GET.
This is my radio button:
<input type="radio" name="ID" value="<?php echo $id; ?>" class="radioValue" />
This is my submit button:
<input type="submit" name="details1" value="Details" id="btndetails" class="btn" />
<div id="notice">
<div class="pop">
<?php
if(isset($_GET['details1']))
{
if(isset($_GET['ID']))
{
$n=$_GET['ID'];
echo$n;
//do some sql queries with the id
}
else echo"Fail";
}
?>
</div>
</div>
I have used jquery to ensure the clicks:
(function($)
{
$(function()
{
$('#btndetails').bind('click', function(e)
{
// Prevents the default action to be triggered.
if($('.radioValue').is(':checked'))
{
e.preventDefault();
$("#notice").css("display", "block");
}
else
{
<?php echo"Please select the radio button";?>');
}
});
});
})(jQuery);
the div notice is display:none;
Currently on clicking the radio button + details button i am getting a popup with msg "fail". How can I get my radio button value in the pop up? Is my method wrong? I need to get the radio value in php so that i can use it to retrieve my DB.
I dont want to use any plugins for popups. I want it only by using php,html, css .
Please help me.
This might be your problem:
<input type="submit" name="details1" value="Details" id="btndetails" class="btn" />
<div id="notice">
<div class="pop">
<?php
if(isset($_GET['details1']))
{
if(isset($_GET['ID']))
{
$n=$_GET['ID'];
echo$n;
//do some sql queries with the id
}
else echo"Fail";
}
?> // the first problem I found is here
</div>
</div>
also check your URL are you getting id parameter in query string
As the title says This is the code that I tried with. The forms must appear one by one because information from previous forms determine how the next ones will look.
$(document).ready(function(){
$('#first_form').submit(function(){
$('#first_form').fadeOut('fast');
$('#second_form').fadeIn('fast');
});
});
<form action="new_patch.php" method="POST" id="first_form">
Title: <input type="text" name="patch" placeholder="Patch 4.20">
<br/>
Number of Champions: <input type="number" name="champ_number" min="1" max="99">
<br/>
<input type="submit" value="submit">
</form>
<form action="new_patch.php" method="POST" id="second_form" style="display: none;" >
<input type="text" value="text">
<input type="submit" value="submit">
<?php
$champ_number = null;
if(isset($_POST['champ_number']))
{
$champ_number = $_POST['champ_number'];
for($champ_number;$champ_number>0;$champ_number--)
{
echo "<br/>Champion ".$champ_number."<input type=\"number\" name=".$champ_number." min=\"1\" max=\"99\">";
}
}
?>
</form>
You're mixing client-side and server-side form code. Submitting the form will reload the page entirely, so from the looks of your code it will fade in the new form when the old form is submitted, but then reload the page so the old form will show again anyway.
You could either:
Let the PHP determine how the next form appears based on the submission of the first form, e.g. if (isset($_POST["First_form_submit"]) { Show second form... }
Probably better and more user-friendly: make the second form appear below once the user has filled in the relevant inputs on the first form before they've submitted
you can use:
$('#first_form').submit(function(){
$('#first_form').fadeOut(function() {
$('#second_form').fadeIn('fast');
});
return false;
});
From the jQuery documentation the syntax is fadeIn( [duration ] [, complete ] ) it accepts a duration and a onComplete callback that you can use to execute the next action when the first is completed.
I did this once too, just add a submit class to the button and make it like this:
<input type="submit" value="submit" class="submit">
Change script to a click function.
$(document).ready(function(event){
event.preventDefault();
$('.submit').click(function(){
$('#first_form').fadeOut(400);
$('#second_form').fadeIn(400);
});
});
PS, also you need to prevent submit default...otherwise it will just submit the form, see this JSfiddle
I am learning PHP and I have a page that reloads back to itself. I want to know if you can ignore a certain function on the initial loading of the page and only call it once the form submit button has been clicked.
The page is passed a 'ticketID' and loads the information from it. I then want to be able to add a note using the following form method:
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<strong>Add Note:</strong>
<textarea name="note" rows="5" cols="40" value=><?php echo htmlspecialchars($note);?></textarea>
<span class="error">*<?php echo $noteErr;?></span><br>
The user then clicks on a submit button to submit the note for processing:
<button type='submit' name='ticketID' value= <?php echo $_POST['ticketID'];?> >View</button>
</form>
The 'ticketID' is then passed back to the page to reload the information.
If the submit button is pressed and no note has been entered I want a message box to display informing the user to include a note. I have tried:
if (!empty($_POST["note"]))
{
echo "This has updated...";
} else {
echo "Missing!";
}
However this loads the error message even on the initial load of the page. I have tried setting a variable to the POST ticketID value and clearing the POST value after the page has displayed and before testing for the error message:
$tempTicketID = $_POST['ticketID'];
$_POST['ticketID'] = NULL;
Then testing the error message, and finally setting the POS value back before the page ends to allow it to reload correctly again:
$_POST['ticketID'] = $tempTicketID;
However the POST value doesn't save and the page reloads with no information.
Any help would be great appreciated.
Here's the full code layout:
##LOAD THE PAGE INFO...
#Set the temp variable and clear the post value
$tempTicketID = $_POST['ticketID'];
$_POST['ticketID'] = NULL;
#Load the form
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<strong>Add Note:</strong>
<textarea name="note" rows="5" cols="40" value=><?php echo htmlspecialchars($note);?></textarea>
<span class="error">*<?php echo $noteErr;?></span><br>
<button type='submit' name='ticketID' value= <?php echo $_POST['ticketID'];?> >View</button>
</form>
#Test if the note is empty and the form button has been pressed
if (!empty($_POST["note"]))
{
echo "This has updated...";
} elseif (empty($_POST["ticketID"] {
echo "Missing!";
}
#Set POST value back to reload the page
$_POST['ticketID'] = $tempTicketID;
We need to restructure the form just a bit to make this happen. You can check if the form is submitted by testing for the button that must be clicked to submit. However, you're using that button for multiple purposes. To simplify, we'll have a separate submit button, and pass the ticketID value through the form with a hidden input. You shouldn't need the code that unsets the $_POST values.
<button type='submit' name='submit'> View</button>
<input type='hidden' name='ticketID' value= <?php echo $_POST['ticketID'];?> />
Then you can test if the form has been submitted with this quick check:
if (isset($_POST['submit'])) {
if (!empty($_POST["note"]))
{
echo "This has updated...";
} else {
echo "Missing!";
}
}
I have multiple submit buttons with the same name in my ongoing table, i want to have each submit button contains only one link. So whenever i click on a button, it generates a link that the submit is associated with. How to do it?
<input type="submit" value="<? $row['bclink'] ?>" name="re_b" id="re_b">
PHP:
if (isset($_POST['re_b'])){
$xml = simplexml_load_file($re_b);
}
this is what i have, but it's giving me an error that "simplexml_load_file() failed to load external entity "" in .... on line 70"
my question is how to call the value of the button when is clicked?
What error? If you have a problem, then give some details, don't just say you have a problem and expect us to be able to read it from your thoughts. No one here has taken Telepathy 101.
Do you mean you want something like this?
<input type="submit" name="submit" value="Something" />
<input type="submit" name="submit" value="Else" />
if ($_POST['submit'] == 'Something') {
...
} else if ($_POST'submit'] = 'Else') {
...
}