Laravel FORM::select not being displayed in webpage - forms

when creating the register page I am trying to pass in an array from the database ('id' and 'name') into a select field box on the register form but it wont display anything, its really bazar, when I inspect it in the browser I can see the div container and all of the options correctly in proper fields but for some reason there is no select field (total not visible in the browser) lol, I tried it with hard coded values and values from db and nothing is getting the select field to work, any help is greatly appreciated!
login.blade.php
#extends('layouts.main')
#section('content')
<div class="page-footer" id="contactus">
<div class="container">
<div class="row" align="center">
<div class="col 16 s12">
<h4 class="black-text">Account Center</h4>
</div>
</div>
<div class="row" style="margin-bottom: 0px;">
<div class="col 16 s12 m6" align="center">
<h5 class="black-text">Login</h5>
{!! Form::open(['method'=>'POST', 'action'=>'UsersController#store', 'class'=>'pure-form pure-form-stacked']) !!}
<br/>
<div class="input-field">
<i class="material-icons prefix fa fa-at"></i>
{!! Form::label('loginEmail', 'E-mail') !!}
{!! Form::email('loginEmail', null, ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-key"></i>
{!! Form::label('loginPassword', 'Password') !!}
{!! Form::password('loginPassword', ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::button('<i class="material-icons left fa fa-send"></i>Login', ['type' => 'submit', 'class'=>'waves-effect waves-light btn']) !!}
</div>
{!! Form::close() !!}
<br/><br/>
</div>
<div class="col 16 s12 m6" align="center">
<h5 class="black-text">Register</h5>
{!! Form::open(['method'=>'POST', 'action'=>'UsersController#store', 'class'=>'pure-form pure-form-stacked']) !!}
<br/>
<div class="input-field">
<i class="material-icons prefix fa fa-at"></i>
{!! Form::label('registerEmail', 'E-mail') !!}
{!! Form::email('registerEmail', null, ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-key"></i>
{!! Form::label('registerPassword', 'Password') !!}
{!! Form::password('registerPassword', ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-key"></i>
{!! Form::label('confirm', 'Confirm Password') !!}
{!! Form::password('confirm', ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-building"></i>
{!! Form::label('role_id', 'Role') !!}
</br>
{!! Form::select('role_id', [''=>'Choose Option'] + $organizationTypes, null, ['class'=>'form-control', 'style'=>' resize:vertical; ', 'id' => 'industryId'])!!}
</div>
</br>
</br>
</br>
</br>
<div class="input-field">
<i class="material-icons prefix fa fa-building"></i>
{!! Form::label('organizationName', 'Organization Name') !!}
{!! Form::password('organizationName', ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::button('<i class="material-icons left fa fa-send"></i>Register', ['type' => 'submit', 'class'=>'waves-effect waves-light btn']) !!}
</div>
{!! Form::close() !!}
<!-- loading spinner -->
<div class="preloader-wrapper active" id="sendEmailLoader">
<div class="spinner-layer spinner-yellow-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
<!-- end loader -->
</form>
<br/><br/>
</div>
</div>
</div>
</div>
#endsection
AuthController.php
<?php
namespace App\Http\Controllers\Auth;
use App\OrganizationType;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* #var string
*/
protected $redirectTo = '/users';
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'email' => 'required|email|max:255|unique:users',
'password' => array(
'required',
'min:6',
'confirmed',
'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/'
),
'organizationType' => 'required',
'organizationName' => 'required|max:255',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
public function getLogin()
{
//
$organizationTypes = OrganizationType::lists('name','id')->all();
//return $organizationTypes;
return view('auth.login', compact('organizationTypes'));
}
}
routes.php
Route::get('/login', 'Auth\AuthController#getLogin');

method lists() is deprecated, use pluck() instead.
to get your select do this:
In your controller first change lists() to pluck() (i hope you have laravel version 5.2+)
$organizationTypes = OrganizationType::pluck('name','id')->toArray();
and in view do this
{!! Form::select('role_id', $organizationTypes, null, ['class'=>'form-control'])!!}
update
OK you are using css template materialize and because of template you need to append right class for select box...this will work but probably needs some other classes too:
{!! Form::select('role_id', $organizationTypes, null, ['class' => 'browser-default', 'placeholder' => 'Choose Option'])!!}
{!! Form::label('role_id', 'Organization name') !!}

Related

Codeigniter 3 select form error not showing on form submit

I was following a youtube tutorial on making a codeigniter college management system
but i am stuck at a point.. when i try to submit the form on wamp server
select form fields not showing requied error on form submit
i have checked the name fields of the form inputs matching the database table but still when the form is submitted without any fiilling any fields
the role and gender select field errors doesnt show
here is my code
controller
welcome.php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
//$this->load->helper('url');
$this->load->view('home');
}
public function adminRegister()
{
$this->load->model('queries');
$roles = $this->queries->getRoles();
// print_r($roles);
// exit();
$this->load->view('register',['roles'=>$roles]);
}
public function adminLogin()
{
echo 'Login';
}
public function adminSignup()
{
//echo 'Registered succesfully';
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('gender','Gender','required');
$this->form_validation->set_rules('role_id','Role','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('confpwd','Password Again','required');
$this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
if($this->form_validation->run()){
echo 'validation passed';
}else{
//echo 'validation error';
echo validation_errors();
}
}
}
and views
register.php
<?php include('inc/header.php');?>
<div class="container mt-2">
<?php echo form_open('welcome/adminSignup',['class'=>'form-hoizontal']);?>
<h3 class="text-center display-4">ADMIN REGISTER</h3>
<hr/>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label for="username" class="mt-2">User name:</label>
</div>
<div class="col-md-9">
<!-- <input type="text" class="form-control" placeholder="User name" id="username"> -->
<?php
$data = array(
'type' => 'text',
'name' => 'username',
'placeholder' => 'Enter Username',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('username','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Email address:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<?php
$data = array(
'type' => 'email',
'name' => 'email',
'placeholder' => 'Enter Email',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('email','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="gender" class="mt-2">Gender:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<select class="form-control" name="gender">
<option>Select</option>
<option>Male</option>
<option>Female</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('gender','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Role:</label>
</div>
<div class="col-md-9">
<select class="form-control" name="role_id">
<option>Select</option>
<?php if(count($roles)) { ?>
<?php foreach ($roles as $role){?>
<option><?php echo $role->rolename;?></option>
<?php }
} ?>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('role_id','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'password',
'placeholder' => 'Enter Password',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('password','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password Again:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'confpwd',
'placeholder' => 'Enter Password Again',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('confpwd','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<!-- <button type="submit" class="btn btn-dark float-right">Register</button> -->
<div class="float-right">
<?php echo form_submit('Register', 'Register',"class='btn btn-dark'"); ?>
<?php echo anchor('welcome','GO BACK',['class'=>'btn btn-warning']);?>
</div>
</div>
</div>
<?php echo form_close(); ?>
</div>
<?php include('inc/footer.php');?>
here is screenshot
The errors are not showing because your select boxes are always submitting a value. When you select an option in the selectbox and no value attribute is specified, the value after the <option> tag is being sent to the server.
To trigger the required rule, you need to send an empty string.
To do this, you can either use an empty <option> tag for the placeholder:
<select class="form-control" name="gender">
<option></option>
<option>Male</option>
<option>Female</option>
</select>
Or set the value attribute of the placeholder to an empty string:
<select class="form-control" name="gender">
<option value="">Select</option>
<option>Male</option>
<option>Female</option>
</select>
Try below Code:
<select class="form-control" name="gender">
<option></option>
<option value="male">Male</option>
<option valie="female">Female</option>
</select>

Display pure html code in tinymce laravel

Hi I am using tinmymce in laravel5. I create blogposts where i need to display code snippets.
for example i want to display this bit of code snippet <meta http-equiv="X-UA-Compatible" content="IE=edge"> and here is my source code as seen in tinymce:
<pre><code><meta http-equiv="X-UA-Compatible" content="IE=edge"></code></pre>
And this is how it is saved in my database:
<pre><code><meta http-equiv="X-UA-Compatible" content="IE=edge"></code></pre>
The problem is when i pull that data to edit in my view using the same tinymce editor
I see nothing, its blank. if i check the source code all is left there is <pre></pre>
Here is my create page:
#extends('layouts.app')
#section('content')
<section class="articles-show">
<div class="container">
<div class="row">
<div class="col-sm-10 articles-page">
<h1>Create Article</h1>
{{-- #if (Auth::user()->isAuthor() || Auth::user()->isAdmin()) --}}
{!! Form::open(['method' => 'POST', 'action' => 'ArticlesController#store', 'files' => true]) !!}
#include('partials.error-message')
<div class="form-group">
{!! Form::label("title", "Title:") !!}
{!! Form::text("title", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label("body", "Body:") !!}
{!! Form::textarea("body", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('photo_id', 'Featured Image:') !!}
{!! Form::file('photo_id', array('class' => 'form-control')) !!}
</div>
<div class="form-group">
{!! Form::label("category_id", "Category:") !!}
{!! Form::select("category_id[]", $categories, null, ['id' => 'tag_list', 'class' => 'form-control', 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label("meta_desc", "Meta Description:") !!}
{!! Form::text("meta_desc", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Create Article", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
{{-- #endif --}}
</div>
<div class="col-sm-2 articles-page">
{!! Form::open(['method' => 'POST', 'action' => 'CategoryController#store']) !!}
<br>
<div class="form-group">
{!! Form::label("name", "Category Name:") !!}
{!! Form::text("name", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Create Category", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</section>
#include('partials.select-2-script')
#include('partials.tinymceScript')
#endsection
Here is my edit page:
#extends('layouts.app')
#section('content')
#section('content')
<section class="articles-show">
<div class="container">
<div class="row">
<div class="col-sm-10 articles-page">
<h1>Create Article</h1>
{!! Form::model($article, ['method' => 'PATCH', 'action' => ['ArticlesController#update', $article->id], 'files' => true]) !!}
#include('partials.error-message')
<div class="form-group">
{!! Form::label("title", "Title:") !!}
{!! Form::text("title", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label("body", "Body:") !!}
{!! Form::textarea("body", null, ['id' => 'mytextarea', 'class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('photo_id', 'Featured Image:') !!}
{!! Form::file('photo_id', array('class' => 'form-control')) !!}
</div>
<div class="form-group">
{!! Form::label("category_id", "Category:") !!}
{!! Form::select("category_id[]", $categories, null, ['id' => 'tag_list', 'class' => 'form-control', 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label("meta_desc", "Meta Description:") !!}
{!! Form::text("meta_desc", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Edit Article", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
{!! Form::open(['method' => 'DELETE', 'action' => ['ArticlesController#destroy', $article->id]]) !!}
<div class="form-group">
{!! Form::submit("Delete Article", ['class' => 'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
</div>
<div class="col-sm-2 articles-page">
{!! Form::open(['method' => 'POST', 'action' => 'CategoryController#store', 'files' => true]) !!}
<br>
<div class="form-group">
{!! Form::label("name", "Category Name:") !!}
{!! Form::text("name", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Create Category", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</section>
#include('partials.select-2-script')
#include('partials.tinymceScript')
#endsection
and here is my tinymce script page that is in partials which i have included in create and edit pages:
<script src="http://code.jquery.com/jquery.js"></script>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
var editor_config = {
path_absolute : "{{ URL::to('/') }}/",
selector: "textarea",
//entities : "60,lt,62,gt,38,amp",
// entity_encoding: "raw",
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern spellchecker"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media | spellchecker",
menubar: "tools",
relative_urls: false,
file_browser_callback : function(field_name, url, type, win) {
var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;
var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
if (type == 'image') {
cmsURL = cmsURL + "&type=Images";
} else {
cmsURL = cmsURL + "&type=Files";
}
tinyMCE.activeEditor.windowManager.open({
file : cmsURL,
title : 'Filemanager',
width : x * 0.8,
height : y * 0.8,
resizable : "yes",
close_previous : "no"
});
}
};
tinymce.init(editor_config);
<!-- -->
</script>
I have searched everywhere, tried everything posted in tinymce forums etc. Stackoverflow is my last hope :)
Use :
{!! $varable !!}
this will echo the value for Html engine and Tinymce
Don't use:
{{$variable}}
I've spent half a day trying to solve it and finally I've figured out that here is the problem with textarea and Blade, not with tinyMCE. If you are using something like
<textarea calss="js-wysiwyg">
{{ $blog->text }}
</textarea>
and the blog text contains some html tags like <pre>, <input> or <form>, textarea will do a bit of magic with it and after tinyMCE initializing you will end up with very strange output (nothing outputted in your case and rendered html input in mine :) ). So, you have 2 different options:
<textarea calss="js-wysiwyg">
{{ htmlentities($blog->text) }}
</textarea>
or
<div contenteditable="true" calss="js-wysiwyg">
{{ $blog->text }}
</div>
Variant with htmlentities is better because you don't need to create some jQuery solution for passing value of the div in request (because divs don't have 'name' attributes)
Hope this will help someone!

Dynamic Form Elements Population Laravel 5 Blade

I have created a form where a user can add elements depending on the number of names needed. My code is as follows
<div class="input_fields_wrap">
<div class="row">
<div class="form-group col-xs-12 col-sm-3 form-group-sm">
{!! form::label('first_name[]', 'First Name: ') !!}
{{--{!! form::text('first_name[]', null, ['class' => 'form-control', 'placeholder' => 'First Name']) !!}--}}
<input type="text" name="first_name[]" value="" class="form-control" placeholder="First Name">
</div>
<div class="form-group col-xs-12 col-sm-3 form-group-sm">
{!! form::label('middle_name[]', 'Middle Name[s]: ') !!}
{{--{!! form::text('middle_name[]', null, ['class' => 'form-control', 'placeholder' => 'Middle Name[s]']) !!}--}}
<input type="text" name="middle_name[]" value="" class="form-control" placeholder="Middle Name[s]">
</div>
<div class="form-group col-xs-12 col-sm-3 form-group-sm">
{!! form::label('last_name[]', 'Last Name: ') !!}
{{--{!! form::text('last_name[]', null, ['class' => 'form-control', 'placeholder' => 'Last Name']) !!}--}}
<input type="text" name=last_name[]" value="" class="form-control" placeholder="Last Name">
</div>
</div>
</div>
<button class="btn btn-success add_field_button"><i class="fa fa-user"></i> Add Another Person (Max 5)</button>
When the form fails it's validation it should return to the original form, display validation errors and re-populate the form.
Obviously this needs to loop though the returned values but I am unable to get the returned form content for these elements.
I can dump out the errors but not sure how to get the returned form element values :(

cakephp login form not working

I've made a login form and now I need to have the same code in one of my Cakephp project but it doesn't work..
<!-- LOGIN SECTION START -->
<section id="login">
<div class="container">
<div class="row">
<div class="Absolute-Center is-Responsive">
<h1 class="text-center form-login-title">Log In</h1>
<div class="col-sm-12 col-md-12 col-md-offset-0">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User');?>
<div class="form-group inner-icon right-icon"> <!--USER NAME-->
<i class="glyphicon glyphicon-user"></i>
<input class="form-control" type="text" name='username' placeholder="username"/>
</div>
<div class="form-group inner-icon right-icon"> <!--PASSWORD-->
<i class="glyphicon glyphicon-lock"></i>
<input class="form-control" type="password" name='password' placeholder="password"/>
</div>
<?= $this->Form->end(__('Sign In')); ?> <!-- SUBMIT BUTTON -->
<div class="form-group text-center">
Forgot Password
</div>
</div><!-- /.col-sm-12 -->
</div>
</div><!-- /.row -->
</div><!-- /.container -->
</section>
<!-- LOGIN SECTION END -->
So with that snippet does not let me log in (the back end is not the problem)
Oh, and how can I change the submit button style ? I've tried <?= $this->Form->end(__(Sign In), array('class'=>'btn-primary')); ?>
but it doesn't help much :(
Thanks
You should use the CakePHP helpers, so instead plain HTML:
Change this:
<input class="form-control" type="text" name='username' placeholder="username"/>
Into this:
<?php
echo $this->Form->input('username', array(
'class' => 'form-control',
'placeholder' => 'username',
'label' => false
));
?>
And this:
<input class="form-control" type="password" name='password' placeholder="password"/>
Into this:
<?php
echo $this->Form->input('password', array(
'type' => 'password',
'class' => 'form-control',
'placeholder' => 'password',
'label' => false
)); ?>
CakePHP Helper will print the input fields with the correct name values for each one, so in your controller you receive the correct data through the array $this->request->data.
For the button style try:
<?=$this->Form->end('Sign In', array('class'=>'btn btn-danger'))?>
Like Ricardo mentioned,use CakePHP syntax and conventions.
Also it will be more helpful if you provide your controller actions. Probably your action is wrong.
For more things about forms and auth here:
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

Zend Form Decorators issue

*I speak English not well. So i'm going to post the code now.*
Form code:
protected $elementDecorators = array('ViewHelper','Errors','Description','Label',
array('HtmlTag',array('tag' => 'div','class' => '_wrapperElement')
));
public function init(){
$this->addElement('text','mytext',array(
'class' => '_inputText',
'label' => 'Mytext',
'required' => true,
'decorators' => $this->elementDecorators
));
$this->setDecorators(array('FormElements',array('HtmlTag',array('tag' => 'div','class' => '_formWrapper')),'Form'));
}
Output:
<form method="post" action="" enctype="application/x-www-form-urlencoded">
<div class="_formWrapper">
<div class="_wrapperElement">
<label class="required" for="mytext">Mytext</label>
<input type="text" class="_inputText" value="" id="mytext" name="mytext">
</div>
</div>
</form>
Now i want a div wraps Label and Input element like this:
<form method="post" action="" enctype="application/x-www-form-urlencoded">
<div class="_formWrapper">
<div class="_wrapperElement">
<div class="_wrapperLabel">
<label class="required" for="mytext">Mytext</label>
</div>
<div class="_wrapperInput">
<input type="text" class="_inputText" value="" id="mytext" name="mytext">
</div>
</div>
</div>
</form>
How to do that?
I tried many times but i can't do it.
Thanks!
protected $elementDecorators = array('ViewHelper','Errors','Description', array('Label', array('tag' => 'div', 'class' => '_wrapperLabel')
),
array('HtmlTag',array('tag' => 'div','class' => '_wrapperInput')
));
i found the solution that render decorators to ViewScript.