yii2


yii2 How to transfer post data from one view to two?


I am trying to create make a two-step form in yii2.
This is my SiteController.php
public function actionCreateCharacter()
{
$model = new Character();
var_dump(Yii::$app->request->post('Character'));
if ($model->load(Yii::$app->request->post())) {
$attributes=['imie','nazwisko','plec','wyznanie_id'];
if ($step1 = $model->validate($attributes)) {
//var_dump($step1);
// form inputs are valid, do something here
//var_dump(Yii::$app->request->post('Character');
return $this->render('createCharacterStep2', [
'model' => $model,
]);;
}
else {
// validation failed: $errors is an array containing error messages
$errors = $model->errors;
}
}
return $this->render('createCharacter', [
'model' => $model,
]);
}
public function actionCreateCharacterStep2()
{
$model2 = new Character();
var_dump($model);
if ($model2->load(Yii::$app->request->post())) {
var_dump(Yii::$app->request->post('Character'));
if ($model2->validate()) {
// form inputs are valid, do something here
return;
}
}
/*return $this->render('createCharacter2', [
'model' => $model,
]);*/
}
... and this is my Character.php (model + attributeLabels and tableName)
public function rules()
{
return [
[['user_id', 'imie', 'nazwisko', 'plec', 'wyznanie_id', 'avatar_src', 'avatar_svg'], 'required'],
[['user_id', 'wyznanie_id'], 'integer'],
[['avatar_svg'], 'string'],
[['imie'], 'string', 'max' => 15],
[['nazwisko'], 'string', 'max' => 20],
[['plec'], 'string', 'max' => 1],
[['avatar_src'], 'string', 'max' => 30]
];
}
I have access to $_POST by Yii::$app->request->post() in createCharacter - I get imie, nazwisko, plec and wyznanie_id.
But when I send the form in step 2 I have only post data from step 2.
How can I set the post data from step1+step2?
Sorry for my english and thanks in advance.
There is another way , if you have to table for step 1 and step 2. then save the data of step 1 first then step2 data. if you are not using two tables then you can create two form each form for each step and also create scenarios for each step according to the fields.I think this may help . You can use session also as per discussion in comments or you can use the extension array wizard but array wizard extension is not well documented , so i suggest you try my way i will help you.
While rendering step2 from step1 action, you can always pass additional data to controller's action. So I added "STEPONEPOSTS" post variable which contains all posts of step 1. Check below.
public function actionCreateCharacter()
{
$model = new Character();
var_dump(Yii::$app->request->post('Character'));
if ($model->load(Yii::$app->request->post())) {
$attributes=['imie','nazwisko','plec','wyznanie_id'];
if ($step1 = $model->validate($attributes)) {
//var_dump($step1);
// form inputs are valid, do something here
//var_dump(Yii::$app->request->post('Character');
return $this->render('createCharacterStep2', [
'model' => $model,
'STEPONEPOSTS' => Yii::$app->request->post(),
]);;
}
else {
// validation failed: $errors is an array containing error messages
$errors = $model->errors;
}
}
return $this->render('createCharacter', [
'model' => $model,
]);
}
And now in step 2 view, you can get step 1 posts variable as
$STEPONEPOSTS

Related Links

2amigos Datepicker is not working with AdminLTE in yii2
Custom filter DD for gridview yii2
Cannot update an extension to latest version in yii2
checkboxlist not rendering checkbox checked correctly
Differentiate between Frontend and Backend Logs in DBTarget Yii2
yii2 ActiveData Provider
How to use custom php function to filter in ActiveDataProvider
Yii2 sort object defaultOrder
How to display names instead of id's in GridView Yii2?
yii2 / Migration Not Working
Kartik GridView Yii2 : Toggle data not working in toolbar
yii2 http client request and repsponse
How to insert multiple times the value of an attribute in single table in yii2
yii2 SluggableBehavior is applied to only emty slug field
Yii2: Create path and url for folder inside a module
Disable ActiveForm Clientside Validation on button other than submit Yii2

Categories

HOME
pandas
arduino-uno
gremlin
fluentd
path-finding
homebrew
relay
paw-app
frameworks
gps
retrofit
angular-ui-bootstrap
ebean
adfs
slurm
elasticsearch-hadoop
dacpac
fancybox-3
correlation
spring-tool-suite
vb.net-2010
usergrid
serverless-framework
openrefine
ef-migrations
code-review
openedx
google-pagespeed
riot.js
scriptcs
physics-engine
jquery-ajaxq
web-sql
semantic-analysis
poltergeist
filezilla
greendao
jspm
fabric8
google-rich-snippets
typed.js
gammu
wallpaper
atl
mapdb
vxworks
automake
hockeyapp
neuroscience
abstract-class
uft-api
android-fingerprint-api
angularjs-factory
ibpy
android-mediaprojection
isbn
total-commander
user-accounts
filepicker
medium.com
visual-c++-2008
nxt
etsy
paypal-express
fuzzy-search
prettytensor
pickadate
execute
endeca-workbench
tmuxinator
fouc
ionic
web-controls
device-orientation
ng-animate
c3
nstableviewcell
gui-test-framework
winddk
codeigniter-routing
nsbutton
funcunit
valuechangelistener
industrial
multiprocessor
ccss
xsockets.net
tidy
jmapviewer
soundtouch
odata4j
bulkloader
excel-2003
back-stack
django-nonrel
interface-orientation
ember-app-kit
type-equivalence
angularjs-controller
e4x
dmoz
libstdc++
manchester-syntax
newtonscript
wse3.0
enter
infobox
google-friend-connect
nhibernate.search
preference
msdev
mdac
commodore
lzh
misv

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