Forums

Article posting of multiple fields

MacDaddy 20 Jul, 2009
Hello!
Im a new purchaser of chronoforms and have downloaded and imported submitcontent.cfbak.
I have the submitcontent.cfbak in its default state and its posting 'articles' fine, but is far too basic in its current form for my needs. So I am using it as a guide while I create another form via the wizard. Below is the wizard created FORM CODE>FORM HTML for the new form entitled "spirit_nominee":


<div class="form_item">
  <div class="form_element cf_heading">
    <h1 class="cf_text">Submit Your "Spirit of El Reno" Nominee Here</h1>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Nominees Name:</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_1" name="text_1" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Nominees Name: :: First and Last name, please.</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Nominees Phone:</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_10" name="text_2" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Nominees Phone: :: This will not be made public.</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Nominees Address:</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_5" name="text_3" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Nominees Address: :: This will not be made public.</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Nominees City:</label>
    <select class="cf_inputbox" id="select_13" size="1" title=""  name="select_4">
    
      <option value="El Reno">El Reno</option>
<option value="Calumet">Calumet</option>
<option value="Minco">Minco</option>
<option value="Union City">Union City</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Why Are You Nominating This Person?</label>
    <textarea class="cf_inputbox" rows="15" id="text_9" title="" cols="60" name="text_5"></textarea>
    <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Why Are You Nominating This Person? :: Please indicate full reason why this person should be considered for "Spirit of El Reno"</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Relation To Nominee</label>
    <select class="cf_inputbox validate-selection" id="select_9" size="1" title=""  name="select_6">
    <option value="">Choose Option</option>
      <option value="Friend">Friend</option>
<option value="Family Member">Family Member</option>
<option value="Co-worker">Co-worker</option>
<option value="Church">Church</option>
<option value="School">School</option>
<option value="Other">Other</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_fileupload">
    <label class="cf_label" style="width: 150px;">Please Upload Picture of Nominee</label>
    <input class="cf_fileinput cf_inputbox" title="" size="20" id="file_12" name="file_7" type="file" />
    <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Please Upload Picture of Nominee :: .jpg only. Not to exceed 100kb.</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_captcha">
    <label class="cf_label" style="width: 150px;">Captcha:</label>
    <span>{imageverification}</span> 
    
    </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_11" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


This is my On Submit code - after sending email:

<p><span style="color: #0000ff;"><strong>Thank you for submitting your nominee entry.  We will review it shortly and if approved it will be published.</strong></span></p>
<p><span style="text-decoration: underline;"><strong>Thank you again!</strong></span></p>
<?php
$_POST['catid'] = '49';
$_POST['id'] = '';
$_POST['sectionid'] = '6';
$_POST['state'] = '1';
$_POST['created'] = date("Y-m-d H:i:s");
?>


When filling out the form and hitting "Submit", it returns with "
Thank you for submitting your nominee entry. We will review it shortly and if approved it will be published.
El Reno Online!" so it appears to be posting, but when I go to the category, it shows me an edit icon, a BLANK Article Title, Todays "Date" and a BLANK "Author". And when i edit the form, there is nothing there. So is it being posted? Is it just NOT being retrieved for viewing? i dont know! Please assist?
GreyHead 21 Jul, 2009
Hi MacDaddy,

You are on the right road biut not quite to the end yet.

The submit_article form saves data to the Joomla Content Articles table, that only has a few specific columns that can take content. You can add any other fields you like in your form but by the time they are saved, they have to be in variables that match those column names.

Now text_1 and text_2 are the default field names that ChronoForms uses but they are not valid column names for the jos_content table so you either need to change the field names or add some more code to set up variables that match the column names.

Here's an example from the OnSubmit Before box of a submit_article form that I wrote recently. This one aggregates the inputs from many fields into a single article.
<?php
// echo '<div>$posted: '.print_r($posted, true).'</div>';
$order   = array("\r\n", "\n", "\r");
$replace = '<br />';
$posted['benefit_exp_1'] = str_replace($order, $replace, $posted['benefit_exp_1']);

$_POST['fulltext'] = "<h2>".$posted['site_title']."</h2> <h3>I help ".$posted['who']." to ".$posted['what'].".</h3> <h3>The three biggest problems in this market are:</h3><ul><li>".$posted['problem_1']." </li><li>".$posted['problem_2']." </li><li>".$posted['problem_3']." </li></ul> <h3>The three biggest benefits I offer are:</h3><ul><li>".$posted['benefit_1']."</li><li>".$posted['benefit_2']."</li><li>".$posted['benefit_3']."</li></ul><h3>About me:</h3><ul><li>".$posted['ci_name']."</li><li>".$posted['ci_location']."</li><li>".$posted['ci_email']."</li><li>".$posted['ci_phone']." </li></ul><p>".$posted['bio']."</p><h3>What other people say:</h3><p>".$posted['testimonial']."</p><p>// picture to be added </p>
<hr title='Benefit 1' alt='Benefit 1' class='system-pagebreak' />
<h2>".$posted['benefit_1']."</h2>
<p>".$posted['benefit_exp_1']."</p>
<hr title='Benefit 2' alt='Benefit 2' class='system-pagebreak' />
<h2>".$posted['benefit_2']."</h2>
<p>".$posted['benefit_exp_2']."</p>
<hr title='Benefit 3' alt='Benefit 3' class='system-pagebreak' />
<h2>".$posted['benefit_3']."</h2>
<p>".$posted['benefit_exp_3']."</p>
<hr title='Products and Services' alt='Products and Services' class='system-pagebreak' />
<h2>My Products and Services</h2>
<p>".$posted['prod_serv']."</p>
<p>".$posted['invitation']."</p>
";
?>
Note that here I'm using the $posted array as this is the output from a multi-page form and that I'm assembling most of the code into a single $_POST['fulltext'] valiable which will be the body text for the article. (There's also an introtext column that I'm not using here.

Bob
MacDaddy 21 Jul, 2009
Hello Bob, and thank you for taking notice of my issue.🙂
Ok.. on the verge of sounding daft, I'm unsure what you're suggesting.
Im not a developer, but im a decent hack. Meaning, I may not know it works, but I can follow the lose threads until i find the source. Some of the things mentioned, there are no loose threads for me to follow, so I have no idea what to do. :/

And the code you presented here... I see you stated it needed to go into the "OnSubmit Before box". ok.. so I alter it to my tables and do so. but.. what else? I was really hoping this might would have been covered in a manual or something when I bought it. Im sure I'm not the only one attempting to post and retrieve multiple fields into an article, hence the creation of the "submitcontent.cfbak". Now, if they would have created a version of "submitcontent.cfbak" that has more than ONE field and shows how to retrieve it, then I would be on to something.

Sorry for the small rant. I hate being clueless.
Max_admin 26 Jul, 2009
Hi MacDaddy,

The solution posted by Bob here should work fine for adding extra fields to articles, because Joomla content table can't be changed to include extra fields, the only way is to attach the extra data to the article body, and this is what Bob did!🙂

Regards
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
MacDaddy 26 Jul, 2009

Hi MacDaddy,

The solution posted by Bob here should work fine for adding extra fields to articles, because Joomla content table can't be changed to include extra fields, the only way is to attach the extra data to the article body, and this is what Bob did!🙂

Regards
Max


And for others needing help with the same thing, our final working result is:


<p><span style="color: #0000ff;"><strong>Thank you for submitting your nominee entry.  We will review it shortly and if approved it will be published.</strong></span></p>
<p><span style="text-decoration: underline;"><strong>Admin.</strong></span></p>
<?php
$_POST['catid'] = '49';
$_POST['id'] = '';
$_POST['sectionid'] = '6';
$_POST['state'] = '1';
$_POST['created'] = date("Y-m-d H:i:s");
?>
<?php
$_POST['title'] = $_POST['text_1'];
?>
<?php
$user =& JFactory::getUser();
$_POST['created_by_alias'] = $user->username;
?>
<?php
$_POST['fulltext'] = $_POST['text_1'].'<br><br>'.$_POST['select_4'].'<br><br>'.$_POST['file_7'].'<br><br>'.$_POST['text_5'];
?>


Thank you, Max, for the patient help. I know how tired you were, and that makes it far more appreciated.
And Bob, thank you as well for the code! This shows me exactly how to clean it all up and make it nicely presentable!
Cheers you two!
Navarre 06 Oct, 2011
How would I go about doing this in Chronoforms V4 (Joomla 1.7)?

Right now I have a send email action setup with an html email including css to correctly display the fields and format. I then have to view the source of the email and paste the code into the article content on my site (using the no editor option in Joomla to avoid pollution of the code).

If the "submit article action" had a Template tab like the "send email action" to replace the "full text field" then that would work too 😀 .
GreyHead 06 Oct, 2011
Hi navarre,

Build the content you want in a Custom Code action before the Submit Article action. Here's a re-written version of the code from my earlier post for CFv4

<?php
$order   = array("\r\n", "\n", "\r");
$replace = '<br />';
$form->data['benefit_exp_1'] = str_replace($order, $replace, $form->data['benefit_exp_1']);

$form->data['fulltext'] = "
<h2>{$form->data['site_title']}</h2>
<h3>I help {$form->data['who']} to {$form->data['what']}.</h3>
<h3>The three biggest problems in this market are:</h3>
<ul>
	<li>{$form->data['problem_1']} </li>
	<li>{$form->data['problem_2']} </li>
	<li>{$form->data['problem_3']} </li>
</ul>
<h3>The three biggest benefits I offer are:</h3>
<ul>
	<li>{$form->data['benefit_1']}</li>
	<li>{$form->data['benefit_2']}</li>
	<li>{$form->data['benefit_3']}</li>
</ul>
<h3>About me:</h3>
<ul>
	<li>{$form->data['ci_name']}</li>
	<li>{$form->data['ci_location']}</li>
	<li>{$form->data['ci_email']}</li>
	<li>{$form->data['ci_phone']} </li>
</ul>
<p>{$form->data['bio']}</p><h3>What other people say:</h3><p>{$form->data['testimonial']}</p><p>// picture to be added </p>
<hr title='Benefit 1' alt='Benefit 1' class='system-pagebreak' />
<h2>{$form->data['benefit_1']}</h2>
<p>{$form->data['benefit_exp_1']}</p>
<hr title='Benefit 2' alt='Benefit 2' class='system-pagebreak' />
<h2>{$form->data['benefit_2']}</h2>
<p>{$form->data['benefit_exp_2']}</p>
<hr title='Benefit 3' alt='Benefit 3' class='system-pagebreak' />
<h2>{$form->data['benefit_3']}</h2>
<p>{$form->data['benefit_exp_3']}</p>
<hr title='Products and Services' alt='Products and Services' class='system-pagebreak' />
<h2>My Products and Services</h2>
<p>{$form->data['prod_serv']}</p>
<p>{$form->data['invitation']}</p>
";
?>

Bob
Navarre 07 Oct, 2011
Okay, I went back to "the drawing table" and spent a few hours wrestling with this but was unsuccessful, the debugger didn't give any error codes, article gets saved but the fulltext just didn't return a value.

I understand how to create a custom action and I did put it in front of the submit article action. I believe the questions I should ask to lead me closer to victory are:

1. In the submit article action, do I leave field "full text field" empty?

2. In the custom code action, "mode" could be set to either controller or view in this case?

3. I understand the code you posted with the exception of
$order = array("\r\n", "\n", "\r");
$replace = '<br />';
$form->data['benefit_exp_1'] = str_replace($order, $replace, $form->data['benefit_exp_1']);


Are any of these 3 lines of code relevant for a one page form or should the following be sufficient?
<?php
$form->data['fulltext'] = "
<h1>Field 1: {$form->data['field_1']}</h1>
<h2>Field 7: {$form->data['field_7']}</h2>
<p>Field 20: {$form->data['field_20']}</p>
";
?>
GreyHead 07 Oct, 2011
Hi navarre,

1) I think that the full text box needs fulltext in it.

2) Controller should be good as you are in the On Submit event (View is only useful in the On Load event)

3) Those three lines replace any carriage returns or line-breaks with <br /> tags - only useful to stop the contents of textareas merging into one solid block of text.

Bob
Navarre 09 Oct, 2011
Thanks Bob!
It was fulltext in the full text box that did it.

Cheers!
This topic is locked and no more replies can be posted.