Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-08-07 15:16:39

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

[SOLVED] Image alt, caption, cost & some more extra fields if possible

Hello,
I need to add some additional fields to pre-existing fields that come with txp’s image form.
After the alt & caption, I want to add a simple field called as cost and another one as product-id.
These two will go in “txp_image” table’s cost & product_id columns respectively.

I tried tweaking txp_image.php & txplib_db.php files a bit, it added “cost” field in the images form (check here). But when I try to save it, it gives error(check here).

I know getting it done this way is “wrong” but I just need to have some additional fields in the images form, as for this website, the images are working as individual products.

Thanks for your time.

EDIT:
This question is SOLVED.

I still have no clue to how to set this as ‘SOLVED’, it should be simple, they should add a button like ‘Set as SOLVED’ somewhere! :p

Nevermind, Thanks to everyone and especially Uli for helping me solve it. :)

Last edited by vineonardo (2012-08-07 20:51:03)

Offline

#2 2012-08-07 15:59:03

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

Hi Vineet

couldn’t you use the “image name” and the alt or caption fields to do what you need?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2012-08-07 16:19:17

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

Hi Colok,
Thanks for your reply. The thing is, all the fields except for the caption are being used to display product information. I’m only left with caption field right now which I can use but in future I might need more fields; also, caption can be alphanumeric but the cost has to be numeric only. This kind of validation is important as in future someone else might be updating the website.

We are trying to connect this installation of the textpattern to an e-commerce application, for products we are using images table. Thus we need to have more fields in image form only so that adding and updating the products will be easier and single time job.

Last edited by vineonardo (2012-08-07 16:21:28)

Offline

#4 2012-08-07 18:19:02

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

Things like these are fun to me :)

Alright, let’s see whether we manage to succeed here in the forum, and not via file exchange, so that others might recap this.

I added a table row cost to txp_image table via phpMyAdmin: varchar(12), utf8_unicode_ci.

The following changes all go into txp_image.php (at the time of writing v4.4.1. And you best use a fresh, unaltered, copy):

What you’ll have done is at least a change around (around! original line numbers are now shifted!) line 490, so that the field is displayed on the Image panel. (I duplicated the alt line and changed all instances of alt -> cost)

  1. Duplicate around line 122 (the one containing alt) and change alt -> cost (2x)
  2. If you want to search for a price in the image list view, duplicate around line 306, again changing alt -> cost (2x)
  3. Around line 638 look for extract(doSlash(gpsa(array('id','category','caption','alt' Add ,'cost' to the end (1x)
  4. Around line 654 duplicate the line containing alt and change alt -> cost (2x)

That should be sufficient, I think. Seems to work, at least here, and as far as I tried.

I just don’t see why you thought you’d have to edit txplib_db.php, these functions there are too basic, too little specialised, IMHO.

Last edited by uli (2012-08-07 18:45:00)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2012-08-07 18:34:56

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

@uli
Thanks for your answer. Duplicating alt line was the first thing I did, but due to lack of my php knowledge, I couldn’t get too far with that. I’ll follow your instructions with a fresh copy of textpattern again. :D

Thanks again, TextPattern’s forum members are so helpful, I knew someone would surely guide me. I am really very grateful.

Offline

#6 2012-08-07 19:05:06

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,075
Website Mastodon

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

uli wrote:

What you’ll have done is a change around line 490, so that the field is displayed on the Image panel. (I duplicated the alt line and changed all instances of alt -> cost)

And will this change have to be made every time one updates Textpattern?


…. texted postive

Offline

#7 2012-08-07 19:27:27

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

Yes.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2012-08-07 19:35:42

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

@uli

I did as you told, but additionally I also updated some more lines like
  1. duplicating alt line at line number 490
  2. at line number 231, I added 'cost='.urlencode($cost).a..

It works and now changes are also reflecting in the database just as they had to, thanks again.

What I was doing wrong at first time was, setting “Cost” as INT in database instead of VARCHAR as you suggested.

Thanks again, really appreciate your time & efforts! :)

p.s. Just in-case anyone wants have a copy of the file that I tweaked, you can download it here

Offline

#9 2012-08-07 19:47:29

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

You’re welcome, it was fun fiddling around a little :)

vineonardo wrote:

I did as you told, but additionally I also updated some more lines like

  1. duplicating alt line at line number 490
  2. at line number 231, I added 'cost='.urlencode($cost).a..

Interesting: I had these included as a sweeping blow at the beginning but found I could leave them out as well. What are they used for, Vineet, did you find out?

Last edited by uli (2012-08-07 19:49:56)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2012-08-07 19:55:03

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

uli wrote:

What are they used for, Vineet, did you find out?

Haha, well, like I said before, I’m not a PHP expert, so I can’t really give a good logical answer for your question, although, I’d like an answer for that too.

Do you think that line number 231’s code, 'cost='.urlencode($cost).a. helps textpattern to put the given data in the database table?

I guess that’s what it does. I think so cause, I was playing with this for over 2 hours before I posted question and I was getting errors, which now I guess, was cause of using INT instead of VARCHAR.

EDIT:

p.s How do I mark this post as ‘SOLVED’ ? :p

Last edited by vineonardo (2012-08-07 19:55:36)

Offline

#11 2012-08-07 20:03:05

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

vineonardo wrote:

Do you think that line number 231’s code, 'cost='.urlencode($cost).a. helps textpattern to put the given data in the database table?

To be honest: I don’t think it does, as it worked here without this change. I’m curious as well for the PHP experts to return from their barbecues/vacations ;)

vineonardo wrote:

p.s How do I mark this post as ‘SOLVED’ ? :p

Just edit the first post. Thanks!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#12 2012-08-07 20:39:42

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

Re: [SOLVED] Image alt, caption, cost & some more extra fields if possible

I was wondering if I could retrieve the ‘cost’ using <txp:image_info type="cost" />,
so I update the taghandlers.php file.

It works!

Offline

Board footer

Powered by FluxBB