php


Yii2:redirect to specific action from submit button


I am not able to redirect a custom form to specific action.
What I am trying is
<?= Html::submitButton( 'delete-selected' ,['class' => 'btn btn-primary']) ?>
here delete-selected is my custom action in controller appointment.
I have also tried like this:
public function actionDeleteForm()
{
return $this->render('delete');
return $this->redirect(['delete-selected']);
}
public function actionDeleteSelected()
{
Appointment::deleteAll(['doctor_name' =>4]);
return $this->redirect(['index']);
}
What I am trying to do is actually delete some records using the form. The form name is delete having a select drop-down field.
I want to post the data to action deleteselected and use the $_POST variable in the delete query.
How can I do this?
Thanks.
Any submit button that you put on your form will submit to the url specified in the action parameter of the form. If you haven't specified one, then Yii will use the current controller/action of the form. If you want to override this behavior, then you will need to specify an action for the form. e.g.
$form = ActiveForm::begin([
'action' => 'appointment/delete-selected'
]);
in actionDeleteForm you have
return $this->render('delete');
before
return $this->redirect(['delete-selected'])
this second instruction will never be executed because you have already made a return to the function and then control has already been returned to the caller
This is somewhat a note for Joe Miller's answer. If you are supposed to override the form's action with an action of a controller, make sure you make the value of 'action' as an array:
$form = ActiveForm::begin([
'action' => ['appointment/delete-selected']
]);
It will treat the action as a route to action delete-selected in controller appointment.

Related Links

Anyway that I can get the values of a PHP array through ajax?
PHP: print success or error message on submit?
Maximum SQL Queries per page [closed]
Running Zend Framework on PHP 5.1.6 - patch or fix for ksort()?
How to design Models the correct way: Object-oriented or “Package”-oriented?
Wordpress adding article category and tags via email post(s)
Top 10 collection completion - a monster in-query formula in MySQL?
REMOTE_ADDR and IPv6 in PHP
Trying to create tiny urls, getting redirect loop
Is there a better way of designing zend_forms rather than using decorators?
How to use include within a function?
error wordpress, adjusted sidebar.php to show latest 10 posts
Use String for Pattern but Exclude it from Being Removed
Htaccess rewrite rule .aspx to .php
How to search array for duplicates using a single array?
PHP & MySQL checked checkbox problem

Categories

HOME
google-chrome
openshift
mod-rewrite
windows-8.1
long-integer
devexpress
initialization
apk
selection
sap-fiori
rangy
outlook-restapi
distributed-computing
twisted
vmware-workstation
l20n
tomcat8
gravity
coroutine
adminlte
spring-ldap
liferay-6.2
uislider
sipp
ratio
plyr
python-imageio
miniprofiler
sparkle
wampsharp
epplus
private-key
osx-lion
django-smart-selects
llvm-ir
hdiv
distributed-caching
moinmoin
nuclio
hibernate-ogm
popen
dex
annotatorjs
ogg
msg
ndk-build
nunit-console
nvda
callouts
coovachilli
wolfram-language
android-sdcard
highlighting
fdt
i2b2
json-spirit
godeps
ibm-was
opencyc
srv-record
jnlp
gql
dynamics-ax-2012-r2
embeddedwebserver
mxe
nsmutabledata
debug-symbols
password-recovery
inputbox
webmethod
maven-central
android-2.3-gingerbread
distributed-r
incognito-mode
bittorrent-sync
accountmanager
mod-perl
typesafe-stack
saga
ember-table
blobstorage
oembed
gprof
multiple-dispatch
getopt-long
autosize
kolite
gwt-celltable
litespeed
servercontrol
net-use
qt-mobility
uipasteboard
tablet-pc
photo-management
digiflow
jdownloader
tessellation
wmd-editor
version-control-migration
error-detection

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App