codeigniter form_radio() - codeigniter

---- I have solved the radio button problem. now the problem is i need to send the value $thing->quistionNo in the controller along with the answer.---
<?php echo form_open(base_url() . 'things/show');
foreach ($data->result()as $thing) {
echo $thing->questionNo.". ".$thing->question;
$qno =array(
'name' => 'qno',
'id' => 'qno',
'value' => $thing->questionNo
);
//$qno = $thing->questionNo;
var_dump($qno);
?>
<ul>
<li>
<div>
<?php echo form_radio("answer", "1", (set_value("answer") == "1"));
echo $thing->option1; ?>
</div>
</li>
<li>
<div>
<?php echo form_radio("answer", "2", (set_value("answer") == "2"));
echo $thing->option2; ?>
</div>
</li>
<li>
<div>
<?php echo form_radio("answer", "3", (set_value("answer") == "3"));
echo $thing->option3; ?>
</div>
</li>
<li>
<div>
<?php echo form_radio("answer", "4", (set_value("answer") == "4"));
echo $thing->option4; ?>
</div>
</li>
<?php }
echo form_submit(array('name' => 'submit'), 'Submit Answer');
echo form_close();
?>
</body>
</html>

There's a problem with your form_submit.
form_submit has 2 parameters, which accept name and value of the input.
echo form_submit('oksubmit', 'Submit!');
which will produce:
<input type="submit" name="oksubmit" value="Submit!" />
For more information you can refer to here

Related

if click default button address should be default

One user multiple shipping address how to make it as default,if click the make as default button,that address should be default and remaining all address shown the make as default button in a particular address box,except default address box.
view page
<?php foreach ($buyer_Address as $row) { ?>
<div class="col-md-4">
<div class="panel panel-default add_min_height">
<div class="panel-heading">Default:</div>
<input type="hidden" name="de" id="de" value="<?php echo $row->b_id; ?>">
<div class="panel-body">
<address><?php echo $row->b_fullname; ?><br>
<?php echo $row->b_street_address; ?>,<?php echo $row->b_locality ?>,<br>
<?php echo $row->b_landmark; ?>,
<?php echo $row->b_city; ?>, <?php echo $row->b_state; ?>,<?php echo $row->b_pincode; ?>
India
Phone number: <?php echo $row->b_mobile_number; ?></address>
</div>
<div class="panel-footer">
<a href="<?php echo base_url(); ?>index.php/welcome/buyereditaddress?id=<?php echo $row->b_id; ?>" >Edit</a>
<i class="fa fa-ellipsis-v"></i>
Delete
<i class="fa fa-ellipsis-v"></i>
<?php if ($row->status == '0') { ?>
<button type="submit" style="color:#337ab7;background: none !important;border: none;" name="default" id="default">Make as deafault</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
controller
public function defaultAddress() {
$id = $this->input->post('de');
$this->BuyerProfile_Model->defaultAddress($id);
redirect('welcome/buyeraddresses');
}
model
function defaultAddress($id) {
$this->db->trans_start();
$this->db->query("UPDATE buyer_order_address SET status = '0' WHERE b_id = '$id'");
$this->db->query("UPDATE buyer_order_address SET status = '1' WHERE b_id = '$id'");
$this->db->trans_complete();
}

How add create AdditionalActionBlockHtml into massactions in category products grid in magento?

How add create AdditionalActionBlockHtml into massactions in category products grid?
like this status
I founded getAdditionalActionBlockHtml in app/design/adminhtml/default/default/template/widget/grid/massaction.phtml
But I'm dont understand how it's work.
<div class="right">
<div class="entry-edit">
<?php if ($this->getHideFormElement() !== true):?>
<form action="" id="<?php echo $this->getHtmlId() ?>-form" method="post">
<?php endif ?>
<?php echo $this->getBlockHtml('formkey')?>
<fieldset>
<span class="field-row">
<label><?php echo $this->__('Actions') ?></label>
<select id="<?php echo $this->getHtmlId() ?>-select" class="required-entry select absolute-advice local-validation">
<option value=""></option>
<?php foreach($this->getItems() as $_item): ?>
<option value="<?php echo $_item->getId() ?>"<?php echo ($_item->getSelected() ? ' selected="selected"' : '')?>><?php echo $_item->getLabel() ?></option>
<?php endforeach; ?>
</select>
</span>
<span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-hiddens"></span>
<span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-additional"></span>
<span class="field-row">
<?php echo $this->getApplyButtonHtml() ?>
</span>
</fieldset>
<?php if ($this->getHideFormElement() !== true):?>
</form>
<?php endif ?>
</div>
<div class="no-display">
<?php foreach($this->getItems() as $_item): ?>
<div id="<?php echo $this->getHtmlId() ?>-item-<?php echo $_item->getId() ?>-block">
<?php echo $_item->getAdditionalActionBlockHtml() ?>
</div>
<?php endforeach; ?>
</div>
</div>
I decided this via add methods in massactions
public function addMassAction($observer)
{
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction' && $block->getRequest()->getControllerName() == 'catalog_product')
{
$stores = Mage::getSingleton('adminhtml/system_config_source_store')->toOptionArray();
$block->addItem('export', array(
'label' => Mage::helper("prodestransl")->__("Export"),
'url' => Mage::helper('adminhtml')->getUrl('prod/adminhtml_export/run'),
'additional' => array(
'stores' => array(
'name' => 'stores',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('catalog')->__('Stores'),
'values' => $stores
)
)
));
}
}

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

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>

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
}
}

CodeIgniter - Undefined variable & Trying to get property of non-object

I'm trying to get data from API in my Controller and pass the data to the View. But it don't seem working and causing error:
Message:Undefined variable: data and
Message:Trying to get property of non-object
Both errors happen in my View.php, on the line when I call variable $data.
This is part of my controller related to data I want to get
$jdwl['jadwal'] = $this->bolalob->api('schedules/bydate|'.$start.'/'.$end.'/10');
$data['jadwal'] = $this->load->view('jadwal', $jdwl, TRUE);
$template['content'] = $this->load->view('jadwal',$data, TRUE);
$this->load->view('template', $template);
And this is my view
<div class="float-left first-column">
<div class="box box-shadow red round-top round-bottom">
<div class="title-box"><strong>JADWAL</strong> TV</div>
<ul class="text-center no-padding">
<?php if ($data->data == 'no data') { ?>
<li class="jadwal-tv"><strong>Belum ada jadwal</strong>
</li>
<?php } else { ?>
<?php foreach ($data->data as $key=>$row) { ?>
<?php if ($key == 0) { ?>
<li class="jadwal-tv"><strong><?php echo $row->team_1->name; ?></strong><br />VS<br /><strong><?php echo $row->team_2->name; ?></strong><br /><span><?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB</span></li>
<?php } else { ?>
<li class="side-padding">
<strong><?php echo $row->team_1->name; ?></strong> vs <strong><?php echo $row->team_2->name; ?></strong>
<br />
<?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB
</li>
<?php } ?>
<?php if ($key == 5) break; ?>
<?php } ?>
<?php } ?>
</ul>
</div>
</div>
The error happens to $data on line the 5 and 9. I've googled it and tried to use $data['jadwal'] instead of $data in my view but I didn't seem working too.
Anyone can help me with this?
Thanks :D
In your view no need to acess the $data array.
you can directly call your data key as a variable.
Ex:
In controller
$data['myVar']="Some string";
$this->load->view('viewName',$data);
In view
echo $myVar;
Try with the following view page..
<div class="float-left first-column">
<div class="box box-shadow red round-top round-bottom">
<div class="title-box"><strong>JADWAL</strong> TV</div>
<ul class="text-center no-padding">
<?php if (empty($jadwal)) { ?>
<li class="jadwal-tv"><strong>Belum ada jadwal</strong>
</li>
<?php } else { ?>
<?php foreach ($jadwal as $key => $row) { ?>
<?php if ($key == 0) { ?>
<li class="jadwal-tv"><strong><?php echo $row->team_1->name; ?></strong><br />VS<br /><strong><?php echo $row->team_2->name; ?></strong><br /><span><?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB</span></li>
<?php } else { ?>
<li class="side-padding">
<strong><?php echo $row->team_1->name; ?></strong> vs <strong><?php echo $row->team_2->name; ?></strong>
<br />
<?php echo $row->television; ?> <?php echo date('d/m/y H:i', $row->pubdate); ?> WIB
</li>
<?php } ?>
<?php if ($key == 5) break; ?>
<?php } ?>
<?php } ?>
</ul>
</div>

Resources