jaredhoyt / cakephp-wizard Goto Github PK
View Code? Open in Web Editor NEWPlugin for handling multi-page forms
Plugin for handling multi-page forms
I'm trying to make a wizard that will reset if the user navigates away from the wizard but i also want to use plotbranching.
The wizard seems to reset when i branch to my 'fail' branch, if i disbale autoReset it works fine
I have included my Component configuration below
$this->Wizard->nestedViews = true;
$this->Wizard->wizardAction = 'step';
$this->Wizard->defaultBranch = true;
$this->Wizard->steps = array('details', 'address', array('success' => array('payment', 'complete'), 'fail' => array('complete')));
$this->Wizard->autoReset = true;
Please could you update the repo to specify which license this project is distributed under?
Hello could you please write some few lines in documentation, how drafts works and how it was intented to use? It would help other people to use and extend this plugin. Thank You.
Is it impossible to use branch mechanism at first step?
I can't figure out how to do it. I just need to skip first step in particular condotion.
My variants:
public function beforeFilter() {
$this->Wizard->steps = array(array('childs' => array('child')), 'details', 'template', 'invite', 'message');
$this->Wizard->defaultBranch = false;
}
public function wizard($step = null) {
$this->Wizard->branch('childs', true);
$this->Wizard->process($step);
}
Doesn't work. (error incorrect step. But if i returns to /wizard all goes correctly)
public function beforeFilter() {
$this->Wizard->steps = array(array('family' => array('details'), 'childs' => array('child', 'details')), 'template', 'invite', 'message');
//$this->Wizard->defaultBranch = false;
}
doesnt work after adding
public function wizard($step = null) {
$this->Wizard->branch('childs');
$this->Wizard->process($step);
}
but works without $this->Wizard->branch('childs');
How can i got this work?
Hi,
My Wizard works just fine but I cannot make it work in the end. The _afterComplete ( ) method isn't called. My wizardAction is a prefixed action ( prefix_add ). I tried to set it in the cake array format but it seems to me that your plugin doesn't support it. The problem comes from here, I think :
line 234 to 248
if ($proceed) {
$this->save();
if (next($this->steps)) {
if ($this->autoAdvance) {
$this->redirect();
}
$this->redirect(current($this->steps));
} else {
$this->Session->write('Wizard.complete', $this->read());
$this->reset();
$this->controller->redirect($this->wizardAction);
}
}
When there's a next step, you call Wizard::redirect that builds the url without paying attention to any prefix ( line 361 ). Cake seems to understand alone that it's a prefix, maybe because there's a parameter added at the end and renders the different steps correctly.
But when there is no next step however, you're using directly the Controller::redirect method. A prefix having already been set, the wizard tries in my case to redirect to the name of the method as it is set litterally in my beforeFilter callback but adds the prefix a second time, redirecting to a non existing prefix_prefix_add action.
I tried setting the url in the cake array format, but I fails right from the beginning because since the Wizard::redirect ( ) method calls the Controller::redirect with wizardAction as 'action' parameter, the Router crashes.
Here's what I'm proposing in Wizard::redirect ( ) :
function redirect($step = null, $status = null, $exit = true) {
if ($step == null) {
$step = $this->_getExpectedStep();
}
$controller = Inflector::underscore($this->controller->name);
if (is_array($this->wizardAction)) {
$url = $this->wizardAction;
$url['controller'] = $controller;
} else {
$url = array('controller' => $controller , 'action' => $this->wizardAction);
}
$url[] = $step;
$this->controller->redirect($url, $status, $exit);
}
Changing the name of the wizardAction parameter to something like wizardUrl may also be interesting if you decide that supporting prefixes is necessary
Thanks for all the work, it saved me hours of work !
I can't put die; or debug(); into the prepare/process or complete methods because of how the wizard works. It would be nice if at the very least placing debug or die could give some feedback on screen instead of merely redirecting (and therefore losing all the output)
Whenever I submit on my 'location' step, i use $this->Wizard->branch( 'us' ) to switch to the US branch below, but I get the following error:
Step validation: review is not a valid step. [APP/plugins/wizard/controllers/components/wizard.php, line 300]
$this->Wizard->steps = array(
'location',
array(
'us' => array(
'dwollainfo'
),
'nonus' => array(
'numbers',
'accounttype',
array(
'personal' => array(
'personalinfo'
),
'business' => array(
'businessinfo'
)
),
)
),
'review'
);
It SHOULD be taking me to the Us -> Dwollainfo step right? Why is it throwing an error that review is not a valid step?
This is a feature request, not a bug.
Complex PBN works great with cakephp-wizard but what about simple PBN? If a given input is a certain value I might want to add a single step, for instance. The PBN in cakephp wizard is not terribly efficient for this scenario.
I envision the API could be trivially extended with getNextStep() and setNextStep() methods in the _processStepX() part of the controller - and, conceptually, that may be a simpler way to envisage complex PBN as well.
In any case the following code works for me - you may want to update the wiki to list this as an alternative to the PBN you have designed:
public function wizard($step = null) {
$wizard_data = $this->Wizard->read();
//e.g. $condition = !empty($wizard_data['stepname']['data_to_branch_on'];
if($condition)) {
$first_array = array_splice ($this->wizard_steps_array, 0, $step_number);
$this->wizard_steps_array = array_merge ($first_array, $additional_steps_array, $this->wizard_steps_array);
}
$this->Wizard->steps = $this->wizard_steps_array;
}
All the best,
Daniel
Im using your example for branching when i click on male or female i get this error
This webpage has a redirect loop
The webpage at http://localhost/fit/clients/wizard/Array has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
the url looks like this
clients/wizard/Array
am i missing something here ?
//controller
$this->Wizard->steps = array('step1', 'step2', 'gender', array('male' => array('step3')), 'step4', array('female' => array('step5')));
function _processGender() {
$this->Owner->set($this->data);
if($this->Client->validates()) {
if($this->data['Owner']['gender'] == 'female') {
$this->Wizard->branch('female');
} else {
$this->Wizard->branch('male');
}
return true;
}
return false;
}
//view
$options=array('male'=>'male','female'=>'female');
echo $this->Form->radio('Owner.gender',$options,$attributes);?>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.