Page 1 of 1

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

Posted: Mon Sep 10, 2012 8:41 pm
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

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

Posted: Mon Sep 10, 2012 10:37 pm
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!

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

Posted: Sat Sep 15, 2012 9:02 pm
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

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

Posted: Sun Sep 16, 2012 9:07 am
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}

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

Posted: Sun Sep 16, 2012 7:51 pm
by leximus
Great, now it's finally working!
Thank you very much for your help!