How do I align where the form element box appears as I want at a minimum each input box to right align, have the same font etc. I tried using templating but in the end I had no idea what it was talking about.
https://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses
echo $this->Form->input('first_name',['label' => 'Tutor FirstName']);
echo $this->Form->input('last_name',['label' => 'Tutor LastName']);
echo $this->Form->input('email', ['label' => 'Email']);
echo $this->Form->input('mobile', ['label' => 'Mobile']);
echo $this->Form->input('home_phone',['label' => 'Home Phone']);
echo $this->Form->input('work_phone',['label' => 'Work Phone']);
For templating it's work like that.
In src/Controller/AppController or where you're need it
class AppController extends Controller
{
public $helpers = [
'Form' => [
'templates' => 'template_forms',
],
];
In src/config
Create a new file "template_forms.php"
<?php
$config = [
'checkboxFormGroup' => '<div class="col-xs-5"><div class="checkbox">{{label}}</div></div>',
'checkbox' => '<input type="checkbox" value="{{value}}" {{attrs}}>',
'checkboxWrapper' => '<div class="form-group"><div class="col-sm-offset-5 col-xs-7">{{label}} {{input}}</div></div>',
'inputContainer' => '<div class="form-group" {{required}} >{{content}}</div><div class="hr-line-dashed"></div>',
'input' => '<div class="col-xs-7 col-sm-10 col-lg-10"><input class="form-control input-sm" type="{{type}}" name="{{name}}" {{attrs}}></div>',
'label' => '<label {{attrs}} class="col-xs-5 col-sm-2 col-lg-2 control-label">{{text}}</label>',
'select' => '<div class="col-xs-7 col-sm-10 col-lg-10"><select class="form-control input-sm" {{attrs}} name={{name}}>{{content}}<select></div>',
'error' => '<p class="text-danger">{{content}}</p>',
'textarea' => '<div class="col-xs-7 col-sm-10 col-lg-10"><textarea class="form-control input-sm" name="{{name}}" {{attrs}}>{{value}}</textarea></div>',
'button' => '<div class="form-group"><div class="col-md-12 col-xs-12 col-sm-12 text-center"><button {{attrs}} type="submit">{{text}}</button></div></div>',
'inputContainerError' => '<div class="form-group has-error" {{required}}>{{content}}</div>{{error}}',
];
?>
This will overide all your forms in your app.
Related
I have some problem when using activeform type file. When i try to send my input in registration controller the validation from model always return it false because there is input type file that empty. After i checking from html inspect elements, it turns out that the form I created on the register page generates a new input on it with the type hidden and the same name. I still can't understand why it can generate another input type hidden and input post in controller read from that input type hidden
this is my activeform:
<?php $form = ActiveForm::begin(['id' => 'form-signup', 'action' => '/site/register/userregister', 'options' => ['enctype' => 'multipart/form-data'], 'method' => 'post' ]); ?>
<?= $form->field($model,'email')->textInput()->input('email', ['placeholder' => "Email"])->label(false) ?>
<?= $form->field($model,'photofile',
['options' => ['class' => 'form-group']])
->fileInput([])
->label('Photo file<br/><span style="font-size:12px;font-style:italic;">(Max. size 1 MB, Allowed type: .jpg, .jpeg, .png)</span>') ?>
<?= $form->field($model,'resumefile',
['options' => ['class' => 'form-group']])
->fileInput([])
->label('Resume file<br/><span style="font-size:12px;font-style:italic;">(Max. size 1 MB, Allowed type: .doc, .docx, .pdf)') ?>
<div class="form-group">
<?= Html::submitButton('Sign Up', ['class' => 'btn btn-sign', 'type' => 'submit']) ?>
</div>
<h6 class="mt-3">Have an account? <a class="font-weight-bold" href="<?= Url::to(['login/userlogin']) ?>">Sign In</a></h6>
<?php ActiveForm::end(); ?>
this my controller :
public function actionUserregister()
{
$model = new SignupModel();
if (Yii::$app->request->isPost) {
$input = Yii::$app->request->post('SignupModel');
echo "<pre>";var_dump($input);exit;
}
}
this is function in to validate rule input:
public function rules()
{
return [
['photofile', 'required'],
['photofile', 'file', 'extensions' => 'jpg,jpeg,png', 'maxSize' => 1024 * 1024 * 1],
['resumefile', 'required'],
['resumefile', 'file', 'extensions' => 'pdf,doc,docx', 'maxSize' => 1024 * 1024 * 1 ],
];
}
and this is what i see in inspect elements:
<div class="form-group field-signupmodel-photofile required">
<label class="control-label" for="signupmodel-photofile">Photo file</label>
<input type="hidden" name="SignupModel[photofile]" value> //here is the problem
<input type="file" id="signupmodel-photofile" name="SignupModel[photofile]" aria-required="true">
<p class="help-block help-block-error"></p>
</div>
<div class="form-group field-signupmodel-resumefile required">
<label class="control-label" for="signupmodel-resumefile">Resume file</label>
<input type="hidden" name="SignupModel[resumefile]" value> //here is the problem
<input type="file" id="signupmodel-resumefile" name="SignupModel[resumefile]" aria-required="true">
<p class="help-block help-block-error"></p>
</div>
what's wrong with my code above?
I've read a lot of laravel tutorial to do this but none has worked for me.
This is my form
<div class="row increment control-group">
{{-- Request Item --}}
<div class="form-group col-md-4">
<input type="text" class="form-control" name="request_item[]" placeholder="Item" />
</div>
{{-- Request Description --}}
<div class="form-group col-md-4">
<input type="text" class="form-control" name="request_description[]" placeholder="Item Description" />
</div>
<div class="form-group col-md-4">
<button class="btn btn-success" id="btn-item" type="button">Add</button>
</div>
</div>
This is my controller
$request->validate([
'request_no' => 'required|max:255',
'request_date' => 'required|date', //unique:(tablename)
'request_item' => 'required|max:255',
'request_description' => 'max:255',
'request_by' => 'required|max:255',
'request_status' => 'required|max:255',
'request_scan' => 'mimes:pdf',
'created_by' => 'max:255',
'updated_by' => 'max:255',
]);
//For file uploading
$name="";
if($request->hasfile('filename')){
$file = $request->file('filename');
$name = time()."_".$file->getClientOriginalName();
$file->move(public_path(). '/images/', $name);
}
$itemArray = Input::get('request_item');
$count = count($itemArray);
for($i = 0; $i < $count; $i++){
$request= new \Trisco\IT_Request;
$request->request_no=$request->get('request_no');
$request->request_date=$request->get('request_date');
$request->request_item=$itemArray[$i];
$request->reqeust_description='';
$request->request_by=$request->get('request_by');
$request->request_status=$request->get('request_status');
$passport->request_scan = $name; //file
$request->added_by=$request->get('username');
$request->updated_by=$request->get('username');
$request->save();
}
The request_item & request_description are both string only.
Can anyone help me?
Thanks in advance.
how about you loop on your array?
$itemArray = Input::get('request_item');
foreach ($itemArray as $value) {
$request->request_item=$value;
//your code here
//request->save()
}
What is the error?
check also the spelling --
$request->reqeust_description='';
try this >>
$request->request_item= implode(',', $request['request_item']);
I have created a custom module with some fields. I have used Varien_Data_Form for creating form with fields. I have added radios buttons, I just want to add one <div> between those radio buttons. I don't know to do that.
My radio button code for form:
$productField=$fieldset->addField('radio2', 'radios', array(
'name' => 'house_building',
'value' => '1',
'class' => 'house_building',
'values' => array(
array('value'=>'1','label'=>'House','id'=>'house'),
array('value'=>'2','label'=>'Building','id'=>'house'),
),
));
I have printed this form in view page using:
<?php echo $this->getChildHtml("suggestions_edit_form") ?>
I got 2 radio button in the following format:
<div class="value">
<input name="house_building" class="house_building" value="1" id="radio21" checked="checked" type="radio"><label class="inline" for="radio21">House</label>
<input name="house_building" class="house_building" value="2" id="radio22" type="radio"><label class="inline" for="radio22">Building</label>
</div>
Now I want to change this is in the following format with extra div tags:
<div class="value">
<div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">
<input type="radio" checked="checked" id="radio21" value="1" class="house_building validation-passed" name="house_building">
<label for="radio21" class="inline">House</label>
</div>
<div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">
<input type="radio" id="radio22" value="2" class="house_building validation-passed" name="house_building">
<label for="radio22" class="inline">Building</label>
</div>
</div>
I don't know how to do this?
Can anyone help me to fix this?
I have added a helper for that particular radio button alone:
My helper file:
class NextBits_Marketplace_Block_Form_Helper_Type extends Varien_Data_Form_Element_Text
{
/**
* Validation classes for weight field which corresponds to DECIMAL(12,4) SQL type
*
* #param array $attributes
*/
public function __construct(array $attributes = array())
{
parent::__construct($attributes);
}
public function getElementHtml()
{
$html = '<div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">';
$html .="<input type=radio checked=checked id=radio21 value=1 class=house_building validation-passed name=house_building>
<label for=radio21 class=inline>House</label></div>";
$html .='<div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">';
$html .="<input type=radio id=radio22 value=2 class=house_building validation-passed name=house_building>
<label for=radio22 class=inline>Building</label>";
$html .= '</div>';
$html .= $this->getAfterElementHtml();
return $html;
}
}
I just called this helper in my Varien_Data_Form addfield:
$fieldset->addType('type', 'NextBits_Marketplace_Block_Form_Helper_Type');
$fieldset->addField('type', 'type', array(
'name' => 'house_building',
'value' => '1',
'class' => 'house_building',
'container_class' => 'col-xs-12 col-sm-12 col-md-12 col-lg-12 customer-profile-radio'
));
Now I got the output with added div tags.
I am using yii2 for webapp. I got stuck at a very unique point & need help
I am using javascript fadeIn & Fadeout effect to show & hide the form. So to enable that effect i have to put all the three forms in a single view & have to call respective controllers(actionlogin, actionSignup & actionPasswordReset) on button click.
I declared rules for the parameters of all the three forms as 'required' for validation but when i submit the form, that time it is not working further as it wants me to fill the other two form fields as well to submit as the other two forms are also in the same view.
I also put my javascript code that call animation it is here:
<script>
jQuery(document).ready(function() {
App.setPage("login"); //Set current page
App.init(); //Initialise plugins and elements
});
</script>
<script type="text/javascript">
function swapScreen(id) {
jQuery('.visible').removeClass('visible animated fadeInUp');
jQuery('#' + id).addClass('visible animated fadeInUp');
}
</script>
anyone knows how to do this
Code is:
<section id="login" class="visible">
<?php $form = ActiveForm::begin(['id' => 'login-form', 'options' => array('role' => 'form')]); ?>
<div class="form-group">
<?= $form->field($model, 'email_address',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-group">
<?= $form->field($model, 'password', ['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordInput(); ?>
</div>
<div class="form-actions">
<?= $form->field($model, 'rememberMe',['template' => "{input} {label}"])->checkbox(); ?>
<?= Html::submitButton('Submit', ['class' => 'btn btn-danger', 'name' => 'login-button']) ?>
</div>
<?php $form = ActiveForm::end(); ?>
My signup page is
<section id="register" class="visible">
<?php $form = ActiveForm::begin(['id' => 'signup-form', 'options' => array('role' => 'form')]); ?>
<div class="form-group">
<?= $form->field($model, 'full_name',['template' => "{label}\n<i class='fa fa-font'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-group">
<?= $form->field($model, 'email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-group">
<?= $form->field($model, 'input_password',['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordInput() ?>
</div>
<div class="form-group">
<?= $form->field($model, 'input_confirm_password',['template' => "{label}\n<i class='fa fa-check-square-o'></i>\n{input}\n{hint}\n{error}"])->passwordInput() ?>
</div>
<div class="form-actions">
<?= $form->field($model, 'agreeTC',['template' => "{input}"])->checkbox(['class' => 'uniform']); ?>
<?= Html::submitButton('Signup', ['class' => 'btn btn-success', 'name' => 'signup-button']) ?>
</div>
& my request reset code is:
<section id="forgot" class="visible">
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
<div class="form-group">
<?= $form->field($model, 'reset_email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-actions">
<?= Html::submitButton('Send Me Reset Instructions', ['class' => 'btn btn-info', 'name' => 'reset-button']) ?>
</div>
<?php $form = ActiveForm::end(); ?>
Hola you could try this Make The Controller actionYourview() , instance 3 models and send to the view.
EXAMPLE controller
//your login,signup and passReset model dir
use frontend\models\login;
use frontend\models\signup;
use frontend\models\passReset;
//example if the Controller is Site (defaulOne)
class SiteController extends Controller
{
//your action
public function actionYourview(){
//1 Make your 3 models for separate
$loginModel = new login();
$signupModel = new signup();
$passResetModel = new passReset();
//this will solve your problem of the three forms as 'required'
if($loginModel->load(Yii::$app->request->post()) && $loginModel){ //if Login form is summit and validate
//do your login stuff
}else if($signupModel->load(Yii::$app->request->post())){ //if $signupModel form is summit
//do your signup stuff
}else if($passResetModel->load(Yii::$app->request->post())){ //if $passreset form is summit
// do yout pass reset stuff
}else{ // and else just render and make sure that you pass your 3 models
return $this->render('Yourview',[
'loginModelToView' =>$loginModel,
'signupModelToView' =>$signupModel,
'passResetModelToView' =>$passResetModel
]);
}
}
}
and the view just change the $model to they respective model
login
<section id="login" class="visible">
<?php $form = ActiveForm::begin(['id' => 'login-form', 'options' => array('role' => 'form')]); ?>
<div class="form-group">
<?= $form->field($loginModelToView, 'email_address',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-group">
<?= $form->field($loginModelToView, 'password', ['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordInput(); ?>
</div>
<div class="form-actions">
<?= $form->field($loginModelToView, 'rememberMe',['template' => "{input} {label}"])->checkbox(); ?>
<?= Html::submitButton('Submit', ['class' => 'btn btn-danger', 'name' => 'login-button']) ?>
</div>
<?php $form = ActiveForm::end(); ?>
signup
<section id="register" class="visible">
<?php $form = ActiveForm::begin(['id' => 'signup-form', 'options' => array('role' => 'form')]); ?>
<div class="form-group">
<?= $form->field($signupModelToView, 'full_name',['template' => "{label}\n<i class='fa fa-font'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-group">
<?= $form->field($signupModelToView, 'email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-group">
<?= $form->field($signupModelToView, 'input_password',['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordInput() ?>
</div>
<div class="form-group">
<?= $form->field($signupModelToView, 'input_confirm_password',['template' => "{label}\n<i class='fa fa-check-square-o'></i>\n{input}\n{hint}\n{error}"])->passwordInput() ?>
</div>
<div class="form-actions">
<?= $form->field($signupModelToView, 'agreeTC',['template' => "{input}"])->checkbox(['class' => 'uniform']); ?>
<?= Html::submitButton('Signup', ['class' => 'btn btn-success', 'name' => 'signup-button']) ?>
</div>
finaly the reset
<section id="forgot" class="visible">
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
<div class="form-group">
<?= $form->field($passResetModelToView, 'reset_email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?>
</div>
<div class="form-actions">
<?= Html::submitButton('Send Me Reset Instructions', ['class' => 'btn btn-info', 'name' => 'reset-button']) ?>
</div>
<?php $form = ActiveForm::end(); ?>
hope that this is what your looking. good luck
in cakephp
echo $this->Form->input('email', array('type' => 'email'));
will render
<div class="input email">
<label for="UserEmail">Email</label>
<input type="email" name="data[User][email]" value="" id="UserEmail" />
how to make this like that
<input type="email" name="data[User][email]" value="" id="UserEmail" class="input_class" style="some:style;" />
Just add a "class" and/or "style" argument to your options array.
echo $this->Form->input('email', array('type' => 'email', 'class' => 'input_class', 'style' => 'some:style' ));
See the the FormHelper documentation for a list of all options.
if you need only input without lable you can also try in this way
echo $this->Form->input('email', array('type' => 'email','div'=>false, 'class' => 'input_class', 'style' => 'some:style' ));