I've 2 ajax form in my ctp,
One is working and other is not,instead it gets redirected.
This is my .ctp file
<div>
<?php echo $ajax->form('deletecreativeschedule','post',array('id'=>'delete','model'=>'admin','update'=>'myTable')); ?>
<input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />
<input type="hidden" name="scheduleid" id="scheduleid"/>
<input name="btnDelete" type="image" src="/<?php echo $site_root ?>/img/btnDelete.gif" height="16" class="sbtnDelete" id="sbtnDelete" onclick="return deleteSchedule();" title="Delete creative" >
<?php echo $form->end(); ?>
<br>
<?php echo $ajax->form('swapcreativeschedule','post',array('id'=>'swap','controller'=>'admin','update'=>'myTable')); ?>
<input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />
<input type="hidden" name="aIdAjax" id="aIdAjax"/>
<input type="hidden" name="aSeqAjax" id="aSeqAjax"/>
<input name="btnUP" type="image" src="/<?php echo $site_root ?>/img/up.png" class="sbtnup" id="sbtnup" onclick="return SwapRow('0');" title="Delete creative" >
<input name="btnDown" type="image" src="/<?php echo $site_root ?>/img/down.png" class="sbtndown" id="sbtnup" onclick="return SwapRow('1');" title="Delete creative" >
<?php echo $form->end(); ?>
and in controller:
function deletecreativeschedule()
{
$this->autorender = false;
$this->layout = 'ajax';
}
function swapcreativeschedule()
{
$this->autorender = false;
$this->layout = 'ajax';
}
and in views/admin folder i've created files deletecreativeschedule.ctp and swapcreativeschedule.ctp
ajax is working fine for deleteschedule
but for swapcreativeschedule it is redirecting to /admin/swapcreativeschedule
what is wrong here?
I hope it'll work,
<?php echo $form->create('deletecreativeschedule'); ?>
<input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />
<input type="hidden" name="scheduleid" id="scheduleid"/>
<input name="btnDelete" type="image" src="/<?php echo $site_root ?>/img/btnDelete.gif" height="16" class="sbtnDelete" id="sbtnDelete" onclick="return deleteSchedule();" title="Delete creative" >
<? echo $ajax->submit('btnDelete.gif',array("url"=>array('controller'=>'your controller','action'=>'ur action',$device['Device']['id']),'class'=>'sbtnDelete','update'=>'ur updateDiv') ?>
<?php echo $form->end(); ?>
<br>
<?php echo $form->create('swapcreativeschedule'); ?>
<input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />
<input type="hidden" name="aIdAjax" id="aIdAjax"/>
<input type="hidden" name="aSeqAjax" id="aSeqAjax"/>
<? echo $ajax->submit('up.png',array("url"=>array('controller'=>'your controller','action'=>'ur action',$device['Device']['id']),'class'=>'sbtnup','update'=>'ur updateDiv') ?>
<? echo $ajax->submit('down.png',array("url"=>array('controller'=>'your controller','action'=>'ur action',$device['Device']['id']),'class'=>'sbtndown','update'=>'ur updateDiv') ?>
<?php echo $form->end(); ?>
Related
I have written code in view as
<input type="hidden" name="cna" id="cna" value="<?php echo $this->security->get_csrf_token_name(); ?>">
<input type="hidden" name="cha" id="cha" value="<?php echo $this->security->get_csrf_hash(); ?>">
Now how to get these fields in angularjs function and pass to
data: JSON.stringify({})
I have a website. With forecasts of sport. When in admin panel want to add new forecasts released the following error:
error!
There was a problem saving the tips: DB Error: Unknown column 'result' in 'field list'
Where is perhaps the error in the system? Can anyone help me with this?
Thank you!
<?php
$tips_open = $this->settings_lib->item('tips.allow_post');
?>
<?php
if (validation_errors()) :
?>
<div class='alert alert-block alert-error animated animated-short zoomIn'>
<a class='close' data-dismiss='alert'>×</a>
<h4 class='alert-heading'>
<?php echo lang('tips_errors_message'); ?>
</h4>
<?php echo validation_errors(); ?>
</div>
<?php
endif;
$id = isset($tips->id) ? $tips->id : '';
?>
<div class="box">
<div class="box-body">
<p class="text-center"><h4><?php if (isset($toolbar_title)) : ?><?php echo $toolbar_title; ?><?php endif; ?>
<span class="pull-right fs12"><span class="hidden-xs"><?php echo lang('tips_action_before_post');?></span>
<button type="button" class="btn btn-blue ml20" data-toggle="modal" data-target="#TipsRules">
<?php echo lang('tips_action_read_rules');?>
</button></span>
</h4></p>
<div class="divider-4"></div>
<?php if ( $tips_open ) { ?>
<?php echo form_open($this->uri->uri_string(), 'id="form" class="form-horizontal"'); ?>
<?php if (isset($current_user->id)) : ?>
<input id="created_by" type="hidden" name="created_by" maxlength="30" value="<?php echo $current_user->id; ?>" />
<?php endif; ?>
<input id="created_on" type="hidden" name="created_on" value="<?php echo date('Y-m-d H:i:s'); ?>" />
<!-- Start Row -->
<div class="row">
<div class="col-sm-4">
<div class="form-group<?php echo form_error('sport_id') ? ' has-error' : ''; ?>">
<?php echo form_label(lang('tips_select_sport') . lang('bf_form_label_required'), 'sport_id', array('class' => 'control-label')); ?>
<select name="sport_id" id="sport_id" class="form-control">
<option value=""><?php echo lang('tips_select_sport');?></option>
<?php foreach ($sports->result() as $row) {
$sel = ($row->id==set_value('sport_id'))?'selected="selected"':'';
?>
<option value="<?php echo $row->id;?>" <?php echo $sel;?>><?php echo $row->name;?></option>
<?php }?>
</select>
<span class='help-block'><?php echo form_error('sport_id'); ?></span>
</div>
</div>
<div class="league">
<div class="col-sm-4">
<div class="form-group<?php echo form_error('league_id') ? ' has-error' : ''; ?>">
<label class="control-label"><?php echo lang('tips_select_league');?></label>
<select name="league_id" id="league_id" class="form-control">
<!-- Auto Populated -->
</select>
<?php echo form_error('league_id');?>
</div>
</div>
</div>
</div>
<!-- End Row -->
<!-- Start Row -->
<div class="row">
<div class="match">
<div class="col-sm-8">
<div class="form-group<?php echo form_error('match_id') ? ' has-error' : ''; ?>">
<?php echo form_label(lang('tips_select_event') . lang('bf_form_label_required'), 'match_id', array('class' => 'control-label')); ?>
<select name="match_id" id="match_id" class="form-control">
<!-- Auto Populated -->
</select>
<?php echo form_error('match_id');?>
</div>
</div>
</div>
</div>
<!-- End Row -->
<!-- Start Row -->
<div class="row">
<div class="bet_id">
<div class="col-sm-4">
<div class="form-group<?php echo form_error('bet_id') ? ' has-error' : ''; ?>">
<?php echo form_label(lang('tips_bet_category') . lang('bf_form_label_required'), 'bet_id', array('class' => 'control-label')); ?>
<select name="bet_id" id="bet_id" class="form-control">
<!-- Auto Populated -->
</select>
<?php echo form_error('bet_id');?>
</div>
</div>
</div>
<div class="choice_id">
<div class="col-sm-5">
<div class="form-group<?php echo form_error('choice_id') ? ' has-error' : ''; ?>">
<?php echo form_label(lang('tips_bet_type') . lang('bf_form_label_required'), 'choice_id', array('class' => 'control-label')); ?>
<select name="choice_id" id="choice_id" class="form-control">
<!-- Auto Populated -->
</select>
<?php echo form_error('choice_id');?>
</div>
</div>
</div>
<div class="stake">
<div class="col-sm-3">
<div class="form-group <?php echo form_error('stake') ? ' has-error' : ''; ?>">
<?php echo form_label(lang('tips_stake') . lang('bf_form_label_required'), 'stake', array('class' => 'control-label')); ?>
<?php $stakes = array('1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6','7'=>'7','8'=>'8','9'=>'9','10'=>'10');?>
<select name="stake" id="stake" class="form-control">
<option value=""><?php echo lang('tips_select_stake');?></option>
<?php foreach ($stakes as $stake) {
$sel = ($stake==set_value('stake'))?'selected="selected"':'';
?>
<option value="<?php echo $stake;?>" <?php echo $sel;?>><?php echo $stake;?></option>
<?php }?>
</select>
<span class='help-block'><?php echo form_error('stake'); ?></span>
</div>
</div>
</div>
</div>
<!-- End Row -->
<input type="hidden" name="odds" id="odds" value="" />
<!-- Start Row -->
<div class="row">
<div class="col-sm-12">
<div class="form-group<?php echo form_error('description') ? ' has-error' : ''; ?>">
<?php echo form_label(lang('tips_description') . lang('bf_form_label_required'), 'description', array('class' => 'control-label')); ?>
<textarea class="textarea" name="description" id="description" placeholder="<?php echo lang('tips_min_words');?>" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
</div>
<span class='help-block'><?php echo form_error('description'); ?></span>
</div>
</div>
<!-- End Row -->
<div class="box-footer">
<input type='submit' name='save' class='btn btn-blue' value="<?php echo lang('tips_action_send'); ?>" />
</div>
<?php echo form_close(); ?>
<?php } else { ?>
<div class="alert alert-info">
<h4> Sorry!</h4>
Cannot bet now.
</div>
<?php } ?>
</div><!-- /.box-body -->
</div><!-- /.box -->
<div id="TipsRules" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content p10">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1 class="text-center"><?php echo lang('tips_rules'); ?></h1>
</div>
<div class="modal-body" data-ng-controller="rulesCtrl">
<?php $rules = $this->settings_lib->item('tips.rules');
echo $rules
;?>
</div>
<div class="modal-footer bg-default">
</div>
</div>
</div>
</div><!--/modal-->
<script type="text/javascript">
// Define site_url variable for use in the js file
var site_url = "<?php echo site_url(); ?>";
// Define error messages for jquery validation
var description_forgot = '<?php echo lang('tips_desc_forgot');?>'
var description_req = '<?php echo lang('tips_min_words');?>'
</script>
I have 2 input arrays one is checkbox and and another one is textbox
which is my view file
<div class="form-group">
<label class="col-lg-2 control-label">Fee Types</label>
<div class="col-lg-8">
<div class="checkbox">
<?php foreach($types as $key=>$value){?>
<label>
<input type="checkbox" value="<?php echo $value['id'] ?>" name="type_id[]" />
<span class="text"><?php echo $value['name'] ?></span>
</label>
<input type="text" class="form-control" name="amount[]" />
<?php } ?>
</div>
</div>
</div>
which is my controller
$data=array(
'id'=>$this->input->post('id'),
'amount'=>$this->input->post('amount'),
'type_id'=>$this->input->post('type_id'),
'created_date'=>date('Y-m-d'),
);
$this->user->details($data);
could anyone tell me how to insert those two arrays as multiple records
$checkboxes = $this->input->post('type_id[]');
$amounts= $this->input->post('amount[]');
for ($i = 0; $i < count($amounts); $i++) {
$data = array(
'id'=> $yourIdPostField,
'amount'=>$amounts[$i],
'type_id'=> $checkboxes[$i],
'created_date'=>date('Y-m-d'),
);
$this->user->details($data);
}
This is simple way... but maybe your problem is no checkbox post data becouse not checked, if you want that problem then add increment number to your form ...
<div class="form-group">
<label class="col-lg-2 control-label">Fee Types</label>
<div class="col-lg-8">
<div class="checkbox">
<?php foreach($types as $key=>$value){?>
<label>
<input type="checkbox" value="<?php echo $value['id'] ?>" name="type_id[$key]" />
<span class="text"><?php echo $value['name'] ?></span>
</label>
<input type="text" class="form-control" name="amount[<?php echo $key ?>]" />
<?php } ?>
</div>
</div>
</div>
$checkboxes = $this->input->post('type_id[]');
$amounts= $this->input->post('amount[]');
$example1 = implode(" ",$checkboxes);
$example2 = implode(" ",$amounts);
Please try this. I hope your problem will be solve.
$checkboxes, $amounts this variables is array so these variable value could not store in your database. So please convert array to string.
Thanks
I'm trying to submit a bunch of form data that has been imported from a .csv file and I'm losing the data when I submit the form.
I check the POST request in Chrome Dev Tools and the data is in the POST request, but if I debug($this->data); in the controller, it's empty.
Here is some relevant code:
admin_add_template.ctp (my view)
<?php for ($i=0; $i < $line - 1; $i++) : ?>
<?php echo $this->Form->create('ActiveQuoteItem');?>
<fieldset>
<legend>Quote Template <?= $i; ?></legend>
<!-- <input type="hidden" name="xxxx" id="xxxx" value="xxxx" />-->
<input name="quote_item_id" id="quote_item_id" value="<?php echo $out[$i][2] ; ?>" />
<input name="estimated_cost" id="estimated_cost" value="<?php echo $out[$i][3] ; ?>" />
<input name="actual_cost" id="actual_cost" value="<?php echo $out[$i][4] ; ?>" />
<input name="billed_at" id="billed_at" value="<?php echo $out[$i][5] ; ?>" />
<input name="inquiry_id" id="inquiry_id" value="<?php echo $the_id; ?>" />
<input name="active" id="active" value="<?php echo $out[$i][7] ; ?>" />
<input name="timeline" id="timeline" value="<?php echo $out[$i][8] ; ?>" />
<input name="timeline_rushed" id="timeline_rushed" value="<?php echo $out[$i][9] ; ?>" />
<input name="title" id="title" value="<?php echo $out[$i][10] ; ?>" />
<input name="description" id="description" value="<?php echo $out[$i][11] ; ?>" />
<input name="category" id="category" value="<?php echo $out[$i][12] ; ?>" />
<input name="quantity" id="quantity" value="<?php echo $out[$i][13] ; ?>" />
</fieldset>
<?php endfor; ?>
<?php echo $this->Form->end(__('Save', true)); ?>
active_quote_items_controller.php (my Controller)
function admin_add_template() {
if (!empty($this->data)) {
$this->ActiveQuoteItem->create();
if ($this->ActiveQuoteItem->saveAll($this->data['ActiveQuoteItem'])) {
$this->Session->setFlash(__('The active quote item has been saved', true));
$this->redirect(array('action'=>'index','inquiry_id'=>$this->data['ActiveQuoteItem']['inquiry_id']));
} else {
$this->Session->setFlash(__('The active quote item could not be saved. Please, try again.', true));
}
}
}
You say
$this->ActiveQuoteItem->saveAll($this->data['ActiveQuoteItem'])
But your form looks to me like it would provide data in a format that would correspond with
$this->ActiveQuoteItem->save($this->data)
Okay, the problem was the names of my inputs.
Instead of an input like:
<input name="quote_item_id" id="quote_item_id" value="<?php echo $out[$i][2] ; ?>"
It needed to be like:
<input type="hidden" name="data[<?php echo $i; ?>][quote_item_id]" id="quote_item_id" value="<?php echo $out[$i][2] ; ?>" />
In other words, I forgot to make it the form into a data array in the view, so when I was trying to debug $this->data in the controller, I wasn't getting anything.
Now, What i want to do is check any two or three checkboxes and after redirecting to multichk.php page, checked boxes should be shown.
<?php
?>
<html>
<form method="post" name="Myf" action="multichk.php">
C <input type="checkbox" name="check_b[]" value="C" ><br>
C++ <input type="checkbox" name="check_b[]" value="C++" ><br>
Java <input type="checkbox" name="check_b[]" value="Java" ><br>
<input type="submit" name="submit" value="Submit">
</form>
</html>
These two are separate files.
<?php
?>
<html>
<body>
<form>
<?php
if(isset($_POST['submit']))
{
if(isset($_POST['check_b']))
{
foreach($_POST['check_b'] as $ch)
{
?>
C <input type="checkbox" name="check_b[]" value="C" <?php if($ch=="C"){ echo "checked=\"checked\" "; } ?> ><br>
C++ <input type="checkbox" name="check_b[]" value="C++" <?php if($ch=="C++"){ echo "checked=\"checked\" "; } ?> ><br>
Java <input type="checkbox" name="check_b[]" value="Java" <?php if($ch=="Java"){ echo "checked=\"checked\" "; } ?> ><br>
<?php
}
}
}
?>
</form>
</body>
</html>
if you are use html form tag same as in your first file if we checked more then one check box and then we click the submit then automatically redirect to the form action file.
and in your 2nd file there use form tag without action part.
change second file code to following one
<html>
<body>
<form>
<?php
$checked = array();
if(isset($_POST['submit']))
{
if(isset($_POST['check_b']))
{
foreach($_POST['check_b'] as $ch)
{
$checked[] = $ch;
}
}
}
?>
C <input type="checkbox" name="check_b[]" value="C" <?php if(in_array("C", $checked)){ echo "checked=\"checked\" "; } ?> ><br>
C++ <input type="checkbox" name="check_b[]" value="C++" <?php if(in_array("C++", $checked)){ echo "checked=\"checked\" "; } ?> ><br>
Java <input type="checkbox" name="check_b[]" value="Java" <?php if(in_array("Java", $checked)){ echo "checked=\"checked\" "; } ?> ><br>
</form>
</body>
</html>
Just one suggestion, If you see code, You may realize that their are no need to use two separate files at all, you can send form action to same file :)