Use multiple form inside an article

< View previous topic | View next topic > 
Author Message
Intertron



Joined: 15 Sep 2009
Posts: 1
Location: Netherlands

PostPosted: Tue Sep 15, 2009 11:56 am    Post subject: Use multiple form inside an article Reply with quote
The Smartformer plugin only allows one form to add to an article at this moment.

I wanted to have two forms so I changed the plugin. Here is the code. You are welcome to use this.

Code:

function plgContentSmartformer( &$row, &$params, $page=0 )
{
   if (defined( '_JEXEC' )) {
      $database=& JFactory::getDBO();
      $GLOBALS['DOCUMENT_ROOT']=$_SERVER['DOCUMENT_ROOT'];
      $GLOBALS['mosConfig_live_site']=substr(JURI::root(),0,strlen(JURI::root())-1);
      $mosConfig_live_site=$GLOBALS['mosConfig_live_site'];
      $GLOBALS['mosConfig_absolute_path']=substr(__FILE__,0,strpos(strtolower(__FILE__),'plugins')-1);
   }
   require_once($GLOBALS['mosConfig_absolute_path'].'/components/com_smartformer/engine.php');

   $pos=strpos($row->text,'{smartformer:');
   while ($pos !== false) {
      $pos2=strpos($row->text,'}', $pos);
      if ($pos===false || $pos2===false) return true;
      $id=intval(substr($row->text,$pos+13,$pos2-$pos-13));
      $form = new SmartformerEngine;
      $smart_html=$form->render($id);
      $row->text=substr($row->text,0,$pos).$smart_html.substr($row->text,$pos2+1);
      $pos=strpos($row->text,'{smartformer:');  // find tag again for next loop iteration
   }

   return true;
}


So I changed
Code:
$pos2=strpos($row->text,'}');

into
Code:
$pos2=strpos($row->text,'}', $pos);

which is a good idea anyway.

And created a loop.

The only problem I have now is, that the data are also submitted to any cloned forms.
_________________
--
Kind Regards
Ronald Pijpers
Freelance developer
Back to top
View user's profile Send private message Visit poster's website
IToris team
Site Admin


Joined: 19 Jan 2009
Posts: 917

PostPosted: Thu Oct 22, 2009 12:28 pm    Post subject: Reply with quote
Hi Ronald,

Thank you for the hack, we will include it in the following version.

To avoid the problem with posting the data in several forms please try the following function:

Code:
function plgContentSmartformer( &$row, &$params, $page=0 ) {
 $database=& JFactory::getDBO();
 $GLOBALS['DOCUMENT_ROOT']=$_SERVER['DOCUMENT_ROOT'];
 $GLOBALS['mosConfig_live_site']=substr(JURI::root(),0,strlen(JURI::root())-1);
 $mosConfig_live_site=$GLOBALS['mosConfig_live_site'];
 $GLOBALS['mosConfig_absolute_path']=substr(__FILE__,0,strpos(strtolower(__FILE__),'plugins')-1);
 preg_match_all( "/\{smartformer.*:(.*)}/U", $row->text, $matches);
 require_once($GLOBALS['mosConfig_absolute_path'].'/components/com_smartformer/engine.php');
 if (!isset($GLOBALS['spost'])) $GLOBALS['spost'] = $_POST;
 foreach ($matches[0] as $key => $value) {
  if (isset($GLOBALS['spost'])) $_POST = $GLOBALS['spost'];
  if (intval($matches[1][$key]) != intval(@$_POST['sformid'])) $_POST = array();
  $form = new SmartformerEngine;
  $smart_html=str_replace('action="">','action=""><input type="hidden" name="sformid" value="'.intval($matches[1][$key]).'" />',$form->render(intval($matches[1][$key])));
  $row->text = str_replace($matches[0][$key], $smart_html, $row->text);
 }
 return true;
}

_________________
Our new Joomla dating component JoDDa
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

All times are GMT + 2 Hours

alexis2 theme created by: Andrew Charron and Web Hosting Bluebook
Powered by phpBB © 2001, 2002 phpBB Group