Populate form with page information

heybyrne 28 Jul, 2010
Is it possible to populate a form when the page loads with the current article, category and section information i.e. page title?
heybyrne 28 Jul, 2010
it appears we actually need the information from a previous page 😲 i.e. if a user wanted to request information about a product (within the article title) then they click a request information button that then takes them to the chrono form - would it be possible to then auto fill a text box for 'product' within the form with the preious pages title?

Is this a javascript function?
heybyrne 29 Jul, 2010
That's what I thought, but there's almost 50 pages of items and this would be reflected by the links within the module which is placed on the right of the page.

I think your on the right lines with

<input type="text" name="product" value="<?php echo JRequest::getString('product', '', 'get'); ?>" />



I've seen something similar to this to call the information for the page requested, but nothing for the previous page yet.

Any ideas?
heybyrne 29 Jul, 2010
I've discovered this:

[ VB ]
Public ReadOnly Property UrlReferrer As Uri

[ C# ]
public Uri UrlReferrer {get;}

[ C++ ]
public: __property Uri* get_UrlReferrer ( );

[ JScript ]
public function get UrlReferrer ( ) : Uri;


I assume for chronoforms it would be the JScript function?
heybyrne 29 Jul, 2010
Ok well I've fathomed this out, within the table properties under form code then expanding the HTML menu, I amended the code with the addition of 'value="<?php echo @$_SERVER['HTTP_REFERER']; ?>' - this then calls the previous pages url and posts it within the form for me.

So I went from:

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Product</label>
    <input class="cf_inputbox required" maxlength="150" size="50" title="" id="text_5" name="preqProd" type="text""/>
  
  </div>
  <div class="cfclear">Β </div>
</div>


to

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Product</label>
    <input class="cf_inputbox required" maxlength="150" size="50" title="" id="text_5" name="preqProd" type="text" value="<?php echo @$_SERVER['HTTP_REFERER']; ?>"/>
  
  </div>
  <div class="cfclear">Β </div>
</div>


So yay - but now if I could get the article title that would be even greater - if anyone knows a fix then I'd really appreciate itπŸ™‚
heybyrne 24 Sep, 2010
Bump bump πŸ˜€ just wondering if anyone does know how to parse the page title of the referring page?
nml375 24 Sep, 2010
Hi,
You could do something like this:
<?
$app =& JFactory::getApplication();
if ($app->isSite()) {
  if (array_key_exists('HTTP_REFERER', $_SERVER)) {
    $router =& $app->getRouter();
    $parts =& $router->parse($_SERVER['HTTP_REFERER']);
    if (array_key_exists('id', $parts) && array_key_exists('catid', $parts)) {
    // We have successfully identified the refering article.. let's proceed
      $article =& JTable::getInstance('content');
      if ($article->load($parts['id'])) {
        // We've successfully loaded the article.. now to print something useful?
        echo "You visited this form from the \"" . $article->title . "\" article.";
      }
    }
  }
}
?>

If you simply need the article or category id, you won't have to do the final step of loading the article, as these are already available in $parts['id'] and $parts['catid'], otherwize access the various properties of $article (see http://api.joomla.org/Joomla-Framework/Table/JTableContent.html for details on the JTableContent object and available properties).

/Fredrik
This topic is locked and no more replies can be posted.