CakePHP confirmation popup not appearing - php

When a user clicks a submit button a popup should appear asking them if they wish to submit the selection. I've been adding to the view, and I just noticed that although the form works properly, I no longer receive a popup asking to confirm the selection.
This consists of two tables. An upper one to display info where each row has a checkbox. The bottom table allows you to choose if you want to submit only selected checkboxes, or all of the rows in the table.
<table>
<?
echo $this->Form->create(null,array(
'onsubmit'=>'return confirm("Are you sure you want to archive?'));
?>
<th>Order ID</th><th>Order Date</th><th>Order Total</th><th>Status</th><th>View</th><th>Select to Archive</th>
<?php foreach ($orders as $order): ?>
<tr>
<td><?php echo $order['Order']['id'];?> </td>
<td><?php echo $order['Order']['date']; ?></td>
<td><?php echo $order['Order']['total'];?> </td>
<td><?php echo $order['Order']['order_status'];?> </td>
<td><a href="/orders/details/<?php echo $order['Order']['id']; ?>"/>View Order</a> </td>
<td><? echo $this->Form->checkbox('archive_value.', array('hiddenField' => false, 'value' => $order['Order']['id'])); ?></td>
</tr>
<?php endforeach; ?>
</table>
<table class = "table_order_status">
<tr>
<td width="350">
<?
echo $this->Form->input('archive_values', array('options' => $archive_options, 'value' => $select_value, 'name' => 'archive'));
?>
</td>
<td>
<?
echo $this->Form->end(__('Submit'));
?>
</td>
</tr>
</table>

You have a typo in the onsubmit option. Look at your quotes. Im guessing this line:
'onsubmit'=>'return confirm("Are you sure you want to archive?'));
should be:
'onsubmit'=>'return confirm("Are you sure you want to archive?")');

Related

Decrement value from database on button click with php

I am creating a carpool website and I need help with something. I have created a button and if people click on that button than the value of free spaces in the car will decrement by one(meaning the one who will click it will reserve the place). So this value must be changed in the database and also when I refresh the page it will change on the table where I display info.This is what I have written so far but doesn't seem to make a change.Thanks in advance!
<tbody>
<?php while ($row=mysqli_fetch_array($results)) {
?>
<tr>
<td><?php echo $row['username_krijim']; ?> </td>
<td><?php echo $row['nisja']; ?> </td>
<td><?php echo $row['destinacioni']; ?> </td>
<td><?php echo $row['data_krijim']; ?> </td>
<td><?php echo $row['ora_krijim']; ?> </td>
<td ><?php echo $row['vende_krijim']; ?> </td>
<td><?php echo $row['cmimi_krijim']; ?> </td>
<td><?php echo $row['mesazhi_krijim']; ?> </td>
<td><form action="index_show.php" method="POST"><input class="btn btn-primary" style="background:#f2545f;" type="submit" name="rezervo" value="Rezervo"></form></td>
<?php
if(isset($_POST['rezervo'])){
$id_krijim=$row['id_krijimi'];
$sql = "UPDATE krijo_itinerar SET vende_krijim=vende_krijim-1 WHERE id_krijimi='$id_krijim'";
mysqli_query($db, $sql);
}
?>
</tr>
<?php } ?>
</tbody>
You can use a form to send the POST request to tell the PHP to initialize.
<td><form action="" method="POST"><input class="btn btn-primary" style="background:#f2545f;" type="button" name="rezervo" value="Rezervo"></form></td>
<?php
if (isset($rezervo)){
$sql = "UPDATE krijo_itinerar SET vende_krijim=vende_krijim-1 WHERE username_krijim='".$username_krijim."'";
mysqli_query($db, $sql);
}
?>
I also don't see the variable $username_krijim being set. I don't know if it's somewhere else in your code but that may also be contributing to your problem.
Edit:
Ok so the problem I see are that that the variable is not being sent through PHP. That previous edit I provided won't work I'll try and think of something.

If statements to change view

I've got a JQuery function running on my create page for my contacts list. User selects one of three radio buttons - individual, team and company. And will fill out different forms depending on which one they chose.
Individual sees all the fields below.
Team sees all but title.
Company sees but company and title.
When users edit between individual/company, the view.php will still --> if individual changes to company (thus not needing company/title) the company/title will still show because they a) haven't backspaced the values and b) technically isn't deleted. I'm fine with the criteria still sitting in the backend, but I want to add if statements to make sure that the individual is seeing the individual criteria, company seeing company criteria etc.
<body>
<div class="container">
<div class="row">
<table class="table">
<tr>
<th><strong>Name</strong></th>
<th><strong>Type</strong></th>
<th><strong>Details</strong></th>
<th><strong>Phone</strong></th>
<th><strong>Email</strong></th>
<th><strong>Address</strong></th>
<th><strong>Extras</strong></th>
</tr>
<?php
while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td class= "r-Name"><?php echo $r['Name']; ?></td>
<td class= "r-Type"><?php echo $r['Contact_type']; ?></td>
<td class="r-Details"><?php echo $r['Title']. ', '.$r['Company']; ?></td>
<td class="r-Phone"><?php echo $r['Phone']; ?></td>
<td class="r-Email"><?php echo $r['Email']; ?></td>
<td class="r-Address"><?php echo $r['Address']; ?></td>
<td class="r-Update">Edit</td>
<td class="r-Delete"><a href='delete.php?id=<?php echo $r['id']?>'>Delete</a></td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>
You can add this to your jquery code
$("yourinput_id").prop('disabled', true); //to disable
$("yourinput_id").prop('disabled', false);//to enable
/*so that the form will ignore the input when passed to php, regardless of
visibility*/

HTML Checkbox cannot be checked

I have some checkbox in a table that contains the id of that row item. I want to allow the user to select multiple rows. However, I can't seem to check the checkbox on Chrome. I loaded the site up on my mobile and it works. I have tried to insert an onclick but it doesn't seem like the checkbox is registering any clicks to it as well. Please help.
The table
<?php echo form_open_multipart('Events/Two/Search');?>
<table class="table">
<thead>
<tr class="text-left">
<td></td>
<td>Name</td>
<td>Email</td>
<td>Phone Number</td>
<td>Address</td>
</tr>
</thead>
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $data){
?>
<tr>
<td><input type="checkbox" name="id[]" value="<?php echo $data->id; ?>"/></td>
<td><?php echo $data->first_name." ".$data->last_name; ?></td>
<td><?php echo $data->email; ?></td>
<td><?php echo $data->phone_number; ?></td>
<td><?php echo $data->address;?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php echo form_close(); ?>
EDIT: I have cleared my cache and cookies as well. It works on the mobile but not on chrome for some reason.
EDIT 2 : It works on Safari
EDIT 3 : If I place a checkbox on another place, I can check it. Just not in the table
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable->result() as $data){
?>
<tr>
<td><input type="checkbox" name="id[]" value="<?php echo $data->id; ?>"/></td>
<td><?php echo $data->first_name." ".$data->last_name; ?></td>
<td><?php echo $data->email; ?></td>
<td><?php echo $data->phone_number; ?></td>
<td><?php echo $data->address;?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
First Your query is not working it seems so please preview this code the use jquery append to add more row if you need help on that code will be below
Jquery on click ADD/REMOVE ROW please Visit the link below
https://jsfiddle.net/susanadhikary/omngzss8/8/

get unique ID's of rows in php foreach loop for JQuery

Good Afternoon,
I have 3 foreach loops on my page, the first gets the teams, the second gets each person in the team, and the third gets each unique reference to a task that the agent has completed. I have collected this data and it is being displayed fine. I now want to add some JQuery to it so it will hide the agents and references unless the relevant team or agent is clicked on.
So if I load the page everything will be hidden apart from the teams, when I click on a team it will show the agents, when I click on an agent it will show the references.
I am having trouble assigning unique ID's to each row and finding those in the JQuery script.
Here is my code...
<?php if($aForm['sTaskType'] !== 'CP' ){?>
<table style="width: 95%">
<tr>
<th>Area</th>
<th>Pass</th>
<th>Pass with feedback</th>
<th>Fail with Minors</th>
<th>Fail with Majors</th>
</tr>
<?php foreach ($aQualityTeamResults AS $iBusinessStreamId => $aTeamData) {
$aQualityAgentResults = $oRadiusQualityFns->GetQualityAgentResults($sDateFrom, $sDateTo, $sTaskType, $aTeamData['iBusinessStreamId']);?>
<tbody>
<tr class="TeamClick<?php echo $aTeamData['iBusinessStreamId'];?>">
<td><?php echo $aTeamData['sBusinessStream']?></td>
<td><?php echo $aTeamData['Pass']?></td>
<td><?php echo $aTeamData['Pass with Feedback']?></td>
<td><?php echo $aTeamData['Fail with Minors']?></td>
<td><?php echo $aTeamData['Fail with Majors']?></td>
</tr>
</tbody>
<?php foreach ($aQualityAgentResults AS $iUserId => $aAgentData) {
$aQualityPropertyResults = $oRadiusQualityFns->GetQualityPropertyResults($sDateFrom, $sDateTo, $sTaskType, $aAgentData['iBusinessStreamId'], $aAgentData['Agent']);
?>
<tbody>
<tr class="Agent<?php echo $iUserId]?>">
<td><?php echo $oRadiusUser->Get_User_Name($aAgentData['Agent']);?></td>
<td><?php echo $aAgentData['Pass'];?></td>
<td><?php echo $aAgentData['Pass with Feedback'];?></td>
<td><?php echo $aAgentData['Fail with Minors'];?></td>
<td><?php echo $aAgentData['Fail with Majors'];?></td>
</tr>
</tbody>
<?php foreach ($aQualityPropertyResults AS $iUserId => $aPropertyData) { ?>
<tbody>
<tr class="Property<?php echo $aPropertyData['iUserId'];?>">
<td colspan="2"><font color="black"><?php echo $aPropertyData['sPropertyCode']?></font></td>
<td colspan="3"><?php echo $aPropertyData['Result']?></td>
</tr>
</tbody>
<?php
}
}
}
?>
</table>
I have given each of the rows a unique class by adding in the unique identifier from the database. I just dont know how to find these within the Jquery script.
EDIT:
Maybe not explained myself properly, I would like help with how to set up this script but obviously a lot better.
<script language="javascript" type="text/javascript" >
$(document).ready(function() {
$('.Agent').hide;
$('.Property').hide;
$(document).on('click','.TeamClick',function(){
$('.Agent').toggle('show');
$('.Property').toggle('show');
});
});
</script>
But in this case it will show/hide all of the rows as they will all have the same id's, whereas now I have added on the unique id on the end with the php code in the class, I dont know how to call those as they all are called different classes.
So if I click on TeamClick1, it shows the actual rows for that team (Agent1), and not all of them. but obviously I cant type out all of the unique id's I just dont know how to get them from the php in JQuery.
<script language="javascript" type="text/javascript" >
$(document).ready(function() {
$('.Agent').hide;
$('.Property').hide;
$(document).on('click','.TeamClick(UNIQUE ID)',function(){
$('.Agent(UNIQUE ID)').toggle('show');
$('.Property(UNIQUE ID)').toggle('show');
});
});
Hope this makes sense.
I am hasty but it is like this
<?php if($aForm['sTaskType'] !== 'CP' ){?>
<table style="width: 95%">
<tr>
<th>Area</th>
<th>Pass</th>
<th>Pass with feedback</th>
<th>Fail with Minors</th>
<th>Fail with Majors</th>
</tr>
<?php foreach ($aQualityTeamResults AS $iBusinessStreamId => $aTeamData) {
$aQualityAgentResults = $oRadiusQualityFns->GetQualityAgentResults($sDateFrom, $sDateTo, $sTaskType, $aTeamData['iBusinessStreamId']);?>
<tbody>
<tr class="TeamClick<?php echo $iBusinessStreamId;?>">
<td><?php echo $aTeamData['sBusinessStream']?></td>
<td><?php echo $aTeamData['Pass']?></td>
<td><?php echo $aTeamData['Pass with Feedback']?></td>
<td><?php echo $aTeamData['Fail with Minors']?></td>
<td><?php echo $aTeamData['Fail with Majors']?></td>
</tr>
</tbody>
<?php foreach ($aQualityAgentResults AS $iUserId => $aAgentData) {
$aQualityPropertyResults = $oRadiusQualityFns->GetQualityPropertyResults($sDateFrom, $sDateTo, $sTaskType, $aAgentData['iBusinessStreamId'], $aAgentData['Agent']);
?>
<tbody>
<tr class="Agent<?php echo $iUserId; ?>">
<td><?php echo $oRadiusUser->Get_User_Name($aAgentData['Agent']);?></td>
<td><?php echo $aAgentData['Pass'];?></td>
<td><?php echo $aAgentData['Pass with Feedback'];?></td>
<td><?php echo $aAgentData['Fail with Minors'];?></td>
<td><?php echo $aAgentData['Fail with Majors'];?></td>
</tr>
</tbody>
<?php foreach ($aQualityPropertyResults AS $iUserId2 => $aPropertyData) { ?>
<tbody>
<tr class="Property<?php echo $iUserId2 ;?>">
<td colspan="2"><font color="black"><?php echo $aPropertyData['sPropertyCode']?></font></td>
<td colspan="3"><?php echo $aPropertyData['Result']?></td>
</tr>
</tbody>
<?php
}
}
}
?>
</table>
I'm putting the identifiers in classes, but if you want put in IDs you can, is the same thing, like this id="<?php ... ?>"

Hide column of sql results and and show below table onClick

I have a table that displays SQL results, however I would like the table to display certain results, and display more upon a click, below the table in a div tag. So far I have this code that displays,'title' and 'email' and the 3rd column which will trigger a JS function and display 'details' in a div tag... How do I use JavaScript to display the specific details and hide those details when a second row details is clicked and replace the first 1?
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td>More details...</td>
</tr>
EDITED:
After a comment I received, here is my entire code of the table with the div element with the id "details"
<table>
<tr>
<td><strong>Investment Title</strong></td>
<td><strong>Email</strong></td>
<td><strong>Details</strong></td>
</tr>
<?php
// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td>More details...</td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
<tr>
</tr>
</table>
<div id="detail"></div>
Im not sure if this is what you want to do but you can try something like this. I hope this helps
HTML
<table>
<tr>
<td><strong>Investment Title</strong></td>
<td><strong>Email</strong></td>
<td><a href='#' id='show_details'>More Details</a></td>
</tr>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td id='details'><?php echo $rows['details'];?></td>
</tr>
</table>
Javascript - JQuery
$(document).ready(function()
{
$('#details').hide(); //on ready hide the td details
$('#show_details').click(function()
{
$('#details').show();
});
});
UPDATE
YOU MEAN LIKE THIS SEE MY FIDDLE
Without JQuery:
HTML
<td id='details'>The details are in here...</td>
<td id='details1'>The other details are in here...</td>
Javascript
document.getElementById('details').style.display = 'table-cell';
document.getElementById('details1').style.display = 'none';

Categories