model->validate displays errors for text field which has value in yii - model-view-controller

I have an application where user has to fill a lengthy form, so I split the form into three and created steps - Step 1, Step 2 etc. So it has to be convenient for users. Now I face a problem, after filling out the details, a text field shows an error. When using model->get Errors() the error is 'address cannot be blank'. When I use $_POST the arrays displays value for the field address. I started yii framework last week and I do not know where I have gone wrong. Any help appreciated.
The view code i use forloop to reduce my code -
<fieldset>
<?php if(!Yii::app()->user->hasFlash('success')):
Yii::app()->user->setFlash('warning','All Fields are mandatory!');
endif; ?>
<?php echo CHtml::errorSummary($model, null, null, array(
'class' => 'alert alert-danger col-lg-offset-2',
)); ?>
<?php $rrr = -1;
foreach($model->attributeLabels() as $a){ $rrr++;
if($rrr<27 && $rrr>=12){
?>
<div class="form-group">
<?php echo CHtml::activeLabel($model, $a, array('class' => 'col-lg-3 control-label')); ?>
<div class="col-lg-7">
<?php echo CHtml::activeTextField($model,array_keys($model->attributeLabels())[$rrr],array('value'=>'a','size'=>255,'maxlength'=>255,'class'=>'form-control formtype1')); ?>
</div>
</div>
<?php
}}
?>
<?php $rrr = -1;
foreach($model2->attributeLabels() as $a){ $rrr++;
if($rrr>1 && $rrr<6){
?>
<div class="form-group">
<?php echo CHtml::activeLabel($model2, $a, array('class' => 'col-lg-3 control-label')); ?>
<div class="col-lg-7">
<?php echo CHtml::activeTextField($model2,array_keys($model2->attributeLabels())[$rrr],array('value'=>'a','size'=>255,'maxlength'=>255,'class'=>'form-control formtype1')); ?>
</div>
</div>
<?php
}}
?>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-sm btn-primary" type="submit"><?php echo Yii::t("user", "Submit") ?></button>
</div>
</div>
</fieldset>
</form>

Related

ACF loadmore flexible content - how to make it work right?

I need to show 4 flexible items and load more, I don't know how to make it manually, so I tried that plugin But I can't understand how to make the shortcode correctly
That's what I generated
[ajax_load_more container_type="div" acf="true" acf_field_type="flexible" acf_field_name="review-repeater" post_type="any" meta_key="review-repeater" meta_value="" meta_compare="IN"]
The original flexible content loop without loadmore
<div class="row justify-content-center">
<?php if( have_rows('review-repeater') ):
// Loop through rows.
while ( have_rows('review-repeater') ) : the_row();?>
<div class="rev">
<?php // Case: Paragraph layout.
if( get_row_layout() == 'review-repeater' ):?>
<div class="d-flex justify-content-between">
<div class="rev-left">
<div class="raiting-review"><?php echo get_sub_field('review-raiting'); ?></div>
<div class="review-content">
<p><?php echo get_sub_field('review-content'); ?></p>
<div class="d-flex">
<?php echo get_sub_field('review-author'); ?> , <?php echo get_sub_field('review-date'); ?>
</div>
</div>
</div>
<div class="rev-right">
<img src="<?php echo get_sub_field('review-platform') ?>">
<p><?php echo get_sub_field('review-count'); ?></p>
</div>
</div>
</div>
<?php endif;
// End loop.
endwhile;
endif; ?>
I copied that code to the 'repeater template' instead of default post archive loop, but the shortcode doesn't show my content, maybe someone already used the same decision?
Already tried posts_per_page="4" parameter, it didn't help too.

codeigniter form_error() not showing error beside form-control

I am trying to show validation errors beside the form-control but form_error() is not working.
codeigniter form_error() not showing error beside form-control
The validation_errors() is working but form_error() not working beside the input control
Admin Controller
<?php
class Admin extends CI_Controller
{
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('uname','Username','required|alpha');
$this->form_validation->set_rules('pass','Password','required|max_length[12]');
$this->form_validation->set_error_delimiters("<div class='text-danger'>","</div>");
if($this->form_validation->run())
{
echo "Validation successful";
}
else
{
//echo validation_errors();
$this->load->view('Users/articleList');
}
}
}
?>
The view is
application/views/Users
<?php include('header.php'); ?>
<div class="container" style="margin-top:20px";>
<h1> Admin Form </h1>
<?php echo form_open('admin/index');?>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="Username">Username</label>
<?php echo form_input(['class'=>'form-control', 'placeholder'=>'Enter Username','name'=>'uname']);?>
</div>
</div>
<div class="col-lg-6">
<?php form_error('uname');?>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="Password">Password</label>
<?php echo form_password(['class'=>'form-control','type'=>'password',
'placeholder'=>'Enter Password', 'name'=>'pass'
]);?>
</div>
<div class="col-lg-6">
<?php form_error('pass');?>
</div>
</div>
</div>
<?php echo form_submit(['type'=>'submit', 'class'=>'btn btn-default','value'=>'Submit']); ?>
<?php echo form_reset(['type'=>'submit', 'class'=>'btn btn-default','value'=>'Reset']); ?>
</div>
<?php echo validation_errors();?>
<?php include('footer.php'); ?>
You need to echo the form_error so...
<?php form_error('pass');?>
becomes
<?php echo form_error('pass');?>
or
<?= form_error('pass');?>

Magento 1.9 order comment ADD do backend info

I am trying to add a box for customers to place a comment on their order.
I've added it to my
/checkout/cart/cart.phtml
You can see I added it here
<div class="cart-collaterals">
<div class="row">
<th><?php echo $this->__('Comments') ?></th>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<?php echo "Any special requirements regarding this order?"; ?>
<!-- COmments box -->
<td class="a-center">
<textarea name="cart[<?php echo $_item->getId() ?>][comments]" rows="3" cols="20"><?php echo $_item->getItemcomment() ?></textarea>
</td>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4">
<?php echo $this->getChildHtml('coupon') ?>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<?php echo $this->getChildHtml('checkout.cart.extra') ?>
<?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="cart-totals">
<span id='ajax_loadertotals' style='display:none'><!--<img src='<?php //echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/>--><div class="loaderTotals">Loading...</div></span>
<div class="totals">
<?php echo $this->getChildHtml('totals'); ?>
<?php if(!$this->hasError()): ?>
<ul class="checkout-types">
<?php foreach ($this->getMethods('methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
<div id="shipping-info-link">
Delivery & Shipping Information
</div>
</div>
</div>
<?php
echo $this->getLayout()->createBlock('giftcard/checkout_cart_giftcard')->setTemplate('mt/giftcard/checkout/cart/giftcard.phtml')->toHtml();
?>
<?php echo $this->getChildHtml('crosssell') ?>
</div>
Now my problem comprises here:
How can I make it so I (the sales person) can see it on the backend when the order comes through?
I don't mind changing this to the checkout page if it makes it easier. If you could give me some help with it, I'd really appreciate. I've looked around but didn't find anything useful
Thanks
1)Add custom field/attribute in sales_flat_order table using install script, the sample is given below
$installer = $this;
$installer->startSetup();
$installer->getConnection()
->addColumn(
$installer->getTable('sales/order'), 'cutom_comment', 'VARCHAR(150) NOT NULL'
);
$installer->endSetup();
2) Add the field into the checkout page
3) You can use the event "checkout_type_onepage_save_order"
4) you can get the value using Mage::app()->getRequest()->getPost('custom_comment')
5) get the order details using $order = $observer->getEvent()->getOrder();
6) save the order
$order->setCustomComment($comment);
7) add a custom layout for admin
for that ref
8 ) get order details with $order = $this->getOrder()
9) get value by $customComment = "$order->getCustomComment();"

validation errors not net to the flashdata in codeigniter

I'm trying to set validation error to the my form using flashdata in codeigniter but i cannot see the error in a view here is my code of view section. I had already read other relative questions close to my this problem but i'm not found a solution!
<?php if($this->session->flashdata('errors')): ?>
<?php echo $this->session->flashdata('errors');?>
<?php endif; ?>
<?php $attributes = array('id'=>'admin_login','class'=>'form-horizontal'); ?>
<?php echo form_open('admin/login', $attributes); ?>
<div class="form-group">
<?php
$lbl = array('class'=>'col-sm-12 col-lg-12 col-md-12 col-xs-12 control-label');
echo form_label('Email','admin_login',$lbl); ?>
<div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
<?php $data = array('
class'=> 'form-control col-sm-12 col-lg-12 col-md-12 col-xs-12',
'name'=> 'email',
'placeholder'=>'Enter your email'
); ?>
<?php echo form_input($data); ?>
</div>
</div>
<div class="form-group">
<?php
echo form_label('Password','admin_login',$lbl); ?>
<div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
<?php $data = array('
class'=> 'form-control',
'name'=> 'password',
'placeholder'=>'Password'
); ?>
<?php echo form_password($data); ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
<?php $data = array('
class'=> 'btn btn-success btn-md center mt-2',
'name'=> 'submit',
'placeholder'=>'Password',
'value'=>'LOGIN',
'type'=>'submit'
); ?>
<center>
<?php echo form_submit($data); ?>
</center>
</div>
</div>
<?php echo form_close(); ?>
This is my controller part it is name of 'admin' method name is login
public function login(){
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('password','Password','required');
// check the form has any error (any miss of rules we set in above codes
if($this->form_validation->run() == FALSE){
$this->session->set_flashdata('errors',
validation_errors());
// $this->session->set_flashdata('name','Your message');
// $errors = validation_errors();
// $this->session->set_flashdata('form_error', $errors);
// $this->session->set_flashdata('name','Your message');
// $data = array('errors'=> validation_errors());
// set_userdata() is regular way to set session, it need manually unset, there for we use flashdata
// $this->session->set_flashdata($data);
}else{
echo "its all good";
}
}
i tried so many codes, i commented out what i used so far. I set in autoload section session library also $autoload['libraries'] = array('database','form_validation','session');
Please tell me what is the wrong here.
Please try with the below code.
public function login(){
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('password','Password','required');
if($this->form_validation->run() == true){
echo "its all good";
}else{
$this->session->set_flashdata('errors', validation_errors());
}
$this->load->view('Your View Page');
}

ajax calling another ajax in yii

I can access the registration form which appears in a model window via ajax on any page as coded in the menu layout .
I need some thing on click of submit button of registration form it should get display a thank you message which is also via ajaxin the same div as that of wherein the registration form appears
registratiincontrooler
if ($model->save()) {echo "thank you for registration";return; }
registration view
<?php
/* #var $this UserProfileController */
/* #var $model UserProfile */
$this->breadcrumbs=array(
'User Profiles'=>array('index'),
'Create',
);
?>
<div id="ajax101" >
<div class="form" >
<?php $form=$this->beginWidget('UActiveForm', array(
'id'=>'registration-form',
'enableAjaxValidation'=>true,
'disableAjaxValidationAttributes'=>array('RegistrationForm_verifyCode'),
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
'htmlOptions' => array('enctype'=>'multipart/form-data'),
)); ?>
<p class="note"><?php echo UserModule::t('Fields with <span class="required">*</span> are required.'); ?></p>
<?php echo $form->errorSummary(array($model/*,$profile*/)); ?>
<div class="row">
<div class="rlabel">
<?php echo $form->labelEx($model,'username', array("style"=>"display:inline")); ?>
</div>
<div class="rtextfield">
<?php echo $form->textField($model,'username', array("style"=>"margin-left:43px")); ?>
</div>
<div class="rerror">
<?php echo $form->error($model,'username', array("style"=>"margin-left:113px")); ?>
</div>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password', array("style"=>"display:inline")); ?>
<?php echo $form->passwordField($model,'password', array("style"=>"margin-left:43px")); ?>
<?php echo $form->error($model,'password', array("style"=>"margin-left:113px")); ?>
<p class="hint">
<?php echo UserModule::t("Minimal password length 4 symbols."); ?>
</p>
</div>
<div class="row">
<?php echo $form->labelEx($model,'verifyPassword', array("style"=>"display:inline")); ?>
<?php echo $form->passwordField($model,'verifyPassword'); ?>
<?php echo $form->error($model,'verifyPassword', array("style"=>"margin-left:113px")); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email', array("style"=>"display:inline")); ?>
<?php echo $form->textField($model,'email', array("style"=>"margin-left:65px")); ?>
<?php echo $form->error($model,'email', array("style"=>"margin-left:113px")); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'user_type', array("style"=>"display:inline")); ?>
<?php echo $form->dropDownList($model,'user_type',$model->getUType()); ?>
<?php echo $form->error($model,'user_type', array("style"=>"margin-left:113px")); ?>
</div>
<?php if (UserModule::doCaptcha('registration')): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
<?php echo $form->error($model,'verifyCode'); ?>
<p class="hint"><?php echo UserModule::t("Please enter the letters as they are shown in the image above."); ?>
<br/><?php echo UserModule::t("Letters are not case-sensitive."); ?></p>
</div>
<?php endif; ?>
<div class="row submit">
<?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),array('/user/register'),array('update'=>'#ajax101')); ?>//div for form
</div>
<?php $this->endWidget(); ?>
</div>
</div><!-- form -->
<?php endif; ?>
I think the problem exists here
<?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),array('/user/register'),array('update'=>'form')); ?>//div for form
</div>
example if I have 3 menu items
home
aboutus
contact
suppose visited home when I click on register a model window with registration form appears and when i click on submit button model->save as well make another call using ajax to update that model window with thank you message
similarly with other items in menu
whats happening is it saves and redirects to /user/registration with thank you but i need same model window and not to be updated with thank message and not redirected thank message
I did try this but it did not save
<?php echo CHtml::ajaxSubmitButton(UserModule::t("Register"),'',array('update'=>'form-content')); ?>
I am calling ajax within ajax .
try with
<?php
echo CHtml::ajaxSubmitButton(signup , CHtml::normalizeUrl(array('<controller>/<action>', 'render' => true)), array(
'dataType' => 'json',
'type' => 'post',
'success' => 'function(data) {
}',
'beforeSend' => 'function(){
}','complete' => 'function(){
}',
), array('id' => 'signup', 'class' => ''));
?>
The problem is in your controller, you have to stop Yii, return; alone won't cut it.
if ($model->save()) {
if($this->isAjaxRequest)
{
ehco 'thank you for registration';
Yii::app()->end(); // to stop yii
}
else
{
// probably redirect
}
}

Resources