hyphen hyphen - 6 months ago 41
PHP Question

codeignitor show form success message using jquery?

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


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>

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') { ?>
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.

Answer Source

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')) { ?>
    setTimeout(function() {$('#success-alert').slideUp('slow');}, 2100);
<?php }; ?>

Note this should be in same page where your form redirects after success.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download