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
Related
Hello im having problem of getting the text on submit button .
what im going to do is use if statement to use a single button to insert and update records. ive found a code in this site but it doesn't give me desired output
foreach($_POST as $name => $content) { // Most people refer to $key => $value
echo "The HTML name: $name <br>";
echo "The content of it: $content <br>";
}
another problem how do i change the text of the button control using javascript
the code below doesn't work
<script type="text/javascript">
$(document).ready(function () {
//Attach button clicke event hanlder
$('.btnedit').click(function () {
var title = document.getElementById('btnsubmit');
title.innerHTML = "Update";
});
});
</script>
this is the code for button
<input type="submit" name="submit" id="btnsubmit" class="btn btn-default" value="Save" />
Give name and value to your submit button
<input type="submit" name="submit" value="SUBMIT" />
The echo in foreach will be
The HTML name: submit
The content of it: SUBMIT
To get the value without foreach(), you should do like this.
echo $_POST['submit'];// will echo SUBMIT
^ name of your submit button.
See demo HERE
I have been trying to get a button that toggles its value (from "check all" to "uncheck all") based on if all the checkboxes of a certain class are checked or not. Here is my HTML (well, PHP) of the simple form with checkboxes, you can see I'm checking with isset for retaining checked state after sending the form (the "Refresh" button):
<form id="contactFormFilters" name="contactFormFilters" class="form-horizontal" action="" method="post">
<label class="checkbox"><input type="checkbox" name="commentStatusCheckbox[]" class="commentStatusCheckbox" value="inbox" <?php if(isset($_POST['commentStatusCheckbox']) && is_array($_POST['commentStatusCheckbox']) && in_array('inbox', $_POST['commentStatusCheckbox'])) echo 'checked="checked"'; ?> />Inbox</label>
<label class="checkbox"><input type="checkbox" name="commentStatusCheckbox[]" class="commentStatusCheckbox" value="archive" <?php if(isset($_POST['commentStatusCheckbox']) && is_array($_POST['commentStatusCheckbox']) && in_array('archive', $_POST['commentStatusCheckbox'])) echo 'checked="checked"'; ?> />Archive</label>
<label class="checkbox"><input type="checkbox" name="commentStatusCheckbox[]" class="commentStatusCheckbox" value="trash" <?php if(isset($_POST['commentStatusCheckbox']) && is_array($_POST['commentStatusCheckbox']) && in_array('trash', $_POST['commentStatusCheckbox'])) echo 'checked="checked"'; ?> />Trash</label>
<input type="button" class="btn btn-success btn-mini" value="check all" id="checkAllCommentStatusCheckboxes" /><br /><br />
<button name="compares">Refresh</button>
</form>
Here is my JS for changing the value of the button based on if all the checkboxes are checked, which works:
$(".commentStatusCheckbox").change(function(){
if ($('.commentStatusCheckbox:checked').length == $('.commentStatusCheckbox').length) {
$('#checkAllCommentStatusCheckboxes:button').val('uncheck all');
}else{
$('#checkAllCommentStatusCheckboxes:button').val('check all');
}});
Here is my JS for toggling the check all / uncheck all button, I am using a toggle class ("toggleClick") I found on StackOverflow since jQuery 1.9.1 was giving me trouble with using toggle with changing the value of the button. This snippet works also:
$.fn.toggleClick = function(){
var methods = arguments,
count = methods.length;
return this.each(function(i, item){
var index = 0;
$(item).click(function(){
return methods[index++ % count].apply(this,arguments);
});
});
};
$(function(){
$('#checkAllCommentStatusCheckboxes:button').toggleClick(function(){
$(this).val('uncheck all');
$('input.commentStatusCheckbox[type=checkbox]').prop('checked',true);
},function(){
$(this).val('check all');
$('input.commentStatusCheckbox[type=checkbox]').prop('checked',false);
})
})
Here is the problem: The 2 JS parts do not work perfectly together, sometimes resulting in the button saying "uncheck all" when it should say "check all" and vice versa. This happens after I submit the form. For example, if I check all 3 checkboxes, then the button's value is correctly "uncheck all", but pressing it does not uncheck all checkboxes when I want it to (I have to press it twice).
I am not sure if I need to do some sort of PHP if/else with the value of the button in the form? Or, intergrate (or redo) these JS sections?
Any help is greatly appreciated!
thanks....
I don't see how the toggleClick function behaves as you want since you do not want it to necessarily toggle with each click. I think you also need to make sure the button is in the correct state when the page loads. I recommend writing a function that updates the button to the correct state. This function would be called (1) when the page loads, (2) when a checkbox is changed, and (3) when the button is clicked.
Instead of using toggleClick(), I recommend setting a .data() value on the button to determine what it does when it is clicked.
Here is what the JavaScript would look like:
$(function() {
// This function sets the button to the correct state.
function updateCheckAllButton() {
if ($('.commentStatusCheckbox:checked').length == $('.commentStatusCheckbox').length) {
$('#checkAllCommentStatusCheckboxes').val('uncheck all').data('check', false);
} else {
$('#checkAllCommentStatusCheckboxes').val('check all').data('check', true);
}
}
// Whenever a checkbox is changed, the button is updated to the correct state.
$('.commentStatusCheckbox').change(function() {
updateCheckAllButton();
});
// Handle the button click. This will check or uncheck the checkboxes, and
// then update the state of the button.
$('#checkAllCommentStatusCheckboxes').click(function() {
$('.commentStatusCheckbox').prop('checked', $(this).data('check'));
updateCheckAllButton();
});
// Make sure the button is initially in the correct state.
updateCheckAllButton();
});
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>
I have a HTML form which when the user clicks submit, all information is sent to email via a php script using the POST method. What i want to do is disable all user input after the submit button is clicked or grey out all text box input fields. How can i go about doing this?
the code for the submit button at the moment looks like this:
<input type="submit" value=" Continue " style="width:200px;height:40px">
Add below to each HTML input element you want to disabled. Since you have not mentioned I assume that you can use PHP for this.
<?php if(isset($_POST['submit'])) echo 'disabled="disabled"'; ?>
If you are using AJAX, when the event is fired, inside particular event
$("input").prop('disabled', true);
Onclick of submit button make all input to disabled
$("input").attr('disabled', true);
Since whether mail has been sent is server side processing, its better if you handle this from server end than from client side like jQuery and javascript :
$form_state = ($is_mail_sent)?"":"disabled='disabled'";
<input type="submit" <?php echo $form_state ?> value=" Continue " style="width:200px;height:40px">
without db interaction you can't do this out, have a flag in db table. Set the flag 1 if user submit a form, by default 0. Based on the flag value you can disable the form.
if(mailsent_status_of_the_user == 1){
$status = "disabled='disabled'";
}else{
$status = "";
}
<input type="submit" value=" Continue " <?php echo $status; ?> >
By using jQuery : $("input").prop('disabled', true);
But in pure Html is not possible without refreshing page !
Edit :
Javascript :
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(e) {
$("#yourFormID").submit(function() {
$("#theInputToDisable").prop('disabled', true);
//Or to disable all inputs
//$(this).children("input").prop('disabled', true);
//$(this).children("input").attr('disabled', 'disabled');
return false;
})
});
</script>
HTML
<form id="yourFormID">
<input type="text" />
<input type="submit" value="Send"/>
</form>
I'm trying to use the submit-function in javascript to submit a form. The reason I'm not using a submit button is that I want to ask the user if really wants to submit the form. Here is the code:
<?php
if(isset($_POST['submit1']))
die("Submit successfull!");
?>
<!--Javascript submit question.-->
<script type="text/javascript">
function question_submit() {
if(confirm('Are you sure you want to submit?')) {
return true;
}
else {
alert('You have not submitted this form');
return false;
}
}
</script>
<!--The form-->
<form action='test.php' method='POST'>
<input type='button' name='submit1' value='Submit' onClick="if(question_submit()) { this.form.submit(); }" />
</form>
Result: The popups works great, it just never wants to submit the form and so "Submit successfull!" never shows up.
The message is not even shown when I add a real submit button to the page. It's like the POST-data won't work.
But when I add a PHP-code and die-function för the submit-button the thing will work and "REal Submit Works" will show up, which is strange because the buttons code is first.
<?php
if(isset($submit1))
die("Submit successfull!");
if(isset($_POST['realsubmitbutton']))
die("REal Submit Works");
?>
I I've also tried to change the onClick to just contain the javascript submit function. Like this: onClick="this.form.submit();". But that won't work either. So my question is, what's wrong with the code and why won't it work?
Can't buttons send it's value with POST?
The issue is that you are submitting the form via your onclick handler. That means, the button isn't pressed as part of the submit.
You can return true from that function to get the behavior you want.
Really though, this is a bad idea. Many of us prefer to simply push enter on a form field, rather than clicking submit. On your form handler, just check !empty($_POST) instead. Put your "are you sure" function in as the onsubmit action of the form.
Use directly "onSubmit" event on form instead of button click.
Then return "false" if you don't actually want to submit.
Modify your function so that it gets a reference to the form and calls it's submit() method:
function question_submit() {
if(confirm('Are you sure you want to submit?')) {
document.getElementById("myForm").submit();
return true;
} else {
alert('You have not submitted this form');
return false;
}
}
Also, update the form HTML so the form has an id, and modify your HTML button so that it calls the question_submit() function. Leave the actual business logic to the function to keep the HTML clean. Finally, make sure your attributes are all lowercase. This shouldn't affect functionality, but it is cleaner to use lowercase attribute names:
<form action='test.php' method='POST' id='myForm'>
...
<input type='button' name='submit1' value='Submit' onclick="question_submit();" />
</form>
The returning true or false works only when the input is type submit. So, you should change
<input type='button' name='submit1' value='Submit' onClick="if(question_submit()) { this.form.submit(); }" />
for
<input type='submit' name='submit1' value='Submit' onClick="if(question_submit()) { this.form.submit(); }" />
With your function, it will only submit when the user accepts. Or maybe, you could use
<form action='test.php' method='POST' onClick="return question_submit()">
<input type='submit' name='submit1' value='Submit' />
</form>
I've read all your answers and have finished the code. It now works with both clicking on the button or pressing Enter key. The javascript runs correctly either way and the form gets submitted.
This is the code:
<?php
if(!empty($_POST['justaname']))
die("Submit successfull!");
?>
<!--Javascript submit question.-->
<script type="text/javascript">
function question_submit() {
if(confirm('Are you sure you want to submit?')) {
document.getElementById("myform").submit();
}
else {
alert('You have not submitted this form');
}
}
</script>
<!--The form-->
<form action='test.php' method='POST' id="myform" onSubmit="event.preventDefault(); question_submit();">
<input type="text" name='justaname' />
<input type='button' name='submit1' value='Submit' onClick="question_submit()" />
</form>
Thanks for all the answers and hope this is helpfull for someone.