Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: glz_custom_fields
Adam, did you get the custom fields working? I am still having trouble. I have 3 custom fields, and I have them in a form like this:
<h2><txp:title /></h2>
<p class="post"><txp:posted /> Category: <txp:category1 link="1" title="1" section="section1" /> <txp:if_custom_field name="Country">Country: <txp:custom_field name="Country" /></txp:if_custom_field>
<txp:if_custom_field name="State">State: <txp:custom_field name="State" /></txp:if_custom_field>
<txp:if_custom_field name="Author">State: <txp:custom_field name="Author" /></txp:if_custom_field>
</p>
<txp:body />
Everything gets outputted except the custom field values – which are set in the article itself.
Any ideas on how to pull out the custom field data? I am probably missing something simple.
Edit: I was missing the obvious after all! Doh! Forget this post :-(
Last edited by jstubbs (2007-11-03 09:10:02)
Offline
#50 2007-11-03 18:48:50
- Logoleptic
- Plugin Author
- From: Kansas, USA
- Registered: 2004-02-29
- Posts: 482
Re: glz_custom_fields
jstubbs wrote:
Edit: I was missing the obvious after all! Doh! Forget this post :-(
Can you tell me what you did to fix it? The code you posted looked sound to me, and I’m kind of curious.
Last edited by Logoleptic (2007-11-03 18:49:18)
Offline
Re: glz_custom_fields
By obvious I mean embarrassing. The form with the custom fields was working perfectly, but I outputted the form in one place on the page where I did not look ;-(
BTW, any idea on how to use custom fields in a form (mem_moderation or ZCR), as outlined in a previous post ? I emailed Gerhard but I guess he is busy as he hasn’t replied yet.
Offline
#52 2007-11-03 22:31:43
- Logoleptic
- Plugin Author
- From: Kansas, USA
- Registered: 2004-02-29
- Posts: 482
Re: glz_custom_fields
jstubbs wrote:
BTW, any idea on how to use custom fields in a form (mem_moderation or ZCR), as outlined in a previous post ? I emailed Gerhard but I guess he is busy as he hasn’t replied yet.
I haven’t used mem_moderation, but from the error message you got I’m guessing that your form needs to be an article form for the custom fields to work. I hadn’t given it much thought, but it makes sense that <txp:custom_field />
would be context-limited to articles. After all, the custom field contents are defined on a per-article basis.
Once you get your form types straightened out, you should be good to go. I’m successfully using custom fields within an article form for a site I’m finishing up this month. My client has an Amazon affiliate bookstore, and the fields contain each book’s author and book details (page count and binding). I’m using them elsewhere on the site, too. Custom fields are probably one of my most-used Txp features.
Offline
Re: glz_custom_fields
That’s helpful. Care to share a portion of your form code so I can compare?
Edit: Trying to add custom fields mostly for text input’s, but also select drop downs.
Last edited by jstubbs (2007-11-04 08:55:43)
Offline
Re: glz_custom_fields
OK I tried your suggestion Adam – I changed the mod_article_form from “misc” to “article”, then added the following to the form:
<div class="submit_label">Country</div>
<txp:custom_field name="Country" />
I get the same error:
Tag error: <txp:custom_field name="Country" /> -> Textpattern Notice: Article tags cannot be used outside an article context on line 1887
Edit: And no output from the custom field tag, forgot to say that.
Last edited by jstubbs (2007-11-04 09:21:08)
Offline
Re: glz_custom_fields
jstubbs wrote:
OK I tried your suggestion Adam – I changed the mod_article_form from “misc” to “article”, then added the following to the form:
“Form types” are just for categorization inside TxP admin. Changing a form type doesn’t have any effect on the functionality of the form.
Tag error: <txp:custom_field name="Country" /> -> Textpattern Notice: Article tags cannot be used outside an article context on line 1887
Are you using it on a page template and rendering an sticky article?
I have reported this as a bug.
It’s supposed that article tags (like txp:custom_field
) work in a page template when you are in an individual-article context.
The bug is that this feature is working for live articles but not for sticky articles.
Offline
Re: glz_custom_fields
Hi Julián,
No, I am using the custom field within a TXP form set to type “article” (I will set it back to “misc” which is what is was before) with mem_moderation tags (the default mem_moderation user input form), which means the users sees a form which is filled in by the user and submitted, then moderated. No sticky articles are used..
Offline
#57 2007-11-04 21:47:01
- Logoleptic
- Plugin Author
- From: Kansas, USA
- Registered: 2004-02-29
- Posts: 482
Re: glz_custom_fields
If the purpose of mem_moderation is to allow users to submit new content, then I’m not sure you can use custom field data in the submission form. After all, there’s no article for the custom field data to “belong” to yet.
Note: To avoid the form/form confusion that comes up when talking about Textpattern forms (templates) and online forms (the kind you fill out), I’m going to borrow a documentation convention from the WordPress Codex. The template feature will be capitalized (i.e. “article Form”). Could we steal this convention for TextBook?
The way around this might be to use a “misc” Form for the submission form, then use <txp:output_form form="my_form_name" />
within the body of an article or in your page template for that article’s section. The article would have the custom field “Country” pre-filled with whatever value you want to appear in the submission form, and the Form should ‘inherit’ that data when it appears along with the article on an individual article page. This won’t work on article list pages, so you’d want to surround the output_form
tag with <txp:if_individual_article>
or take similar measures to restrict it to the individual article context.
Of course, I’m not really sure why you’d go to all that trouble rather than just type in the name of the country. Will there be different submission forms for different countries? I’m not quite sure what you’re trying to accomplish, so it’s hard to know whether my advice makes any sense.
Disclaimer: I am completely ignorant of how mem_moderation works, as I’ve never used it. Also, this line of discussion is starting to seem better suited to the mem_moderation support thread or the How Do I…? forum.
Last edited by Logoleptic (2007-11-04 21:48:06)
Offline
Re: glz_custom_fields
I will read through your reply more carefully later Adam, but just this for now – the form is for a classifieds style site, where the user will register/login via mem_self_register, then see a form with fields like:
-title
-classified details
-country (drop-down selection)
-state (drop-down selection)
-email
etc etc…the idea with drop down lists is that it avoids error on the part of the user. One person could type in USA, another could type in USO!
Hope that explains what I am doing…
Edit: The form is being submitted with mem_moderation, ZCR is not applicable here.
Last edited by jstubbs (2007-11-04 21:59:06)
Offline
#59 2007-11-04 22:54:32
- Logoleptic
- Plugin Author
- From: Kansas, USA
- Registered: 2004-02-29
- Posts: 482
Re: glz_custom_fields
jstubbs wrote:
-country (drop-down selection)
Another Disclaimer: I haven’t actually installed glz_custom_fields yet. The following post is constructed almost entirely of educated guesses.
Unless glz_custom_fields has done something to change this, the <txp:custom_field />
tag should only output the selected value of the chosen custom field for the current article — not a drop-down list. Being able to output selects, radio button groups, etc. to the public site would be a nice feature for a future version though.
What you probably want to do here is use some PHP and SQL to pull the defined values for Country out of the Txp database (in the textpattern
table, according to this post) and turn that into a series of <option>
elements for your <select>
.
I don’t know how multiple values for selects are stored in the database. My guess is that explode()
would be handy for doing what you want, though. Check your textpattern
table and the plugin docs for more information, and keep in mind that you’ll probably have to change all this code when Gerhard moves the custom field data to a new table later on.
Offline
#60 2007-11-12 01:55:29
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: glz_custom_fields
Ok I found a temporary solution to the “only on front page” problem, untill next release fixes it.
I slightly modified the plugin code around line 861 replacing
$section = (!$section) ? '' : " and Section = '".doSlash($section)."'";
with
$section = '';
and, apparently, all seems to be working ok now.
Offline