I want to remove GET parameters from urls:
http://localhost/fadt/admin/edit_country.php?id=7
I want my URLs to become:
http://localhost/fadt/admin/edit_country
here is how links are currently generated:
<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
Instead of a button use an HTML form with the POST method.
Something like:
<form action="edit_country.php" method="post">
<input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
<input type="submit" class="btn btn-primary btn-xs fa fa-pencil" title="Edit"/>
</form>
in place of
<button onClick="location.href='edit_country?id=<?php echo $row['COUNTRY_ID']; ?>'" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
Then on edit_country.php use $_POST instead of $_GET.
This id can be manipulated just as easily as your button value so make sure you are authenticating executing user has permissions to perform action.
Update, using button:
<form method="post">
<input type="hidden" value="<?php echo $row['COUNTRY_ID'];?>" name="id" />
<button type="submit" class="btn btn-primary btn-xs" title="Edit"><i class="fa fa-pencil"></i></button>
</form>
Not clear the question but i think u need this
<?php
$a = explode('?','http://localhost/fadt/admin/edit_country.php?id=7');
echo rtrim($a[0], '.php')
?>
Related
I have question on Laravel with jQuery.
Right now, I have form with three (3) different buttons (update,delete,email). Each button have different task in controller.
Normally I use button type="submit" to submit data from blade into controller.
Blade
<form id='form-info' class="form-info" action="{{url('/form/sendData')}}" method="post">
#csrf
<input type="text" id="info" class="info" name="name" value="test"/>
<button type="submit" class="btn btn-xs btn-warning" name="update" id="update">Update</button>
<button type="submit" class="btn btn-xs btn-danger" name="delete" id="delete">Delete</button>
<button type="submit" class="btn btn-xs btn-info" name="email" id="email">Email</button>
</form>
And in controller, I just use '$request->has()' to differentiate three request.
if ($request->has('update'))
{
echo 'update';
}
else if($request->has('delete'))
{
echo 'delete';
}
else if($request->has('email'))
{
echo 'email';
}
But my current goal is to show loading icon before data successfully submitted.
The reason why I want to show loading page is because system need to send an email to multiple user and it might take some time to load before it finished the task. To prevent user to click the same button multiple times.
I use jQuery click function and I change button type from 'submit' to 'button'.
But the problem is when the form submitted to controller. It doesn't recognize '$request->has()' in my controller.
Here's my html form and jQuery and my controller
blade.php
<form id='form-info' class="form-info" action="{{url('/form/sendData')}}" method="post">
#csrf
<input type="text" id="info" class="info" name="name" value="test"/>
<button type="button" class="btn btn-xs btn-warning" name="update" id="update">Update</button>
<button type="button" class="btn btn-xs btn-danger" name="delete" id="delete">Delete</button>
<button type="button" class="btn btn-xs btn-info" name="email" id="email">Email</button>
</form>
jQuery
$(document).ready(function(){
$('#update').click(function(){
$(".loader").show();
$("#form-info").submit();
$(".loader").hide();
});
$('#delete').click(function(){
$(".loader").show();
$("#form-info").submit();
$(".loader").hide();
});
$('#email').click(function(){
$(".loader").show();
$("#form-info").submit();
$(".loader").hide();
});
});
Controller.php
if ($request->has('update'))
{
echo 'update';
}
else if($request->has('delete'))
{
echo 'delete';
}
else if($request->has('email'))
{
echo 'email';
}
How to solve this problem ? Thanks in advance.
How I can echo the whole code below.. The problem is another echo inside of the button..
Thanks!
<button type="submit" id="addres" name="addres" <?php echo $addres_disabled;?> class="btn btn-primary btn-lg pull-right"><i class="fa fa-map-marker"></i> Send Addres</button>
Try this:
echo '<button type="submit" id="addres" name="addres" '.$addres_disabled.' class="btn btn-primary btn-lg pull-right"><i class="fa fa-map-marker"></i> Send Addres</button>';
This is way too small question. A bit google search would have helped you.
echo '<button type="submit" id="addres" name="addres" '.$addres_disabled.' class="btn btn-primary btn-lg pull-right"><i class="fa fa-map-marker"></i> Send Addres</button>';
Something like that:
<?php
$addres_disabled = 'disabled';
echo '<button type="submit" id="addres" name="addres" '.$addres_disabled.' class="btn btn-primary btn-lg pull-right">
<i class="fa fa-map-marker"></i> Send Addres</button>';
?>
You can use it outside the <?php?> as you are already using, something like:
<?php
/*** Your php code ***/
$addres_disabled = 'disabled';
/*** Your php code ***/
?>
<button type="submit" id="addres" name="addres" <?=$addres_disabled?> class="btn btn-primary btn-lg pull-right">
<i class="fa fa-map-marker"></i> Send Addres</button>';
<?php
/*** Your rest php code ***/
?>
Close PHP tag, before starting your HTML, and after HTML, you can continue the PHP tags, depends on your rest code.
i think you can juste do :
<?php echo '<button type="submit" id="addres" name="addres" '. $addres_disabled .' class="btn btn-primary btn-lg pull-right">
<i class="fa fa-map-marker"></i> Send Addres</button>' ?>
I have the following code=>
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="<?php ?>">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="<?php ?>">FORWARD</button>
These buttons submit the form to the same page. At the top of the page I have variable $t which is initialized at value '0' and is followed by the codes=>
$t=0;
if( $this->input->post('ileri') ) { $t=$t+1;} // Back button was pressed;
if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;
Now as I press forward I want to increase $t and when I press back I want to decrease it. But because of the declaration at the top ($t=0;) it goes as far as '1' with 'forward' and as back as '0' with 'back' buttons. Can anyone think of a way of getting over this problem.
Thank you...
Add a hidden input, and store $t there. This gets posted upon submit:
<?php
$t = $this->input->post('t');
if (!$t) $t = 0;
if( $this->input->post('ileri') ) { $t=$t+1;} // Back button was pressed;
if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;
?>
<input name="t" type="hidden" value="<?=$t ?>">
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="submit">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="submit">FORWARD</button>
You could use url parameter. Get instead of post. so that it stores the current value of variable $t i.e.
if (isset($_GET['t']))
{
$t = $_GET['t'];
}
else
{
$t = 0;
}
Something like that could be of some help
If you want to know what button makes the submit you need to change the buttons
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="<?php ?>">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="<?php ?>">FORWARD</button>
to
<button class="btn btn-lg btn-warning text-center but-width" id="first" name="s_button" type="submit" value="geri">BACK</button>
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="s_button" type="submit" value="ileri">FORWARD</button>
in your controller
$button_s = $this->input->post('s_button');
if( isset($button_s)){
switch($button_s){
case 'geri':
//do somthing
break;
case 'ileri':
//do somthing
break;
}
}
i have two buttons of type submit in my view:
<button type="submit" class="btn btn-default btn-xs" name="Excel">
<span class="glyphicon glyphicon-download-alt"></span> Download as Excel
</button>
<button type="submit" class="btn btn-default btn-xs" name="Resume">
<span class="glyphicon glyphicon-download-alt"></span> Download Resume
</button>
and controller:
if ($this->input->post('Resume')) {
echo "Resume Clicked";
}
if ($this->input->post('Excel')) {
echo "Excel Clicked";
}
i would like to know that which button has submitted the form for that i have written the above code..but i am not getting any echo after clicking any of the button..
i don't want to use here:
<input type='submit' name='excel' value='Excel'/>
<input type='submit' name='excel' value='Excel'/>
as it works with the type 'input' i would like to use button of type submit
Add a value to the button, ie:
<button type="submit" class="btn btn-default btn-xs" name="Resume" value="true">
<span class="glyphicon glyphicon-download-alt"></span> Download Resume
</button>
You will have a $_POST['Resume'] with value "true" in your backend code.
Ofcourse something like: name="buttonName" value="Excel" and another button with name="buttonName" value="Resume" would make have a $_POST['buttonName'] with its value either being 'Excel' or 'Resume'.
I have a form in my CakePHP with two submit buttons like so:
<div class="form-actions">
<button type="submit" name="preview" class="btn btn-large">Preview</button>
<button type="submit" name="save" class="btn btn-large">Save</button>
</div>
However because I've given them both names it returns with an error that the request has been black-holed due to the security restrictions.
How do I get around this? As I want to do different things in the controller dependant on which button was used to submit the form.
Does it work if you give them both the same name but different values:
<input type="submit" name="submitButton" value="Preview" />
<input type="submit" name="submitButton" value="Save" />
Can you do this instead?
<div class="form-actions">
<button type="button" name="preview" class="btn btn-large">Preview</button>
<button type="submit" name="save" class="btn btn-large">Save</button>
</div>
$(function() {
$(".btn.btn-large").on("click", function(){
$( "#yourForm" ).submit();
});
});
Doing this works:
<?php
echo $this->Form->submit('Save and Preview', array('div'=>false, 'name'=>'submit', 'value'=>'preview'));
echo $this->Form->submit('Publish Post', array('div'=>false, 'name'=>'submit', 'value'=>'publish'));
?>