Forums

Categories, and Displaying Custom Fields in Article

thisyearsgirl 17 Mar, 2009
I know next to nothing about coding and have honestly spent hours upon hours digging through these forums trying to find answers to my questions and put together a form. I've managed to figure almost everything out, but there are still two problems left and I've searched, but I haven't been able to find the answers.

I am putting together a form that allows users to submit an article, but with custom fields.

First, I would like them to be able to choose which category (in a specific section) the article is submitted to. I got the dropdown box with the correct categories to appear using this code (formatted this way due to css styling):

<div class="form_item">
   <div class="form_element">
      <label class="cf_label">
         <b>Category</b> 
      </label>
      <?php
      echo JHTML::_('list.category', 'field_name', '9');
      ?>
   </div>
   <div class="clear"> 
   </div>
</div>


However, when I do a test run to try to submit something to a category, it just goes to Uncategorized within that section. I assume the issue is in the code I have under On Submit after email, which is this:


<?php

$_POST['catid'] =  ' ';
$_POST['id'] = ' ';
$_POST['sectionid'] = '9';
$_POST['state'] = '1';
$_POST['created'] = date("mm-dd-YYYY");
?>


I simply don't know what to put instead of ' ' for catid. The search results I've found on here have been bits and pieces of the problem, and I haven't been able to mix and match solutions to correctly result in a Categories drop down box that appears the right way in the front end and actual successful submission to selected Category.

Second, while I can get whatever is typed into the HTML Editing box on the form to appear as an article, as well as the title and the username from Community Builder, I can't get any of the custom fields (and subsequent entries) to appear, either on the page as published information or as part of the saved article in the backend. Just a horizontal line and whatever was entered into the HTML box. I *think* I may have to edit core Joomla files to fix this, but I would just appreciate being pointed in the right direction if possible as to where to get the information on what files I need to hack into and edit, as I really have no idea.

Sorry for being such a beginner. I really appreciate this extension as well as the support! Thank you!
GreyHead 17 Mar, 2009
Hi thisyearsgirl,

If you turnon debug in the form General tab you should be able to see what is being returned when the form is submitted.

In this case I think you will find that the category id you need shows up in a field called 'form_name' . . . probalby a first step is to rename this as 'catid' in the JHTML Line.

I'm not sure if this will solve the problem but it's a good step on the way.

Bob
thisyearsgirl 17 Mar, 2009
Excellent!

I changed my Form Code to:

<!--CATEGORY SELECT--!>
<div class="form_item">
   <div class="form_element">
      <label class="cf_label">
         <b>Category</b> 
      </label>
      <?php
      echo JHTML::_('list.category', 'catid', '9');
      ?>
   </div>
   <div class="clear"> 
   </div>
</div>


(where 9 = the section I am pulling categories from)

And simply changed the post-email On Submit code to:


<?php
$_POST['catid'];
$_POST['id'] = '';
$_POST['sectionid'] = '9';
$_POST['state'] = '1';
$_POST['created'] = date("mm-dd-YYYY");
?>


Eliminating the blank field after catid. Simple enough, but good lord I tried a million different things. Thanks! This website is for a college midterm (in a non-computer class) in addition to being a pet project so I really appreciate things *actually* working!

Now if anyone could point me in the direction of the files I need to rewrite to make the custom fields appear, that's my next headache to sort out🙂
thisyearsgirl 18 Mar, 2009
Awesome! That worked out great, but now I'm running into a new problem. Both the intro text and the full text inside the article are refusing to accept any sort of formatting (and the full text is, of course, edited using an HTML editor). I see there was a similar situation in the discussion you just linked me to, but either I'm putting that code in the wrong place (which is entirely possible - I was putting it after the opening php tag in the On Submit after email box), or that code just isn't working for me.

Anyway, here's what my code looks like now:

<p><span style="color: #0000ff;"><strong>Thank you!</strong></p></span>
<p>Your story should be available on the website within 10 minutes. If it isn't up in an hour, please let us know: help@dollhouse-attic.com</p>
<p>If you need to edit, or add chapters, please see the Instructions for more information.</p>
<p>And don't forget to invite friends to read and review!</p>



<?php

$introtext = "
<strong><p>Author: {created_by}</strong></p>
<strong>Rating: </strong>{rating_1}<br>
<strong>Characters: </strong>{char1_1}/{char2_1}<br>
<strong>Summary: </strong>{summ_1}<br>
<strong>Status: </strong>{radio0}<br>";

$introtext = str_replace('{username}', 
''.JRequest::getVar('created_by').'', $introtext);
$introtext = str_replace('{rating_1}', 
''.JRequest::getVar('rating_1').'', $introtext);
$introtext = str_replace("{char1_1}", 
''.JRequest::getVar("char2_1").'', $introtext);
$introtext = str_replace("{char2_1}", 
''.JRequest::getVar("char2_1").'', $introtext);
$introtext = str_replace("{radio0}", 
''.JRequest::getVar("radio0").'', $introtext);
$introtext = str_replace("{summ_1}", 
''.JRequest::getVar("summ_1").'', $introtext);
           
JRequest::setVar('introtext', $introtext);



$fulltext_template = "<br>
<strong>Title: {title}</strong><br>
<strong>Author: {created_by}</strong><br>
<strong>Rating: </strong>{rating_1}<br>
<strong>Characters: </strong>{char1_1} and {char2_1}<br>
<strong>Status: </strong>{radio0}<br><br>
<strong>Summary: </strong>{summ_1}<br><p><br></p>
{fulltext}<br>";

$fulltext_template = str_replace("{title}", 
''.JRequest::getVar("title").'', 
$fulltext_template);
$fulltext_template = str_replace("{created_by}", 
''.JRequest::getVar("username").'', 
$fulltext_template);
$fulltext_template = str_replace("{rating_1}", 
''.JRequest::getVar("rating_1").'', 
$fulltext_template);
$fulltext_template = str_replace("{char1_1}", 
''.JRequest::getVar("char1_1").'', 
$fulltext_template);
$fulltext_template = str_replace("{char2_1}", 
''.JRequest::getVar("char2_1").'', 
$fulltext_template);
$fulltext_template = str_replace("{radio0}", 
''.JRequest::getVar("radio0").'', 
$fulltext_template);
$fulltext_template = str_replace("{summ_1}", 
''.JRequest::getVar("summ_1").'', 
$fulltext_template);
$fulltext_template = str_replace("{fulltext}", 
''.JRequest::getVar("fulltext").'', 
$fulltext_template);

JRequest::setVar("fulltext", $fulltext_template);



$_POST['catid'];
$_POST['id'] = '';
$_POST['sectionid'] = '9';
$_POST['state'] = '1';
$_POST['created'] = date("m-d-Y");
?>


Any suggestions appreciated! Thank you so much!
GreyHead 18 Mar, 2009
Hi thisyearsgirl,

Hard to tell what's happening from the code snippet - that looks OK, but I'm not sure about 'after the php tag'
[sendfb][/sendfb]
Bob
thisyearsgirl 18 Mar, 2009
Sorry, I just meant I had added the code listed in the thread Max linked me:

$mydata = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
$introtext =$mydata['introtext'];

right after "<?php" but wasn't positive that was the right place.
GreyHead 18 Mar, 2009
Hi thisyearsgirl,

I think I found it . . . the getVar() method filters the input by default as a security protection from site attacks. You can control this by using an extra parameter in getVar. The syntax is

mixed getVar (string $name, [string $default = null], [string $hash = 'default'], [string $type = 'none'], int $mask)

and $mask can take these values

#
* @param int Filter bit mask. 1=no trim: If this flag is cleared and the input is a string, the string will have leading and trailing whitespace trimmed. 2=allow_raw: If set, no more filtering is performed, higher bits are ignored. 4=allow_html: HTML is allowed, but passed through a safe HTML filter first. If set, no more filtering is performed. If no bits other than the 1 bit is set, a strict filter is applied.


Bob
thisyearsgirl 18 Mar, 2009
I'm sorry, please excuse my ignorance, but I have no idea where to put those codes. I tried just inserting them after "<?php" in hopes of not bothering you again, but just got errors after the form was submitted.

Again, I really appreciate all the assistance.
GreyHead 18 Mar, 2009
Hi thisyearsgirl,

Sorry, it needs to go into the JRequest::getVar("fulltext") where you want to allow html. This would become
JRequest::getVar("fulltext", '', 'post', 'none', '4')
If 4 doesn't do the trick then try 2 instead.

Bob
thisyearsgirl 18 Mar, 2009
Great! That allows the main content of my article to have html formatting. Thanks so much! I still can't get proper formatting on the intro text when a bunch of articles are listed, but I think that's an issue with AlphaContent.

Thank you so much for all your help!!
This topic is locked and no more replies can be posted.