SFormWizard is a wrapper for http://thecodemine.org
Features: Turn a normal form into a multi-step ajax form in no time. A bunch of events,options and methods (see link above).
Installation: unzip to protected/extensions/sformwizard
Make sure your form has an id (or other unique identifier)
Then, divide your normal form into steps by adding class="step" to any div AND give each div an unique id. this id can be anything. To use other elements then a div tag, please see http://thecodemine.org Leave the submit button outside of the steps Example:
...
<div class="step" id="Step1">
<div class="row">
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title',array('size'=>80,'maxlength'=>128)); ?>
<?php echo $form->error($model,'title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'content'); ?>
<?php echo CHtml::activeTextArea($model,'content',array('rows'=>10, 'cols'=>70)); ?>
<p class="hint">You may use <a target="_blank" href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.</p>
<?php echo $form->error($model,'content'); ?>
</div>
</div>
...
Minimum code:
<?php
$this->widget('ext.sformwizard.SFormWizard',array(
'selector'=>"#post-form", //change this to the jquery selector for your form
));
?>
All options and their default values (see SFormWizard.php for description of each or visit http://thecodemine.org
<?php
$this->widget('ext.sformwizard.SFormWizard',array(
'selector'=>"#post-form",
'historyEnabled' =>"false",
'validationEnabled' => "false",
'validationOptions' => "undefined",
'formPluginEnabled' => "false",
'formOptions' => '{ reset: "true",}, success: function(data) { alert("success"); }',
'linkClass' =>".link",
'submitStepClass' =>".submit_step",
'back' => ":reset",
'next' => ":submit",
'textSubmit' => "Submit",
'textNext' => "Next",
'textBack' =>"Back",
'remoteAjax' =>"undefined",
'inAnimation' => "{opacity:'show'}",
'outAnimation' => "{opacity:'hide'}",
'inDuration' => 400,
'outDuration' => 400,
'easing' => "swing",
'focusFirstInput' => "false",
'disableInputFields' => "true",
'disableUIStyles' => "false",
'jsAfterStepShown'=> '',
));
?>
A more complex but far from full featured example that uses ajax: For this we need to slightly modify out controller action. This is the how it should look in the blog demo (PostController). Note you can customize as much if you want if you understand the code.
public function actionCreate()
{
$model=new Post;
if(isset($_POST['Post']))
{
$model->attributes=$_POST['Post'];
if($model->save()){
if(Yii::app()->request->isAjaxRequest){
$comment=$this->newComment($model);
$link = CHtml::link('Click here to see your new post','view?id='.$model->id);
echo CJSON::encode($link);
exit;
}
//if the form is submitted without ajax
$this->redirect(array('view','id'=>$model->id));
}else{
if(Yii::app()->request->isAjaxRequest){
echo CJSON::encode("Error! Could not save the model");
exit;
}
}
}
$this->render('create',array(
'model'=>$model,
));
}
Next: Add a couple of placeholder divs below your form
<div id="stepmessage"></div>
<div id="data"></div>
And then the widgetcall:
<?php
$this->widget('ext.sformwizard.SFormWizard',array(
'selector'=>"#post-form",
'historyEnabled' =>"true",
'validationEnabled' => "true",
'validationOptions' => "undefined",
'formPluginEnabled' => "true",
'formOptions' => '{
success: function(data){$("#stepmessage").fadeTo(500,1,function(){ $("#stepmessage").html(data); })},
beforeSubmit: function(data){
$("#data").html("data sent to the server: " + $.param(data));
},
dataType: "json",
resetForm: true
} ',
'linkClass' =>".link",
'submitStepClass' =>".submit_step",
'back' => ":reset",
'next' => ":submit",
'textSubmit' => "Submit",
'textNext' => "Next",
'textBack' =>"Back",
'remoteAjax' =>"undefined",
'inAnimation' => "{opacity:'show'}",
'outAnimation' => "{opacity:'hide'}",
'inDuration' => 400,
'outDuration' => 400,
'easing' => "swing",
'focusFirstInput' => "true",
'disableInputFields' => "true",
'disableUIStyles' => "false",
'jsAfterStepShown'=> '
/* Available in data (data.steps ,data.settings etc):
isBackNavigation - boolean
settings - options object containing the options set for the wizard
activatedSteps - list of activated steps (visited steps)
isLastStep - boolean specifying whether the current step is a submit step
isFirstStep - boolean
previousStep - the id of the previously visited step
currentStep - the id of the current step
backButton
nextButton
steps - the steps of the wizard
firstStep - the id of the first step
*/
$("#stepmessage").html("");
$.each(data.activatedSteps, function(){
$("#stepmessage").append(this+" - ");
});
var currentstepnumber = data.activatedSteps.length;
$("#stepmessage").append("<br/>Step "+currentstepnumber+"/"+data.steps.length);',
));?>
Resources ¶
- GITHUB REPO
- Try out a demo
[The original plugin page] (http://thecodemine.org/)
nice
thanks for this feature i have been looking for it.
looks great!
Good work.
Thank you
Automatic merge of model rules and validationOptions
Hello, thanks for the plugin.
I'm wondering if it is possible to merge someway, automatically, the rules explicited in the model and place them inside the validationOptions object of the plugin without explicitly rewrite everything by hand.
Any idea about it?
Thanks!
Back button is not shown in demo project
Thanks for the great and cool extension.
I need to shoe the back button but in the demo peoject the back button is disappear.
How can i ad the back button in the form?
Thanks
I have got it.
Again thanks a lot...
Validation Rules
"Hello, thanks for the plugin. I'm wondering if it is possible to merge someway, automatically, the rules explicited in the model and place them inside the validationOptions object of the plugin without explicitly rewrite everything by hand.
Any idea about it? Thanks!"
Having the same question, it would be great to use this feature. Any ideas on how to do this without typing each rule manually?
EDIT: also i'm trying to do this, and I can't view this validation message or the rule working.
'validationOptions' => '{ rules: { field_a: "required", }, messages: { field_a: "required", } }',
Dynamic Steps
Hi, I'm having some trouble implementing the example 15 for this extension Anyone can share with me how I can implement this? From the example I only see the script but i would like to know how i can use this inside my widget in a similar way that we can see in the given example on the extension page.
Thank you in advance.
Not working
Hello, please ive been on this extension for 24 hours. Its not just working for me. i cant see the NEXT and PERVIOUS Buttons.
I followed thesame example on this page but yet, no luck.
RE: Spatan
Hi, any progress?
Post your message and your code on the forum thread so we can try to help you out.
I'm using this but took me quite some time to start using it.
Fix for submit_step problem
Out of the box, the submit_step class in a branch doesn't work as expected. It does work if you override the submitStepClass in the plugin definition statement to eliminate the leading period:
'submitStepClass'=>"submit_step",
validationOptions Not Work
Hi, Guys. Anyone know how to make 'validationOptions' work, I use sformwizard, but the validations not works. Thanks a lot, for your colaboration.
My code is:
<?php
<?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'registro-form', 'enableAjaxValidation'=>true, //'enableClientValidation'=>true 'clientOptions'=>array( 'validateOnSubmit'=>true, ) )); ?>/ @var $this RegistroController /
/ @var $model Registro /
/ @var $form CActiveForm /
error_reporting(E_ALL);
?>
Los datos con * son requeridos.
<?php echo $form->errorSummary($model); ?><div id="stepmessage"></div> <div id="data"></div>
<?php $this->endWidget(); ?>
<?php
$this->widget('ext.sformwizard.SFormWizard',array( 'selector'=>"#registro-form", 'historyEnabled' =>"true", 'validationEnabled' => "true", 'validationOptions' => '{ alert("el valor es baz"); rules: { "#grupinv" : "required", "#correo_alterno" : { required: "true", email: "true" } }, messages: { "#grupinv": "Please specify your country", "#correo_alterno": { required: "Please specify your email", email: "Correct format is name@domain.com" } } }', 'formPluginEnabled' => "true", 'formOptions' => '{ success: function(data){$("#stepmessage").fadeTo(500,1,function(){ $("#stepmessage").html(data); })}, beforeSubmit: function(data){ $("#data").html("data sent to the server: " + $.param(data)); }, dataType: "json", resetForm: true } ', 'linkClass' =>".link", 'submitStepClass' =>".submit_step", 'back' => ":reset", 'next' => ":submit", 'textSubmit' => "Guardar", 'textNext' => "Siguiente", 'textBack' =>"Atrás", 'remoteAjax' =>"undefined", 'inAnimation' => "{opacity:'show'}", 'outAnimation' => "{opacity:'hide'}", 'inDuration' => 400, 'outDuration' => 400, 'easing' => "swing", 'focusFirstInput' => "true", 'disableInputFields' => "true", 'disableUIStyles' => "true", 'jsAfterStepShown'=> ' /* Available in data (data.steps ,data.settings etc): isBackNavigation - boolean settings - options object containing the options set for the wizard activatedSteps - list of activated steps (visited steps) isLastStep - boolean specifying whether the current step is a submit step isFirstStep - boolean previousStep - the id of the previously visited step currentStep - the id of the current step backButton nextButton steps - the steps of the wizard firstStep - the id of the first step */ $("#stepmessage").html(""); $.each(data.activatedSteps, function(){ $("#stepmessage").append(this+" - "); $("#stepmessage").append($("#nombres_apellidos").val()+"data sent to the server: "+data.activatedSteps.length); }); var currentstepnumber = data.activatedSteps.length; $("#stepmessage").append("<br/>Paso "+currentstepnumber+" de "+data.steps.length);', ));?>
updated extension
You can find an updated version here (3.0.7) :
https://github.com/tpruvot/SFormWizard
Will this work in yii2?
Hi
I need to do multi step in yii2? Will your plugin work in yii2?
Can you guide me how to get this done in yii2?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.