There is a drop down text box for type which contains two options as
1.Tracking Url + Image and 2. Code.
If I select the Tracking Url + Image , then I add two option tracking url and image and I select the code then I add js_api_code
When I check if the tracking url already exists by call back validation then the error is invisible and the tracking url and image option are also invisible and the end user does not know the actual problem
Also when I validate it by j query validation it does not work
<form onsubmit="return checktrackingurl();" method="post" action="add_content" enctype="multipart/form-data" class="form-horizontal">
<div class="panel-body">
<input type="hidden" name="type" value="banner">
<div style="color:red;padding:5px;">
<?php echo form_error('content_type_id'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Content Type<font color="red">*</font>
</label>
<div class="col-sm-5">
<select id="super_category_id" class="form-control" id="content_type_id" name='content_type_id' readonly>
<?php foreach($content_type as $content_type)
{ ?>
<option value="<?php echo $content_type['content_type_id']; ?>"><?php echo $content_type['content_type']; ?>
</option>
<?php } ?>
</select>
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('title'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Title<font color="red">*</font>
</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="title" name="title" placeholder="Title" value="<?php echo set_value('title'); ?>">
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('selectwhat'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Type <font color="red">*</font>
</label>
<div class="col-sm-5">
<select name="selectwhat" class="form-control" id="selectwhat">
<option value="">Select type</option>
<option value="tracking"> Tracking URL + Image</option>
<option value="jsapicode"> Code</option>
</select>
</div>
</div>
<div id="trackingid"></div>
<div id="codeid"></div>
<div style="color:red;padding:5px;">
<?php echo form_error('description'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Description
</label>
<div class="col-sm-5">
<textarea class="form-control" name="description" placeholder="Description"><?php echo set_value('description');?></textarea>
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('steps[]'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Steps<font color="red">*</font>
</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="steps[]" placeholder="steps" value="<?php echo set_value('steps[]'); ?>"> <span style="font:normal 12px agency, arial; color:blue; text-decoration:underline; cursor:pointer;" onclick="addMoreRows(this.form);" > Add More</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
</label>
<div class="col-sm-5">
<div id="addedRows">
</div>
</div>
</div>
<!-- <div style="color:red;padding:5px;">
<?php //echo form_error('callback_url'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
CallBack Url
</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="callback_url" placeholder="Callback Url" value="http://182.73.146.18/staging/iRupee/rewarduser.php?offer_id={offer_id}&affiliate_id={affiliate_id}&clickId={aff_sub}" readonly>
</div>
</div>-->
<!-- <div style="color:red;padding:5px;">
<?php //echo form_error('term_condition'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Term Condition
</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="term_condition" placeholder="Term Condition" value="<?php //echo set_value('term_condition'); ?>">
</div>
</div>-->
<div style="color:red;padding:5px;">
<?php echo form_error('city'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
City
</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="city" placeholder="City" value="<?php echo set_value('city'); ?>">
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('daily_limit'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Daily Limit <font color="red">*</font>
</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="daily_limit" placeholder="Daily Limit" value="<?php echo set_value('daily_limit'); ?>">
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('cashback_amount'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Cashback Amount <font color="red">*</font>
</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="cashback_amount" placeholder="Cashback Amount" value="<?php echo set_value('cashback_amount'); ?>">
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('priority'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Priority
</label>
<div class="col-sm-5">
<select name="priority" class="form-control " >
<option value="">select Priority</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('status'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Offer Status
</label>
<div class="col-sm-5">
<select class="form-control " name='status'>
<option value="">Select Status</option>
<option value="1">Active
</option>
<option value="0">Deactive
</option>
</select>
</div>
</div>
<div style="color:red;padding:5px;">
<?php echo form_error('title_image'); ?>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Select Title Image
</label>
<div class="col-sm-4">
<input type="file" class="filestyle" name="title_image" data-buttonText="Find Image">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Push Notification
</label>
<div class="col-sm-5">
<select class="form-control " name='push_status'>
<option value="1">Yes
</option>
<option value="0" selected>No
</option>
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary btn-md" size="12px;">
Submit <i class="fa fa-arrow-circle-right"></i>
</button>
<input type="button" value="Go Back" size="8px;" onclick="goBack()" class="btn btn-primary btn-md" style=""/>
</div>
</form>
The javascript code that populate the tracking url + image and js_api_code as below
function selectwhat()
{
var selectwhat=$('#selectwhat').val();
if(selectwhat=='tracking')
{
var rowTrackingUrl='<p id="newtracking"><div style="color:red;padding:5px;"><?php echo form_error('tacking_url'); ?>\
</div><div class="form-group"><label class="col-sm-3 control-label" for="form-field-3" >\
Tracking Url<font color="red">*</font></label>\
<div class="col-sm-5">\
<input type="text" class="form-control" id="tacking_urls" name="tacking_url" required placeholder="Tarcking Url" value="<?php echo set_value('tacking_url'); ?>">\
</div></div>\
<div style="color:red;padding:5px;"><?php echo form_error('image'); ?></div>\n\
<div class="form-group"><label class="col-sm-3 control-label" for="form-field-3" >Select Image<font color="red">*</font></label>\n\
<div class="col-sm-4"><input type="file" class="filestyle" name="image" required data-buttonText="Find Image">\n\
</div></div></p>';
jQuery("#trackingid").html(rowTrackingUrl);
}
if(selectwhat=='jsapicode')
{
var rowJsapicode='<p id="newjsapicode"><div style="color:red;padding:5px;">\
<?php echo form_error('js_api_code'); ?>\
</div>\
<div class="form-group">\
<label class="col-sm-3 control-label" for="form-field-3" >\
Js Api Code<font color="red">*</font>\
</label>\
<div class="col-sm-5">\
<textarea type="text" class="form-control" name="js_api_code" required placeholder="Js Api Code" ><?php echo set_value('js_api_code'); ?></textarea>\
</div>\
</div></p>';
jQuery("#trackingid").html(rowJsapicode);
}
}
$(document).on('change','#selectwhat',$(this),selectwhat);
The form validation code for tracking url like this
$this->form_validation->set_rules('tacking_url', 'Tracking Url', 'trim|required|xss_clean|callback_check_tracking_url');
public function check_tracking_url()
{
$this->db->where('content_type_id', $_POST['content_type_id']);
$this->db->where('tacking_url', $_POST['tacking_url']);
$result = $this->db->get('offer_content');
if($result->num_rows() > 0)
{
$this->form_validation->set_message('check_tracking_url','Combination of tracking url and content tye is already exist'); // set your message
return false;
}
else{ return true;}
}
I am unable to this I tried jquery validation like this
function checktrackingurl()
{
var tacking_url= $('#tacking_urls').val();
var content_type_id=$('#super_category_id').val();
if(typeof tacking_url!= "undefined")
{
var url= "<?php echo base_url() ?>checktrackingurl";
var data='tacking_url='+tacking_url+"&content_type_id="+content_type_id;
$.post(url,data,function(msg){
var status=$.trim(msg);
if(status=='alreadyExist')
{
alert("The combination of Tracking Url and Content Type already exist");
return false;
}
else if(status=='notExist'){
alert('hi');
return true;
}
});
}
else{
alert();
}
}