[SOLVED] Define the value of a field automatically in CGBlog

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
leximus
Forum Members
Forum Members
Posts: 51
Joined: Fri Oct 20, 2006 8:57 pm

[SOLVED] Define the value of a field automatically in CGBlog

Post by leximus »

Hi,

I'd like to edit the frontend submit template of cgblog in the way that there are two custom fields, for which the values are automatically defined by the template (every blog entry should be connected to a calendar entry, so I'd like to automatically save the id and the name of the event in the blog entry)
I'm calling the fields one by one using {$customfields.0->field} for example for the first field for the variable named akt_id.
So is it possible to set the value for that field automatically (and how if it is ;) )?

Thank you...

CGBlog 1.9.8
CMSMS 1.11.1
Last edited by leximus on Sun Sep 16, 2012 7:52 pm, edited 1 time in total.
mrenigma
Forum Members
Forum Members
Posts: 48
Joined: Fri Aug 05, 2011 3:43 pm
Location: London, United Kingdom

Re: Define the value of a field automatically in CGBlog ?

Post by mrenigma »

Probably the most easiest thing for you to do would be to save the values you want stored in the inputs and then call this tag on the fields:

Code: Select all

{$customfields.0->field|regex_replace:'/value=\".*?\"/':'value="'|cat:$yourvariable|cat:'"'}
This code searches for the term value="(anything in here)" and then replaces it with value="(your variable)".

Hope that helps!
~ Life is like water, every movement you make changes the way it flows ~
leximus
Forum Members
Forum Members
Posts: 51
Joined: Fri Oct 20, 2006 8:57 pm

Re: Define the value of a field automatically in CGBlog ?

Post by leximus »

Thanks for the fast reply mrenigma. Had to wait until today to try it and it nearly works. But there seems to be an error, because the value I enter (30 in the example) is shown behind the field... The content of the field is just value=".
The page source explains the problem:
<input type="text" class="cms_textfield" name="m6d4e5cgblog_customfield_1" id="m6d4e5cgblog_customfield_1" value=" size="3" maxlength="3" />
30"
And here is the code in the template:
{$customfields.0->field|regex_replace:'/value=\".*?\"/':'value="'|cat:$smarty.get.event_id|cat:'"'}
Does anyone know what's wrong with it?
Thank you!

Regards,

Lex
mrenigma
Forum Members
Forum Members
Posts: 48
Joined: Fri Aug 05, 2011 3:43 pm
Location: London, United Kingdom

Re: Define the value of a field automatically in CGBlog ?

Post by mrenigma »

Hmm so its missing the other quotation mark?

I've noticed smarty can be a bit picky when using certain modifiers with cat so did you try putting the value in a variable and then applying that to the regex replace?

Code: Select all

{assign var='fieldVal' value='value="'|cat:$smarty.get.event_id|cat:'"'}
{$customfields.0->field|regex_replace:'/value=\".*?\"/':$fieldVal}
~ Life is like water, every movement you make changes the way it flows ~
leximus
Forum Members
Forum Members
Posts: 51
Joined: Fri Oct 20, 2006 8:57 pm

Re: Define the value of a field automatically in CGBlog ?

Post by leximus »

Great, now it's finally working!
Thank you very much for your help!
Post Reply

Return to “Modules/Add-Ons”