Forums

submitcontent allmost what I need

lennart 01 Feb, 2011
I want visitors to submit articles on my website.
But I want all of the articles to have the same format.

That's why I want my visitors to fill in a questionform. The answers will get a specific spot in the article.

For example:
Question 1: title?
Question 2: fulltext?
Question 3: what transport did you use?

So the output should be like an email template:

<p>Hi,</p>
<p>New user has submitted a new Content item, please review it!</p>
<p><strong>Title:</strong>{title}</p>
<p><strong>Body:</strong> {fulltext}</p>
<p><strong>TRansport:</strong> {transport}</p>

The question is: how can I achieve this.

How can I replace this part of submitcontent by a form?


<?php
$editor =& JFactory::getEditor();
echo $editor->display( 'fulltext', '' , '80%', '350', '55', '20', false ) ;
?>
GreyHead 02 Feb, 2011
Hi lennart,

You can only use three fixed columns to save the contents of an article: title, introtext and fulltext.

You can use any PHP you like to combine the results from your form as long as they end up in the three $_POST variables with these names.

There's a long example of this using a multi-page form in Chapter 12 of The ChronoForms Book.

For your example you'd need something like this in the OnSubmit Before Email box (you must have "Send Emails" set to yes in the Form General tab for this code to run).
<?php
$title = JRequest::getString('title', '', 'post');
$fulltext = JRequest::getString('fulltext', '', 'post');
$transport = JRequest::getString('transport', '', 'post');
$article = "<p>Hi,</p>
<p>New user has submitted a new Content item, please review it!</p>
<p><strong>Title:</strong> $title</p>
<p><strong>Body:</strong> $fulltext</p>
<p><strong>Transport:</strong> $transport</p>";
JRequest::setVar('fulltext', $article);
?>

Bob

PS You might be better changing the name of the 'fulltext' input to avoid confusion.
lennart 02 Feb, 2011
Thanks Greyhead, I understand this: "You can only use three fixed columns to save the contents of an article: title, introtext and fulltext."
I want fulltext to be shaped by a form instead of by an editor.

So the answer to howto is in your book!? That's what Multipage forms is about?
But to read it, I have to buy your "The ChronoForms Book". Am I right?
GreyHead 02 Feb, 2011
Hi lennart,

There's a long example in the book - you don't have to buy it and you don't need multi-page forms.

The code that you do need is in the example that I posted.

Bob
lennart 02 Feb, 2011
Could you make an form-to-article-example.cfbak🤣? Or am I asking too much now🙄?

The perfect example for me would be a form that asks several questions like:

What were your symptoms of disease?
What medicine did you use?
What therapist did you see?
What therapy did you receive?
What were you treated for?
How many treatments did you have?
Your story:
Also contains an editor for part of the fulltext (I would call it mystory).


And then the outcoming article would look like this:

Title {title}

Fulltext, containing:
[list]
  • symptoms: {symptoms}

  • medicine: {medicine}

  • therapist: {therapist}

  • treated for: {treatedfor}

  • Amount of treatments: {treatments}

  • My story: {mystory}

  • [/list]
    GreyHead 02 Feb, 2011
    Hi lennart,

    I'd be happy to do it -if each day had about 48 hours :-(

    I think the kind of thing you have in mind is a form like this that creates an article like this.

    Bob
    lennart 02 Feb, 2011
    Ow, that looks superb! I am impressed! I will settle for this!
    How can I achieve something like that? Please advise me!
    Is there an example .cfbak for that?


    For me, there is only one thing missing in this example...
    Could a textarea like "testimonial" and "Your bio" be replaced by an editor to provide the author more "freedom of designing" their main text for these areas of the article only?


    Ah no, forget my last comment above: this way WORD-code will enter the article...
    Without editor the code stays clean.
    GreyHead 02 Feb, 2011
    Hi lennart,

    I hate so say it but that's the form that got written up in the book :-( You do get most of the code too.

    Packt haven't made this particular 'recipe' free for me to re-publish but here's the main chunk of code which is very similar to the code you've already seen.

    Note that $posted is the result array used for multi-page forms. If you only have one page you can use $_POST or, better the Joomla! JRequest methods.

    Bob

    <!-- On Submit Before code to build an article -->
    <?php
    if ( ! $mainframe->isSite() ) { return; }
    $order   = array("\r\n", "\n", "\r");
    foreach ( $posted as $k => $v ) {
    	$posted[$k] = str_replace($order, '<br />', $v);
    }
    $_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>
    ";
    $_POST['sectionid'] = '5';
    $_POST['catid'] = '34';
    $_POST['id'] = '';
    $_POST['state'] = '1';
    $_POST['created'] = date("Y-m-d H:i:s");
    $_POST['title'] = JRequest::getString('site_title', 'My website', 'post');
    $user =& JFactory::getUser();
    if ( $user->id ) {
    	$_POST['created_by'] = $user->id;
    }
    $_POST['created_by_alias'] = JRequest::getString('ci_name', 'Me', 'post');
    ?>
    <!-- End of On Submit Before code to build an article -->
    lennart 04 Feb, 2011
    Thanks Bob!
    I think I have enough clues now to figure it out!
    This topic is locked and no more replies can be posted.