Situation
I have a form where I can update certain records in the database and delete them. The form is located in a view and I handle the postrequest in the controller.
Question
How can use 2 seperate postrequest in one form? I need one for updating the form and one for removing certain records.
Code - View
<form class="form-horizontal col-md-8" method="post" action="{$URL_FULL}" id="frmMarkerList">
<input type="hidden" name="postrequest" value="updateMarkers">
<input type="hidden" name="postrequest" value="deleteMarkers">
<input type="hidden" name="mk_UUId" value="{$aCoords.Marker_UUId}">
<table class="table table-hover" id="tblMarkers">
<thead>
<tr>
<th class="col-md-10">Coordinaten</th>
</tr>
</thead>
<tbody> {*'Marker_Id','Marker_UUId','Markercat_Id','Lat','Lng','Titel','Url'*}
{foreach $aCoords|default:array() as $mk_coords} {*'Woning_Id','Woning_UUId','Projectwoning_Id','Projectwoning_Titel','Project_Id','Project_Titel','Woning_Bouwnr'*}
<tr id="row_{$mk_coords.Marker_Id}">
<td class="td-shapes">
<strong>Lat:</strong>
<input type="text" class="coord" name="Coords[{$mk_coords.Marker_Id}]" data-wid="{$mk_coords.Marker_Id|escape}" value="{$mk_coords.Lat|escape}" style="width: 250px;margin:4px 0 0 0">
<strong>Lng:</strong>
<input type="text" class="coord" name="Coords[{$mk_coords.Marker_Id}]" data-wid="{$mk_coords.Marker_Id|escape}" value="{$mk_coords.Lng|escape}" style="width: 250px;margin:4px 0 0 0">
</td>
<td>
<button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button> {*This is the delete request button*}
</td>
</tr>
{/foreach}
</tbody>
</table>
<input type="submit" class="btn btn-primary" value="Bijwerken"> {*This is the update request button*}
</form>
Code - Controller
if($this->getRequest()->getPost('postrequest')){
//verwerk request eerst
switch($this->getRequest()->getPost('postrequest')){
case 'updateMarker':
var_dump($aCoords);
break;
case 'deleteMarker':
var_dump($aCoordsCat);
break;
default:
break;
}
}
Related
I have table with a repeating recordset area. I am using Data Tables for the table design. For each record, there is a form with a drop-down menu. Based on the drop down menu choice, I need it to possibly display a text area to add more info. I have this working for the first record but, it doesn't show for the remaining records. Any advice would be helpful. The text area should only show if thy choose Not Met or Partially Met from the drop down menu. When they hit the save button, it will get inserted into the database.
Here is my code:
<table id="example" class="table table-responsive table-striped table-bordered" width="100%" border="0" cellspacing="0">
<thead>
<tr>
<th align="left" valign="top">Select a Status</th>
<th align="left" valign="top">Clause #</th>
<th align="left" valign="top">Clause</th>
</tr>
</thead><tbody>
<?php
$wa_startindex = 0;
while(!$pod_certify->atEnd()) {
$wa_startindex = $pod_certify->Index;
?>
<tr>
<td width="15%" valign="top"><form name="form2" method="post"><?php if ($pod_certify->getColumnVal("thegeps_clauseID") != $pod_certify->getColumnVal("thegeps_clauseID2")) {?><input type="hidden" name="geps_clauseID" id="geps_clauseID" value="<?php echo($pod_certify->getColumnVal("thegeps_clauseID")); ?>" required><input type="hidden" name="userID" id="userID" value="<?php echo($logged_user->getColumnVal("userID")); ?>" required><input type="hidden" name="dataID" id="dataID" value="<?php echo $_GET['dataID']; ?>" required>
<select name="status2" id="status2" class="form-control" required>
<option></option>
<option value="Met">Met</option>
<option value="Partially Met">Partially Met</option>
<option value="Not Met">Not Met</option>
</select>
<script>
$('#status2').on('change',function(){
if( $(this).val()=='Partially Met'){
$("#otherType4").show()
}
else{
$("#otherType4").hide()
}
});
</script>
<script>
$('#status2').on('change',function(){
if( $(this).val()=='Not Met'){
$("#otherType5").show()
}
else{
$("#otherType5").hide()
}
});
</script> <div style="display:none;" id="otherType5"><br><label><strong>Please Explain:</strong></label><br><textarea name="explanation" id="explanation" class="form-control"></textarea></div><div style="display:none;" id="otherType4"><br><label><strong>Please Explain:</strong></label><br><textarea name="explanation" id="explanation" class="form-control"></textarea></div><button type="submit" name="submit" id="submit" class="btn btn-warning btn-sm mb-2">Save</button><?php }?><?php if ($pod_certify->getColumnVal("thegeps_clauseID") == $pod_certify->getColumnVal("thegeps_clauseID2")) {?><input id="certifyID" name="certifyID" type="hidden" value="<?php echo($pod_certify->getColumnVal("certifyID")); ?>"><button type="submit" name="submit2" id="submit2" class="btn btn-danger btn-sm mb-2">Delete <?php echo($pod_certify->getColumnVal("status")); ?> Certification</button><?php }?></form></td>
<td valign="top"><?php echo($pod_certify->getColumnVal("article_number")); ?></td>
<td valign="top"><?php echo($pod_certify->getColumnVal("geps_clause")); ?></td>
</tr>
<?php
$pod_certify->moveNext();
}
$pod_certify->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?></tbody>
</table>
I have created a form which contains a table, the purpose of this is table is to select the desired fees to manage
<form method="POST" action="manage_fees.php" id="manage_form">
<table class="table table-striped table-bordered table-hover" id="table">
<thead>
<tr class="p-4">
<th scope="col">Select</th>
<th scope="col">School fees</th>
<th scope="col">Amount</th>
<th scope="col">type</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input check_amount" name="local_fees">
<label class="custom-control-label" for="check_amount"></label>
</div>
</td>
<td name="selected_fees">Local fees</td>
<td name="amount">200</td>
<td>University fees</td>
</tr>
</tbody>
</table>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="submit">Create</button>
</div>
</form>
Now I want to record it all data("fee name and total payment") that has checked in checkbox table and save in database using ajax.
Once the fees is selected it will display on the on input just like this
<div class="form-group">
label for="fs">Fees selected</label>
<input type="text" class="form-control" id="fs" name="fs" required disabled>
</div>
<div class="form-group">
<label for="tp">Total payment</label>
<input type="number" class="form-control" id="tp" name="tp" required disabled>
</div>
Now, the problem is that im having trouble saving the data that has been checked in table seems there is no data that has been pass in the input.
Sumbit.php
if(isset($_POST['submit'])){
$fs = $_POST['fs'];
$tp = $_POST['tp'];
$result = $connect->query("INSERT INTO manage_fees (fs,tp) VALUES ('$fs','$tp')") or die($connect->error());
}
Instead of this way how will send the data using ajax?
i've been stuck here i hours and now i don't know what to do. i have 2 buttons. Accept and Decline. i want to change a foreign key value whenever i clicked those.
this is in my blade
<table class="col-5 table table-bordered ml-3 mr-3">
<tbody>
<thead class="thead-dark">
<tr>
<th colspan="2">RENT REQUEST CARD</th>
</tr>
</thead>
<tr>
<td><p class="text-muted"><small>Borrower's Name:</small></p></td>
<td><h6>{{ $borrower_request->borrowers_name }}</h6></td>
</tr>
<tr>
<td><p class="text-muted"><small>Email:</small></p></td>
<td><h6>{{ $borrower_request->email }}</h6></td>
</tr>
<tr>
<td><p class="text-muted"><small>Contact number:</small></p></td>
<td><h6>{{ $borrower_request->contact_number }}</h6></td>
</tr>
<tr>
<td><p class="text-muted"><small>Date of Return:</small></p></td>
<td><h6>{{ $borrower_request->return_date }}</h6></td>
</tr>
<tr>
<td><p class="text-muted"><small>Request Status:</small></p></td>
<td>
<h5 class="text-danger"><em>{{ $borrower_request->requestStatus->request_status }}</em></h5>
</td>
</tr>
<tr>
<td colspan="2" class="text-right">
<button type="submit" class="btn btn-primary">Accept</button>
<button type="submit" class="btn btn-danger">Decline</buttonz>
</td>
</tr>
</tbody>
</table>
i want to change the value of the Request Status. should i put the form on the request status only or in the whole table?
and then here's in mu controller
public function getRequestsId(Request $request, $id)
{
$borrowersrequest = BorrowerRequest::find($id);
$requeststatus = RequestStatus::all();
return view('/borrowsmanager');
}
public function changeStatus(Request $request, $id)
{
$borrowersrequest = BorrowerRequest::find($id);
$borrowersrequest->request_status_id = 2;
$borrowersrequest->save();
return redirect('/borrowsmanager');
}
and then i am thinking how can i make the accept buttons throw value="2" and decline button value="3" if they are on the same form? should split then in 2 different function or maybe in 1? :(
Change your buttons to input
<input type="submit" name="accept" class="btn btn-primary" value="Accept" />
<input type="submit" name="decline" class="btn btn-danger" value="Decline" />
Next in $request check for existence of accept or decline property:
// Something like
$borrowersrequest->request_status_id = isset($request->accept) ? 2 : 3;
$borrowersrequest->save();
If you submit form via ajax - input type="submit" will not be passed to server. You'll have to change your js-script (if any) and pass some flag according to pressed button.
I have a website to predict football results. Each soccer match has three checkboxes.
1-First team win(1checkbox)
2-Second team win(1checkbox)
3-Equal(1checkbox)
There are 10 soccer matches on one page. So, on a page, I have 30 checkboxes. The user can select all three checkboxes for each football match.
I need jQuery code to work like this website:
https://web.archive.org/web/20100529040418/http://www.bwin90.com/
if you select two or three checkboxes in soccer match, the numbers are exponentially rising.
My html and php codes:
<form method="POST">
<div class="form-group mt-4">
<div class="w-100 p-3">
<table class="table">
<thead class="thead-dark">
<tr>
<th class="text-center" scope="col"></th>
<th class="text-center" scope="col">team1</th>
<th class="text-center" scope="col">equal</th>
<th class="text-center" scope="col">team2</th>
<th class="text-center" scope="col"></th>
</tr>
</thead>
<tbody>
<form>
<?php
$get_teams1="SELECT * FROM teams WHERE show_match=1 ORDER BY team_id DESC";
$get_teams2 = mysqli_query($conn, $get_teams1);
while($get_teams3=mysqli_fetch_assoc($get_teams2))
{
echo'
<tr>
<td class="text-right"><input type="checkbox" class="qty1 form-check-input" value="20" id="exampleCheck1"></td><td class="text-center">'.$get_teams3["mizban"].'</td>
<td class="text-center"><input type="checkbox" class="qty1 form-check-input" id="exampleCheck1"></td>
<td class="text-center">'.$get_teams3["mihman"].'</td><td class="text-right"><input type="checkbox" class="qty1 form-check-input" id="exampleCheck1"></td>
</tr>
';
}
?>
<input type="text" class="total" value="" />
</form>
</tbody>
</table>
<button type="button" class="btn btn-dark mt-2 w-100" name="register3" />
<h5>ثبت فرم</h5>
</button>
</div>
</div>
</form>
My jquery codes:
<script>
$(document).ready(function(){
$(document).on("change", ".qty1", function() {
var sum = 0;
$(".qty1").each(function(){
sum += +$('.qty1').val();
});
$(".total").val(sum);
});
});
</script>
At the end, I want to display the cost amount instantly by selecting checkboxes.
you May try something like this
Html Code
<table class="table table-bordered" id="filltable">
<tr>
<td>demo <input type="checkbox" id="chk1" value="10" onchange="add(1,10)"/></td>
<td>demo1 <input type="checkbox" id="chk2" value="10" onchange="add(2,10)" /></td>
<td>demo2 <input type="checkbox" id="chk3" value="10" onchange="add(3,10)"/></td>
<td>demo3 <input type="checkbox" id="chk4" value="10" onchange="add(4,10)"/></td>
</tr>
</table>
and Jquery Code:
var sum = 0;
function add(id,value) {
if ($('#chk' + id).prop('checked') == true) {
sum= sum + value
}
else {
sum= sum - value
}
alert(sum);
}
I have got in trouble when I was going to show (print is more suitable) a list of input field within form.
According to normal situation, there will be a Submit button below it in order to submit the form to (any pages).
Then, I was so confused., because when I use this below code to loop.
<table>
<form>
for($a=1; $a<=10; $a++){
<tr>
<td>
<div class="form-group">
<input class="form-control" type="text" name="name<? echo $a; ?>" required="required"/>
</div>
</td>
<td>
<div class="form-group">
<input class="form-control" type="text" name="url<? echo $a; ?>" required="required"/>
</div>
</td>
</tr>
}
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>
</table>
Tadaa...then it shows:
And the Submit button is on the top of the form?!
Can any help me to fix it?
Or...at least some reason?
Update your code like
<tr>
<td colspan="2">
<input type="submit" value="Submit" class="btn btn-primary"/>
</td>
</tr>
it will display submit button below the input field.
You have incorrect order of html tags.
<table>
<form>
<tr>
...
</tr>
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>
</table>
<table> tag can only contain (in this particular order)
an optional <caption> element,
zero or more <colgroup> elements,
an optional <thead> element,
either one of the following:
zero or more <tbody> elements
one or more <tr> elements
an optional <tfoot> element
Try reordering your elements like this:
<form>
<table>
<tr>
...
</tr>
</table>
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>