I'm trying to do something, which I feel really dumb for, and I'm sure is very simple. However, I'm having such a difficult time trying to find any clear examples on the web. I've tried modifying divs and css, but to no avail.
Can anyone give me a clear example of how to have, for instance 2 or more form fields on the same line in Cactive form for creating a new model, as opposed to the default one on each line.
Any help would be greatly appreciated!!
I've attempted form = 'wide form'
but I get strange formatting that ends up like in the example here:
http://imgur.com/E5VVs
Suppose this is your form (taken from Yii documentation)
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'focus'=>array($model,'firstName'),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'firstName'); ?>
<?php echo $form->textField($model,'firstName'); ?>
<?php echo $form->error($model,'firstName'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'lastName'); ?>
<?php echo $form->textField($model,'lastName'); ?>
<?php echo $form->error($model,'lastName'); ?>
</div>
<?php $this->endWidget(); ?>
You could use blueprint default built depending on the width of your page to split it into 2 columns like
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'focus'=>array($model,'firstName'),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<div class="span-8">
<?php echo $form->labelEx($model,'firstName'); ?>
<?php echo $form->textField($model,'firstName'); ?>
<?php echo $form->error($model,'firstName'); ?>
</div>
<div class="span-8 last">
<?php echo $form->labelEx($model,'lastName'); ?>
<?php echo $form->textField($model,'lastName'); ?>
<?php echo $form->error($model,'lastName'); ?>
</div>
</div>
<?php $this->endWidget(); ?>
you can get your self familiar with blueprint css or general css rules in tons of places on the web. sorry I cant help more without seeing your code. if there is already a built in magical solution for this perhaps someone else knows it?
For the below example:
<div class="row">
<?php echo $form->labelEx($model,'firstName'); ?>
<?php echo $form->textField($model,'firstName'); ?>
<?php echo $form->error($model,'firstName'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'lastName'); ?>
<?php echo $form->textField($model,'lastName'); ?>
<?php echo $form->error($model,'lastName'); ?>
</div>
All you need to do is set change a little css
.row {
width:200px; /* or whatever you prefer */
float:left;
}
Remember to clear:left after your finished floating elements or other elements may wrap oddly.
You can also use:
.row {
width:200px; /* or whatever you prefer */
display:inline-block;
}
This does something different but may be a better option for you. Your rows will stay in the dom structure unline when floating, but it may have unintended results. Try both and see what you come up with.
Just change the CSS class to "column" instead of "row" of the div prior to ones you wish to put on the same row.
Example:
To change the following four row divs ...
<div class="row"> ... </div>
<div class="row"> ... </div>
<div class="row"> ... </div>
<div class="row"> ... </div>
into three divs that sits side-by-side, and the last div on a new row, just do the following:
<div class="column"> ... </div>
<div class="column"> ... </div>
<div class="row"> ... </div>
<div class="row"> ... </div>
Or am I completely misunderstanding the question...
Related
I have setup a small webstore and I want to show this <div class ="data-plan"></div> only for one single product. My database table from where I want to match this id is called sb_files and it has these fields id table_id path type slide_link, so I am trying to get my code to go trough that table, search up the id ( Its 13040100 ) and if it matches then to show the div, else it shows an empty div. I am using the Yii2 framework, which is php based. So far I have tried this
<?php if($product->$this->id('13040100')): ?>
<ul>
<?php
$index = 1;
foreach($product->() as $prd):
if(strpos($prd->getPath(), '13040100') == true) {
?>
<div class="wrap">
<div class="data-plan" style="height:20px; width:65px; background-color:#00a651; float:right;color:white;margin:10px;text-align:center;">A+++ </div>
<div class="data-plan" style="height:20px; width:65px; background-color:#ed1c1c; float:right;color:white;margin:10px;">Datu lapa </div>
</div>
<?php
$index++;
}
endforeach;
?>
</ul>
<?php else: ?>
<div class="wrap">
</div>
<?php endif; ?>
I'm not that familiar with Yii2 framework myself, but are you sure that $product->$this->id('13040100') is correct? It looks weird to me, shouldn't it be something like $product->id('13040100')?
The solution was way easier than I tought, just had to think simple
<?php if ($product->id == '13001100'): ?>
<div class="wrap">
<div class="data-plan" style="height:20px; width:65px; background-color:#00a651; float:right;color:white;margin:10px;text-align:center;">A+++ </div>"
<div class="data-plan" style="height:20px; width:65px; background-color:#ed1c1c; float:right;color:white;margin:10px;">Datu lapa </div>
</div>
<?php else: ?>
<div class="wrap">
</div>
<?php endif;
I have a form like this as yii active record :
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'arsip-perihal-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'nama_arsip'); ?>
<?php echo $form->textField($model,'nama_arsip',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'nama_arsip'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'kode_primary'); ?>
<?php echo $form->textField($model,'kode_primary',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'kode_primary'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Keterangan'); ?>
<?php echo $form->textField($model,'Keterangan'); ?>
<?php echo $form->error($model,'Keterangan'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Can I use a HTML tag, An example textbox
First name: <input type="text" name="fname"><br>
if it can, how to use it? how to set default from $model like the form above?
Thank You,
When you use $form->textField, CActiveForm generates a textbox with ModelName[attributeName] name. So you can provide name for your textbox with this structure.
<input type="text" name="ModelName[fname]">
Note, "ModelName" is your model class, for example, "User".
I'm new in programming zend and socialengine. I have default.tpl layouts like the following:
<body id="global_page_<?php echo $identity ?>">
<div id="global_header">
<?php echo $this->content('header') ?>
</div>
<div id='global_wrapper'>
<div id='global_content'>
<div class="new class contain widget">
</div>
<?php //echo $this->content('global-user', 'before') ?>
<?php echo $this->layout()->content ?>
<?php //echo $this->content('global-user', 'after') ?>
</div>
</div>
<div id="global_footer">
<?php echo $this->content('footer') ?>
</div>
<div id="janrainEngageShare" style="display:none">Share</div>
</body>
I want to add/call widget and place it inside <div class="new class contain widget"> </div> tag. For example, I want to add widget menu main and search widget from Core Module inside this html tag, How can I achieve this? Need your help.
It is quite simple.
Use the following code, replacing the core.menu-main with name of your widget:
<div class="new class contain widget">
<?php echo $this->content()->renderWidget("core.menu-main"); ?>
</div>
The following is done using Yii and PHP already tried to ask on the Yii Forum but no solutions where given.
I have the following textArea in one of my views.
<div class="row">
<?php echo $form->labelEx($model,'ref_description'); ?>
<?php echo $form->textArea($model,'ref_description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'ref_description'); ?>
</div>
Why isn't it able to return a newline when pressing the enter key but instead it's moving to the following textField?
Whole Code:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'report-references-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'ref_name'); ?>
<?php echo $form->textField($model,'ref_name',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'ref_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_description'); ?>
<?php echo $form->textArea($model,'ref_description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'ref_description'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_quarter'); ?>
<?php echo $form->textField($model,'ref_quarter'); ?>
<?php echo $form->error($model,'ref_quarter'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_year'); ?>
<?php echo $form->textField($model,'ref_year'); ?>
<?php echo $form->error($model,'ref_year'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_date'); ?>
<?php echo $form->textField($model,'ref_date'); ?>
<?php echo $form->error($model,'ref_date'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Please suggest about anything as this thing looks really stupid and I can't seem to find a way around it tried javscript with shift+enter command and other things.
Try to disable all js code (webdeveloper addon for firefox for example).
Save to pure html page and delete particular parts. This will help you diagnose reason.
If below fail try to build pure html form without anything more than pure html tags. No css, no js.
Check your browser addons - mabye there is something.
For further help to this question regarding the Yii. What needs to be changed is in the main layout.
There is a javascript code:
$('body').on('keydown', 'input, select' , 'textarea', function(e) {
var self = $(this)
, form = self.parents('form:eq(0)')
, focusable
, next
;
if (e.keyCode == 13) {
focusable = form.find('input,a,select,button,textarea').filter(':visible:not(:disabled)');
next = focusable.eq(focusable.index(this)+1);
if (next.length) {
next.focus();
} else {
form.submit();
}
return false;
}
});
Remove the textarea from the $('body').on function ONLY!
I have a div that looks like this:
<div id="restinfoinn">
<div id="resthead">Purpose</div>
<div id="restcontstitle2"><?php echo $row_pages_here['purpose']; ?></div>
</div>
I want it to be omitted if the value of purpose is empty/null. How can I do this?
<?php if (!empty($row_pages_here['purpose'])) : ?>
<div id="restinfoinn">
<div id="resthead">Purpose</div>
<div id="restcontstitle2"><?php echo $row_pages_here['purpose']; ?></div>
</div>
<?php endif; ?>
But i think it would be better to print the empty div and deal with the design in CSS
This is really basic. You just need to do an IF check on top.
<?php if (!empty($row_pages_here['purpose'])) : ?>
<div id="restinfoinn">
<div id="resthead">Purpose</div>
<div id="restcontstitle2"><?php echo $row_pages_here['purpose']; ?></div>
</div>
<?php endif;?>
Have a look at alternative control syntax and empty