Reputation: 5075
I need when I click the button for submit view popup box for confirmation and if I press ok, it will continue the submit and if cancel nothing will happen and close the box
here is my code,
code in the view form
<?php
foreach($company_data as $row){
?>
<h2>Company Details.</h2>
<?php echo form_open_multipart('site/update');?>
<?php form_hidden('id', $row->code);?>
<label>Code : </label> <?php echo form_input('code',$row->code);?><br/><br/>
<label>Name : </label> <?php echo form_input('name',$row->name);?><br/><br/>
<label>Logo : </label><input type="file" name="userfile"/><br/><br/>
<label>URL : </label> <?php echo form_input('url',$row->url);?><br/><br/>
<label>Description : </label> <textarea name="description" rows="4" cols="50"><?php echo $row->description; ?></textarea><br/><br/>
<input type="submit" name="submit" value="Update" onclick="update(<?php echo $row->name;?>)"/>
</form>
<?php } ?>
Upvotes: 1
Views: 8377
Reputation: 15
you can use below one line
<?php
foreach($company_data as $row){
?>
<h2>Company Details.</h2>
<?php echo form_open_multipart('site/update');?>
<?php form_hidden('id', $row->code);?>
<label>Code : </label> <?php echo form_input('code',$row->code);?><br/><br/>
<label>Name : </label> <?php echo form_input('name',$row->name);?><br/><br/>
<label>Logo : </label><input type="file" name="userfile"/><br/><br/>
<label>URL : </label> <?php echo form_input('url',$row->url);?><br/><br/>
<label>Description : </label> <textarea name="description" rows="4" cols="50"><?php echo $row->description; ?></textarea><br/><br/>
<input type="submit" name="submit" value="Update" onclick="return confirm(<?= $row->name ?>);"/>
</form>
<?php } ?>
Upvotes: 0
Reputation: 124
First, here's the classic jQuery way to do this.
$(document).ready(function(){
$( 'form#yourFormId' ).submit( function(){
if( confirm('Really submit this form?') ){
return TRUE;
} else {
return FALSE;
}
})
})
However, your code doesn't appear to submit the form directly, so this probably won't work with your code as written.
You haven't provided the code for the update()
method specified in your onClick attribute, but you should be able to add confirmation code to the top of it like this:
function update(name){
if( !confirm('Really submit this form?') ){
return FALSE;
}
// ....the rest of your code...
}
Upvotes: 0
Reputation: 5075
here is the answer
<form action="<?php echo site_url('site/update'); ?>" name="myForm" onsubmit="return(validate());">
<?php// echo form_open_multipart('site/update');?>
<?php form_hidden('id', $row->code);?>
<label>Code : </label> <?php echo form_input('code',$row->code);?><br/><br/>
<label>Name : </label> <?php echo form_input('name',$row->name);?><br/><br/>
<label>Logo : </label><input type="file" name="userfile"/><br/><br/>
<label>URL : </label> <?php echo form_input('url',$row->url);?><br/><br/>
<label>Description : </label> <textarea name="description" rows="4" cols="50"><?php echo $row->description; ?></textarea><br/><br/>
<input type="submit" value="Update"/>
</form>
<?php } ?>
<script type="text/javascript">
function validate()
{
var r=confirm("Do you want to update this?")
if (r==true)
return true;
else
return false;
}
</script>
Upvotes: 0
Reputation: 1
in onclick function call a javascript function and create confirm box using java script and check the return value from the confirm box if it is true then submit the form by using javascript onsubmit function
Upvotes: 0
Reputation: 74738
You can put confirm()
dialog in your update function like this:
function update(args){
if(confirm('Do you want to submit?')){
// put all the js code here.
}else{
return false;
}
}
So whenever you call your update function it will show a confirm box to ask user to submit the form if user clicks ok then it submits else form won't get submitted.
Upvotes: 1