Thomas BP
Thomas BP

Reputation: 1227

TYPO3 Fluid add date now to URL

I know how to add the data to a URL in PHP, but now this is TYPO3 with Fluid. I need to add date now to an URL like

http://domain.dk/form.html?tx_powermail_pi1[field][30]=DATENOW

But how can i do this in TYPO3+FLUID ?

ADD / EDIT 19/05/2014..

Im trying to use the time as an booking id.

Okay so I have the folder /www/typo3conf/ext/powermail/Classes/ViewHelpers

In that folder I have a file called BookIdViewHelper.php with this code

     <?php
#Booking ID
class BookIdViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
     * Renders time()
     *
     * @return int The current timestamp
     */
    public function render() {
        return time();
    }
}

And then i have the link with

<a href="http://www.domain.dk/?id=47&tx_powermail_pi1[field][30]={urs:time()}">

And then I in the template /www/typo3conf/ext/powermail/Resources/Private/Templates/Forms in the form.html file i added the namespace like this.

{namespace vh=Tx_Powermail_ViewHelpers}
{namespace urs=Tx_Powermail_ViewHelpers}
<f:layout name="Default" />

Render Powermail Form
{forms}             All Forms with their Pages and their Fields


<f:section name="main">

    <f:flashMessages class="powermail_message powermail_message_error" />

    <f:if condition="{forms}">
        <f:then>
            <f:for each="{forms}" as="form">
                <f:form
                        action="{action}"
                        controller="Forms"
                        enctype="multipart/form-data"
                        class="powermail_form powermail_form_{form.uid} {form.css} {vh:Misc.MorestepClass(activate: '{settings.main.moresteps}', class: 'powermail_morestep')}">
                    <h3>{form.title} - {urs.time()}</h3>
                    <f:render partial="FormError" arguments="{error}" />

                    <f:for each="{form.pages}" as="page">
                        <fieldset class="powermail_fieldset powermail_fieldset_{page.uid} {page.css}">
                            <legend class="powermail_legend">{page.title}</legend>
                            <f:for each="{page.fields}" as="field">
                                <f:render partial="Forms/{vh:String.Upper(string: '{field.type}')}" arguments="{field: field}" />
                            </f:for>
                        </fieldset>
                    </f:for>

                    <f:form.hidden name="form" value="{form.uid}" />
                    <f:render partial="HoneyPod" arguments="{form: form}" />
                </f:form>
            </f:for>
        </f:then>
        <f:else>
            <f:translate key="error_no_form" />
        </f:else>
    </f:if>

</f:section>

But its not working.. im only getting the text {urs:time()}

Upvotes: 0

Views: 2299

Answers (1)

derhansen
derhansen

Reputation: 6133

You can use the f:format.date viewhelper to output the date in a given format like shown below:

<a href="http://domain.dk/form.html?tx_powermail_pi1[field][30]={f:format.date(date: '', format: 'd.m.Y')}">Link</a>

The f:format.date viewhelper outputs the current date if the parameter date is empty (not null).

If your field (in this case a powermail field) requires a timestamp, I would recommend to create an own viewhelper, which outputs the current timestamp like shown below.

class TimeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
     * Renders time()
     *
     * @return int The current timestamp
     */
    public function render() {
        return time();
    }

}

Usage would the be like:

<a href="http://domain.dk/form.html?tx_powermail_pi1[field][30]={yournamespace:time()}">Link</a>

Upvotes: 4

Related Questions