0

I have the below BS Modal

<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>

<div  class="modal exx fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                    <h4 class="modal-title">Mesaj</h4>
                </div>
                <div class="modal-body">
                    <p><?php
                        if (isset($registration)) {
                            if ($registration->errors) {
                                foreach ($registration->errors as $error) {
                                    echo $error;
                                }
                            }
                            if ($registration->messages) {
                                foreach ($registration->messages as $message) {
                                    echo $message;
                                }
                            }
                        }
                        ?></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" aria-label="Close" data-dismiss="modal">Inchide</button>
                    <button type="button" class="btn btn-primary">Acasa</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
</div>

I am trying to run the Modal Only when the PHP code outputs something(its a registration page)

I have read the BS Modal documentation but i cany find anythinh automatic except the button.

1 Answer 1

1

If you want to open modal on page load then,

$(document).ready(function(){
 var content = $('.modal-body').find('p').html();
 console.log(content); // You can see in console there is content present or not
  if(content != '' || content != null ){
      $('your modal').modal('show');
   }
});

Not the answer you're looking for? Browse other questions tagged or ask your own question.