Fancybox is not opening as it should

Asked

Viewed 32 times

0

I am registering in PHP using fancybox, I made the configuration of the action to call the javascript screen and the template I want to use. But inside the html by clicking the fancybox button is being directed to another page instead of just opening there.

Page of Action:

class cadastroAction extends Action
{
    public function getResults()
    {
        return [
            SUCCESS => new TemplateResult(
                'templates/basico.php', [
                    'body' => 'views/cadastroLivros/titulo/form.php',
                    'js' => [
                        'js/livraria/cadastroLivros/titulo.js'
                    ]
                ]
            )
        ];
    }

    public function cadastrar(){

        return SUCCESS;

    }
}

Screen of the fancybox:

<div class="portlet light border-0">
    <div class="portlet-title margin-botton-0">
        <div class="caption font-blue-steel">
            <i class="icon-trophy font-blue-steel"></i>
            <span class="caption-subject bold uppercase">Livros</span>
        </div>
    </div>
    <div class="portlet-body form">
        <form method="POST" id="form-livros" >
            <div class="form-group">
                <div class="col-md-12">
                    <label>Descrição</label>
                    <textarea class="form-control" rows="5"></textarea>
                </div>
            </div>            
        </form>
    </div>
</div>


Javascript screen:

$('#btn-nova-inscricao').fancybox({
    titleShow: 'false',
    type : 'iframe',
    autoSize : false,
    width : '100%',
    height : '100%'
});

HTML code:

<div id="main" class="portlet light margin-botton-0 paddingBottom0">
    <div class="row">
        <div class="col-md-12">
            <div class="portlet light portlet-fit">
                <div class="portlet-body">
                    <div id="livros" class="portlet light margin-botton-0 padding-lr-0">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="icon-trophy font-blue-steel"></i>
                                <span class="caption-subject font-blue-steel bold uppercase">Livros</span>
                                <span id="lblSubtituloTab" class="caption-helper">cadastro</span>
                            </div>
                            <div class="actions">
                                <a id="btn-nova-inscricao" href="<?= ActionRequest::absurl("cadastroLivros", "cadastro", "cadastrar") ?>" class="btn btn-primary blue-steel pull-right"> Configurar Inscrição</a>
                            </div>
                        </div>
                    </div>                   
                </div>
            </div>
        </div>
    </div>
</div>

Note: I am beginner and I am not able to understand what I did wrong.

  • Puts the full code that surrounds the question. For example, where is the button clicked? You are using AJAX?

  • Added, it’s quite simple is just a button calling the action

  • is opening on which page? name

  • test by swapping: <?= Actionrequest::absurl("registrationLivros", "register", "register") ? > by views/registrationLivros/title/form.php and see if it works. I still need the code of your entire page to be able to help you better

  • @Leandroalfredo is opening in localhost/cadastralLivros/registration/registration

  • Can you post your full page? Edit your question so I can better understand your code

  • @Leandroalfredo This is the entire code, I’m just trying to learn how fancybox works, I’ve done javascript a action o html e a fancybox (modal) separada.

  • fancybox works as follows. On the same page you need to do the includes of the fancybox js files. You create a <a> link with href going to the page you want to show in the fancybox. In your type:iframe code you link with id tbm. basically that’s it.

  • 1

    @Leandroalfredo Uhuu I did, when you told me to change the code I noticed that I could try to change using url, so I added a code in jquery that when clicking the button and trigger the action it call the url through an ajax, so I added instead of templateResult I switched to Basicresult. Now it worked. Thank you!

  • 1

    @Leandroalfredo This I was forgetting to link the ID now that Linkei the ID using ajax worked =D

  • @Gustavomazzo show

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.