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

Decrypt Rijndael with Passphrase in PHP
WP-API Get Posts After a Specific Date
How Do i Print last 10 days using php? [closed]
MySQL: Joining table duplicates SUM()
how to manuplate the google api php client
Unable to get cookie in construct function
How to loop through Models find from Where clause?
Trying to keep session with curl login in twitter
Code start and end in specific time
Return total values of each column after using datepicker to select a start and end date
file_put_contents on multiple request of XML data
How can i change this select sql statement into another select sql?
This code always return $id but not $first_name [duplicate]
Laravel 5.3 array validation
recursion - How to construct a data tree without ids, data is ambigious.
Submitting a form at 3 different times using PHP

Categories

HOME
office365
focus
scroll
compilation
apk
magento-2.0
malware
fogbugz
iptables
navigation
cisco
alljoyn
erd
freertos
squirrel-sql
jpa-2.0
asciimath
jaspersoft-studio
http-authentication
wsf
adminlte
jest
sqlplus
hdl
rxjs5
ratio
jpa-2.1
tortoisemerge
introspection
python-appium
clipboard
android-service
python-imageio
npoi
matlab-app-designer
autodesk-model-derivative
infopath2010
publishing
commonsware-cwac
opnet
mongodb-3.4
epplus
caesar-cipher
shapeless
cloveretl
redgate
extbase
android-n
praat
microkernel
suds
elasticsearch-aggregation
fluid-mac-app-engine
asihttprequest
destroy
aws-kinesis-firehose
uiautomatorviewer
connect-direct
kendo-editor
google-shopping-api
nrf51
nitrousio
controllers
livecycle
traversable
deferred-rendering
exists
teamviewer
ruby-on-rails-4.1
chicagoboss
netdatacontractserializer
google-gdk
darwin
com0com
ipod
quercus
nssortdescriptor
baseadapter
rubber
maven-central
sql-function
autonumber
pbkdf2
saga
form-for
ckeditor.net
daap
clearinterval
opends
fitch-proofs
sigar
qt-mobility
solandra
mongrel
jdownloader
uninstaller
activestate
iphone-sdk-4.3
cleartype
index.dat

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App