How to Close the popup box in angularjs - php

Actually, i want to close the popup when i click the submit button but right now it is not closing the popup box. please check my code, and let me know what I'm doing wrong.
My code :
<div class="modal-footer">
<button type="submit" class="btn btn-primary m-r-10 waves-effect" ng-click="updateGrade()" ng-disabled="updateMenuForm.$invalid || menugradesCtrl.formData.dataLoading || menugradesCtrl.formData.processing" tabindex="14">Submit</button>
</div>

Related

How to register button click

html:
<button type="button" class="btn btn-outline-danger btn-icon-text" id = "LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
php:
<?php
if (isset($_SESSION['LOAD']))
{
exit();
}
?>
when i click the button, nothing happens. sorry i am really new to html and php. i have tried multiple other methods but none work :(
<button type="button" class="btn btn-outline-danger btn-icon-text" id = "LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
That's just a HTML code, so it will not trigger anything. You need little bit javascript.
Also remember, php loads before javascript. So you can't trigger php with javascript if you don't use AJAX or redirect etc.
<script>
document.getElementById("LOAD").onclick = function(){
window.location.href = window.location.href+"?LOAD=1";
}
</script>
If you add that javascript code, button will refresh the page and redirect the same page with GET parameter.
You can control the GET parameter on the PHP side.
<?php
if (isset($_GET['LOAD']))
{
exit();
}
?>
It's not efficient path but if you understand the mechanics, you can figure it out.
Research AJAX.
You are not assigning the button name (which is different from the id)
try name="LOAD" as in:
<button type="button" class="btn btn-outline-danger btn-icon-text" id="LOAD" name="LOAD">
<i class="mdi mdi-upload btn-icon-prepend"></i>LOAD
</button>
</div>

PHP access name of javascript function that fired in AJAX onclick event

I have several buttons that the user may press to see results from a MySQL database. The onclick event on the button fires an AJAX call that goes out and retrieves the data that coincides with which button was pressed.
One of the following functions is called, depending on which button is pressed.
<script language="JavaScript">
function ChangeText1() {
$("#ajax_content").load("zone_code.php #zone_code1");}
function ChangeText2() {
$("#ajax_content").load("zone_code.php #zone_code2");}
function ChangeText3() {
$("#ajax_content").load("zone_code.php #zone_code3");}
</script>
Following are the buttons on zones.php:
<button type="button" class="active zone" name="z1" onclick="ChangeText1()">Zone 1</button>
<button type="button" class="active_zone" name="z2" onclick="ChangeText2()">Zone 2</button>
<button type="button" class="active_zone" name="z3" onclick="ChangeText3()">Zone 3</button>
Here is the php code that is retrieved from zone_code.php when a button is pressed:
<div id="zone_code1">
<?php echo '<p>' . $all_results[0]['zone_desc'] . '</p>'; ?>
</div>
<div id="zone_code2">
<?php echo '<p>' . $all_results[1]['zone_desc'] . '</p>'; ?>
</div>
<div id="zone_code3">
<?php echo '<p>' . $all_results[2]['zone_desc'] . '</p>'; ?>
</div>
And here is the div on zones.php that is populated by the ajax call:
<div id="ajax_content">
<p>Choose a zone</p>
</div>
Right now, the code works beautifully to call in the zone description for whichever button was pressed, either zone 1, zone 2, or zone 3. But I would also like to know which of the buttons was pressed, whether it was number 1, 2, or 3. There are more operations I would like to do with PHP, based on which of the buttons they pressed.
For various reasons, I cannot make the button into a submit button, or put it between form tags. Nor can I embed a link in the button. The reasons are too complicated to go into here. So I would like to be able to access either the name of the function that fired, or the name of the button that was clicked.
It may seem like a simple thing, but I am a javascript newbie, and am much more comfortable with php. I have tried various if statements in PHP, which of course didn't work, because javascript is client side and PHP is server side. I have been Googling this for a couple of hours, but haven't been able to find anything close enough to my situation to solve this. I'm not including those failed attempts here, for the sake of keeping this as short as I can. Suffice it to say I tried... I really tried.
I would very much appreciate help with this. Thank you, in advance, for your kindness and consideration.
<script language="JavaScript">
function ChangeText1() {
$("#ajax_content").load("zone_code.php?zone=1 #zone_code1");}
function ChangeText2() {
$("#ajax_content").load("zone_code.php?zone=2 #zone_code2");}
function ChangeText3() {
$("#ajax_content").load("zone_code.php?zone=3 #zone_code3");}
</script>
then it should be in zone_code.php's $_GET['zone'] , "1" or "2" or "3" ^^
You can simplify your code like this -
<script language="JavaScript">
function ChangeText(code) {
$("#ajax_content").load("zone_code.php?zoneCode="+code+" #zone_code"+code);
}
</script>
In the HTML now -
<button type="button" class="active zone" name="z1" onclick="ChangeText(1)">Zone 1</button>
<button type="button" class="active_zone" name="z2" onclick="ChangeText(2)">Zone 2</button>
<button type="button" class="active_zone" name="z3" onclick="ChangeText(3)">Zone 3</button>
In your PHP code, you can get the zoneCode as follows -
$zoneCode = $_GET["zoneCode"]
as we said before (see comment) i will do something like that, buttonName is then with post process:
<script language="JavaScript">
function ChangeText(value) {
$("#ajax_content").load("zone_code.php #zone_code"+value, {buttonName:"z"+value});
}
</script>
or like that, buttonName is then send with get process
<script language="JavaScript">
function ChangeText(value) {
$("#ajax_content").load("zone_code.php #zone_code"+value, "buttonName=z"+value);
}
</script>
in both of the upper code you can use $("#zone_code"+value).load("zone_code.php") instead of $("#ajax_content").load("zone_code.php #zone_code"+value)
there is another post about this here
and in your html
<button type="button" class="active zone" name="z1" onclick="ChangeText(1)">Zone 1</button>
<button type="button" class="active_zone" name="z2" onclick="ChangeText(2)">Zone 2</button>
<button type="button" class="active_zone" name="z3" onclick="ChangeText(3)">Zone 3</button>

The anchor tag not working as should

the anchor tag not working, is there a syntax error?
<button type="button" class="btn btn-default" onclick="window.location.href='/user/<?php echo $user->uid; ?>/edit#shops'" >επιλέξτε εδώ</button>
URL from firebug translates to: http://www.website.com/user/1/edit#shops
Why are you using button use a tag
επιλέξτε εδώ

Jquery Bootstrap modal PHP

I have a form with many fields and when I click the submit button, before saving the data in my database, I would like to show a bootstrap modal popup that displays a question to the user. The user can answer "yes" or "no" to the question. In these two cases, the data will be saved in the database. The difference between the "yes" and "no" button is the action.
I get some trouble to manage with this.
I know that Ajax and PHP are required but I do not really know how to do the trick.
A hand would be appreciate.
Sorry for my poor english.
You just need to call the modal when the submit is clicked. Then, do the ajax call based on what the user clicked.
SOme like this:
HTML
//Submit Button
<div class="form-group">
<button id="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
//Modal to ask for confirmation
<div id="confirm" class="modal hide fade">
<div class="modal-body">
Are you sure?
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" id="yes">Yes</button>
<button type="button" data-dismiss="modal" class="btn" id="no">No</button>
</div>
</div>
Then, you just need to add listeners to each button and do the corresponding action.
Javascript
<script type="text/javascript">
//If user submits, show modal.
$("#submit").click(function() {
showModal();
});
//If user selects Yes, do action A.
$("#yes").click(function() {
doAjax_A();
});
//If user selects No, do action B.
$("#no").click(function() {
doAjax_B();
});
</script>
All thats left is to do your Ajax Call.
More on: http://api.jquery.com/jquery.ajax/

How to handle two submit buttons in my form

I am trying to create two submit button in my form
<form id="form-input-wrapper" action='test.php'>
//form items..
//form items..
<button class="btn btn-primary" type="submit" value="old">first button.</button>
<button class="btn btn-primary" type="submit" value="new">second button</button>
</form>
My question is how to distinquish which button the user clicks in my test.php page?
You need to add the name attribute to your buttons
<button class="btn btn-primary" type="submit" name="old" value="old">first button.</button>
<button class="btn btn-primary" type="submit" name="new" value="new">second button</button>
The php code to use would look like:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//something posted
if (isset($_POST['old'])) {
//old
} elseif (isset($_POST['new']){
//new
}
}
related question:
How can I tell which button was clicked in a PHP form submit?
Use button name tag and check them in php:
<button name="subject1" type="submit" value="HTML">HTML</button>
<button name="subject2" type="submit" value="CSS">CSS</button>
And in php:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ( isset($_POST['subject1']) ) {
// first button is clicked
} elseif ( isset($_POST['subject2']) ) {
//second button is clicked
}
}
?>

Categories