Forums

Image in TCPDF

Fredolino 03 Jun, 2016
Hi,

I use the TCPDF action in the form.
An image in the PDF is displayed correctly (
<img src = "/ www / htdocs / xxxxxx / __ test / components / com_chronoforms5 / chrono forms / uploads / Logo.jpg" />
<p>
</ p>)
I want to insert a second image in the PDF that was saved in the internal Joomla database as category-image (table name: #_categories). Each category has a different picture.
Maybe:
<img src = "? / Www / htdocs / xxxxx / __ test / images / categories / <? Php echo $ this-> category-> getParams () -> get ('image');?>" />

But that does not work well.
It appears to me the PDF without the header and footer and without images. The ä,ö,ü... in the text are not displayed correctly.
Is there perhaps an idea? Or has a specific code to be inserted directly into the tcpdf.php?

Best wishes
F.
GreyHead 03 Jun, 2016
Hi Fredolino,

An image tag needs a URL - not a path so that needs to be fixed; and because of the way that TCPDF works you may need to make that an absolute url like /images/categories/image_name. I would use a Custom Code action before the TCPDF action to get the image name - and probably build the image tag too.
<?php
// something here to define $this ???
$image = $this->category->getParams()->get('image');
$form->data['image_tag'] = "<img src='/images/categories/{$image}' alt='xxx' />";
?>
Then add {image_tag} in the TCPDF template.

Bob
Fredolino 03 Jun, 2016
Hi Bob,
Thanks for the tip!
In this direction it should go:
<?php
//$input = JFactory::getApplication()->input;
$app = JFactory::getApplication();
$params = &JComponentHelper::getParams('com_alpha');
$image = $this->category->getParams()->get('image');
$form->data['params'] = "<img src='/images/categories/{$image}' alt='xxx' />";
?>


But I have made a mistake.
Fatal error: Call to a member function getParams () on a non-object in ...

Probably because the data from option-fields come from the Joomla component (screen).
In the DB table "#_categories" the data is stored (screen1) in the "params".

Best wishes
F.
GreyHead 03 Jun, 2016
Hi Fredolino,

As I said if you are going to use $this then you need to define it. I have no idea what that object is supposed to be.

Do you have the Category ID available? You might be able to get it from the current menu setting or the page URL.

Bob
Fredolino 03 Jun, 2016
Hi Bob,

yes i have this:
GreyHead 03 Jun, 2016
Hi Fredolino,

If you have the page URL - see this FAQ - then you can look up the menu item and it's associated category.

Bob
Fredolino 03 Jun, 2016
this from Menu-link?
index.php?option=com_content&view=article&id=2
Fredolino 03 Jun, 2016
:-) sorry...
this is from Menu:
Fredolino 03 Jun, 2016
Hi Bob,

with this code for Menu-title:

<?php
/** Getting the Menu ID of Menu was clicked by user **/
$menu    =   &JSite::getMenu(); 
$id    =   $menu->getActive()->id;

/** Getting the Title of the Menu by using id. **/ 
$db    = JFactory::getDBO();
$query    = "SELECT title FROM #_menu WHERE id = $id";
$db->setQuery($query);
$rows    = $db->loadObjectList();
$itemrow = $rows[0];
$title   =   $itemrow->title;

echo "Menu you have clicked is : ".$title;
?>
Menu you have clicked is : Gutschein einlösen


And this is in the table #_menu:

:-)
Fredolino 06 Jun, 2016
Hello,
my updated this script:
<?php
    // Get a db connection.
    $db = JFactory::getDbo();
    // Create a new query object.
    $query = $db->getQuery(true);
    $query
        ->select(array('title, description, params'))
        ->from('#__categories')
        //->where('title = \''.$group_name.'\'')
		->where('title = "'.$group_name.'"')
        ->where('extension = \'com_alphauserpoints\'')
        ->where('published = \'1\'');
    // Reset the query using our newly populated query object.
    $db->setQuery($query);
    // Load the result(1) as an object.
    $cat = $db->loadObject();
   $catparams = json_decode($cat->params); 
$form->data['params'] = "No image";
?>


params shows in TCPDF: "No image"

Test:
$form->data['params'] = "<img src='/images/categories/{$image}' alt='xxx' />";
Shows nothing in TCPDF

Test:
$form->data['params'] = "<img src='/images/categories/bild.jpg' alt='xxx' />";
Shows nothing in TCPDF

Where can still be the problem?

F.
GreyHead 06 Jun, 2016
Hi Fredolino,

Where exactly is the bild.jpg image - I don't see anything at http://test.your_domain,de/images/categories/bild.jpg ?

Bob
Fredolino 06 Jun, 2016
Hi :-)
this wars for the test.
This ist the real URL with .jpg:

$form->data['params'] = "<img src='/images/categories/avatar.jpg' alt='xxx' />";
GreyHead 06 Jun, 2016
Hi Fredolino,

Does that work if you put {params} in the TCPDF template?

Bob
Fredolino 06 Jun, 2016
Hi Bob,

no , i have this in TCPD:
<p>{params}</p>


This is ok in TCPDF:
<p><img src="/www/htdocs/xxxxx/__test/components/com_chronoforms5/chronoforms/uploads/TCS_Logo.jpg" />
</p>


and i have test this in TCPDF:
<p><img src="/www/htdocs/xxxx/__test/images/categories/avatar.jpg" />
</p>


is ok.
Fredolino 06 Jun, 2016
...or i must make this:
// GET CATEGORY ID
$option   = JRequest::getCmd('option');
$view   = JRequest::getCmd('view');
$temp   = JRequest::getString('id');
$temp   = explode(':', $temp);
if ($option == 'com_content' && $view == 'category' && $temp[0]){
   $category_id  = $temp[0]; 
}

//GET THE CATEGORY CONTENT OBJECT 
jimport( 'joomla.application.categories' );
$categories = JCategories::getInstance('Content');

 
//GET THE CATEGORY OBJECT
$cat = $categories->get($category_id);

//USES THE PARENT_ID ARRAY KEY
echo $cat['parent_id'];
GreyHead 07 Jun, 2016
Hi Fredolino,

Sorry, I don't know what the question is ??

And I'm a bit surprised if you have the images working using folder paths instead of a URL ??

Bob
Fredolino 07 Jun, 2016
Hi Bob,

this code works:

<?php
    // Get a db connection.
    $db = JFactory::getDbo();
    // Create a new query object.
    $query = $db->getQuery(true);
    $query
        ->select(array('c.title, c.description, c.params'))
		->from($db->quoteName('#__categories', 'c'))
		->join('INNER', $db->quoteName('#__alpha_userpoints_coupons', 'a') . ' ON (' . $db->quoteName('a.category') . ' = ' . $db->quoteName('c.id') . ')')
		->where($db->quoteName('a.couponcode') . ' = ' . $db->quote($form->data['modAUP_CPsCouponValue'] ));
    // Reset the query using our newly populated query object.
    $db->setQuery($query);
	$db->execute();
    // Load the result(1) as an object.
	if ($db->getNumRows() > 0)
	{
    	$cat = $db->loadObject();
		$params = json_decode($cat->params);
		if	($params->image)
		{
			$form->data['params'] = sprintf('<img src="%1$s" alt="%2$s" />', $params->image, $cat->title);
		}
	}		
?>


Best wishes
F.
GreyHead 07 Jun, 2016
Hi Fredolino,

Excellent - well done :-)

Bob
Fredolino 07 Jun, 2016
Hi :-)
One thing, however, is still struck me:
In the form I use in "On submit" the "check Google NoCaptcha" action.
Under this action is the event Switcher.

If the Captcha query is not clicked on the form, then although no e-mail will be sent with PDF, but the coupon code will still be redeemed.
This is a mistake. Do I have perhaps the event Switcher or NoCaptcha move?

F.
GreyHead 07 Jun, 2016
Hi Fredolino,

That looks correct, if the Google NoCaptcha check fails then the form is reloaded, the coupon isn't used and no email is sent.

Bob
Fredolino 23 Aug, 2016
Hi,
in the send via mail PDF the correct image is displayed. Given this script:

<?php
 // Get a db connection.
 $db = JFactory::getDbo();
 // Create a new query object.
 $query = $db->getQuery(true);
$query
->select(array('c.title, c.description, c.params'))
->from($db->quoteName('#__categories', 'c'))
->join('INNER', $db->quoteName('#__alpha_userpoints_coupons', 'a') . ' ON (' . $db->quoteName('a.category') . ' = ' . $db->quoteName('c.id') . ')')
 ->where($db->quoteName('a.couponcode') . ' = ' . $db->quote($form->data['modAUP_CPsCouponValue'] ));
// Reset the query using our newly populated query object.
 $db->setQuery($query);
$db->execute();

// Load the result(1) as an object.
if ($db->getNumRows() > 0)
{
$cat = $db->loadObject();
$params = json_decode($cat->params);
if ($params->image)
 {
$form->data['params'] = sprintf('<img src="%1$s" alt="%2$s" />', $params->image, $cat->title);
}
 }  
?>


What can I do but that this image is displayed simultaneously on the form? So even before the PDF is sent with onsubmit.
I would recommend this script translated as "Custom Code" in "On Load" and change the line:

echo $form->data['params'] = sprintf('<img src="%1$s" alt="%2$s" />', $params->image, $cat->title); 


That shows me not the right category-image in the form. With a session action it did not work. Or have I made a mistake.
Can I use an Action of ChronoForms? Or Javascript or Custom Code?

Many thanks for the help.

F.
GreyHead 24 Aug, 2016
Hi Fredolino,

If you know the Category when the form loads then you can use the same code in the On Load event.

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