Reputation: 3450
new to CI and trying to figure out how to put it all together. I have a form that i'm submitting via the form helper and using the form validation library to send feedback to the user. I'm submitting the form with a simple $('#editForm').submit();
I'd like to be able to show a success notification to the user and use jquery animations to make it appear in a smooth transition versus just showing up.
All I've been able to do so far is use flashdata to conditionally display the div containing the notification in the view file.
<div id="success-alert" style="display:none;" class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
Success!
</div>
Is there a way to trigger jquery to animate this? I tried just echoing out some php to conditionally display the jquery code, but it wasn't working:
<?php if($this->session->flashdata('result') == 'success') { ?>
$('#success-alert').slideDown('slow');
setTimeout(function() {$('#success-alert').slideUp('slow');}, 2100);
<?php }; ?>
I get this error: Uncaught SyntaxError: Unexpected token <
I'd prefer not to use flashdata, other than to conditionally execute jquery, if possible. I know there must be a way, but unfortunately too I'm new to CI to know what it is.
Upvotes: 1
Views: 880
Reputation: 1200
you dont have to check the value of flash data if the flash data is set then it will trigger
<?php if($this->session->flashdata('result')) { ?>
<script>
$('#success-alert').slideDown('slow');
setTimeout(function() {$('#success-alert').slideUp('slow');}, 2100);
</script>
<?php }; ?>
Note this should be in same page where your form redirects after success.
Upvotes: 2