We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

\Phalcon\Tag::form adds unwanted slash

Hi all, here is the problem

<?= Tag::form(array(
                        "my/url",
                        'method'=>'post',
                        'id'=>'some-form'
                    )) ?>
<?= Tag::form(array(
                        $this->url->get('my/url'),
                        'method'=>'post',
                        'id'=>'some-form'
                    )) ?>

this code always adds slash as first character. I've tried to remove url at all or use $this->url->get() to generate url - and it still adds slash to the start of the string.

<form action="/my/url" id="some-form" method="post">

Also, the following code

<?= Tag::form(array(
                        "",
                        'method'=>'post',
                        'id'=>'some-form'
                    )) ?>

also generates html like

<form action="/" id="some-form" method="post">


2.2k

Try setting an absolute url, not empty or relative.

Hi Jacek, do you mean setBaseUri (which is already set in my config/di)? If so, it doesn't help/work :) Btw, phalcon 1.1.0



2.2k

OK, this is evidently frameworks fault. What I mean is that user should have greater control over what is happening, and not so much framework dependent - in this situation. For instance, one would need a form that posts to other page, on other domain, and boomer, you can't (well, you can hardcode the tag, but then you loose control of the form in oo manner).

How I would see it: Phalcon needs something like a url helper, to generate url's similar to how Zend is doing now, where you define route's elements and then url is created according to arguments passed. Tag::form and Tag::linkTo should not generate default path like they do now, based on baseUrl. If you pass an empty string, then that is what should be returned. If you need absolute url - there you have it, etc. And when you want route specific link, you use url helper.

<?php
echo Tag::form(array(
    $this->url(/** arguments **/),
    'method'=>'post',
    'id'=>'some-form'
));
?>


98.9k

Set the BaseUri to an empty string:

$url->setBaseUri("");

What if my phalcon website is not located under www root?