Jump to content

Recommended Posts

Hey everyone,

say I want to store invoices as pages inside PW, for later referral and storage as a scanned document, and to relate the items (themselves stored independently) listed on the invoice to the invoice.

Say I have a template for invoices and have to use the title field. Really, I don't want to give every invoice a name, title or other identifier - they come complete with the firm that sent the invoice, an invoice number and a date. These three really are enough to identify any invoice.

What to do with the title field? In my envisioned system, it is pretty much useless, but PW forces me to come up with a name for each invoice. Can I circumvent this? Can I somehow autoconstruct the title from the other inputs?

Thanks a lot for any suggestion!

Link to post
Share on other sites

Remove global flag from title so you can remove it from templates.

Name field is required, as it is sort of the "id" of the page that is needed to have.

  • Like 1
Link to post
Share on other sites

Sorry, I assumed it is clear. In the field advanced settings. Go to Setup -> Fields, open title field and under Advanced you'll find the Global setting. Uncheck it and you can remove title fields from templates.

  • Like 1
Link to post
Share on other sites

Greetings,

As Soma explained, you can turn off the need for the title field. However, I would want to make sure this is a good idea.

If you ever need those pages for other purposes, you'll likely want the title. Also, the "title" can be anything (any field). It does not need to be an extra field, and the user does not even have to know that it's a "title." For example, I'm working on a site with separate pages for numerous retail stores. Stores each have a unique "store number," and I just made that the "title." The user does not know that when they enter the store number they are simultaneously creating a "title," but now I have that bit of information to use in my template code.

Based on your description, it sounds like your users are already building invoices through field entries. Maybe just use the "invoice_number" field as the title?

Thanks,

Matthew

  • Like 3
Link to post
Share on other sites

Thanks for your replies everyone. I'm sorry I haven't replied earlier - I forgot to follow my own topic.

@Soma: It's good to learn that turning off the global flag is an option, seems to be quite exactly what I need - and @pwired: yes, it's really not as obvious to me as it surely is to anyone more familiar with PW :) - would have taken me ages to find out on my own.

@MatthewSchenker: I would love to use the "invoice_number" field as the title! Sadly, it is just a string, and nothing precludes different vendors to produce identical invoice numbers.

If I could combine the fields "vendor" and "invoice_number" into the "title", that would be really great! Like a mysql composite key.

My gut feeling says that's impossible. But if anyone thinks otherwise, I would much appreciate hearing it!

So again, thanks to all of you!

Link to post
Share on other sites

To populate a field on save you can create a autoload module (see HelloWorld.module)

And do something like this 

$this->addHookBefore('Pages::save', $this, 'addTitle');
 
public function addTitle($event) {
        $page = $event->arguments[0];
        if($page->template->name !== "product") return;
        $page->title = $page->somefield . " " . $page->field2;
    }
 
  • Like 1
Link to post
Share on other sites

Your code is a mess Soma :D

I did some corrections:

public function addTitle($event) {
        $page = $event->arguments[0];
        if($page->done) return;
        if($page->template->name !== "product") return;
            $page->title = $page->somefield . " " . $page->field2;
            //$page->trackChange("data"); <- is this needed? I got an error, and it worked without
        //}
        //$page->done = true; <- same goes for this
        //$page->save(); <- the hook is before save, so we don't need this
    }
Link to post
Share on other sites

Thanks diogo, yeah might some in there that is not needed. It was original from a repeater on page and done months ago so might not all right there for simple page, just edited it in browser quickly. :)

Edited my example. Does it work like this?

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By prestoav
      Hi all,
      I could have sworn I used to be able to use the site generic 'title' field as a sub field of a repeater field. However I've tried to do this on two 3.0.165 sites recently and, while it will add the title field in the repeater field setup, it wont save the repeater title sub field's content when the repeater is used in a page template and edited.
      It;'s not a big issue but I wondered if this was a known restriction?
    • By spercy16
      I was previously using individual fields to capture and output multiple cards onto my web page but after recently learning about repeaters would prefer to use this field type, as it will be a lot more user friendly for end users to create new cards. I tried to modify my code to grab the fields from the new Repeater field(s) but am getting this error message on the page:
      Here is the code I'm currently trying to use for the cards:
      <?php // https://processwire.com/api/arrays/ // check if the array of images has items foreach($page->tall_card as $card) { $count = 0; $count++; $options = array( 'quality' => 70 ); $image = $card->image; $img = $card->image->size(550, 400, $options); $cardHeading = $card->title; $cardBody = $card->plain_paragraph; $raised = $card->raised_amount; $goal = $card->goal_amount; $link = $card->link; if ($raised == 0 ) : $percent = 0; else: $percent = $raised_amount / $goal_amount * 100; endif; if ($percent <= 5) : $percent = 0; endif; ?> <span id="card<?php echo $count?>" class="card"> <img class="cardThumb" src="<?php echo $img->url; ?>" alt="<?php echo $image->description; ?> Thumbnail" /> <div class="cardBody"> <div class="cardText"> <h2><?php echo $cardHeading; ?></h2> <?php echo $cardBody; ?> </div> <div class="progressBarSection"> <progress class="progressBar" id="progressbar<?php echo $count; ?>" value="<?php echo $percent; ?>" max="100"></progress> <span class="raisedAmount"> $<?php echo $raised; ?> usd </span> <span class="goalAmount"> $<?php echo $goal; ?> usd </span> </div> <div class="primaryBtn"> <a href="https://www.paypal.com/donate?hosted_button_id= <?php echo $link; ?> &source=url"> <button> <i class="fas fa-donate"></i> Donate </button> </a> </div> </div> </span> <?php } ?> Thanks in advance for any help!
    • By spercy16
      Coming from Perch (CMS) to Processwire, the one major downside I've found is that every place I want to insert content into my pages requires a single field (be that an image, integer, string, etc.). This can be a real pain to setup and manage if you have a lot of pages, many of them with dozens of unique fields. For example, on the Projects page of a site I'm working on right now I have to have fields for donate_amount (1-15, meaning fifteen unique fields that I have to duplicate manually), goal_amount(1-15), card_body(1-15), etc. After using Perch for a while, the way their system works is simply easier. You instead create your fields in a single PHP template (for every unique section, like a card) and their CMS imports those fields into the CMS when you choose to use that card, then you just fill in the values. You can also choose to reuse that card multiple times and each one you add gives you the several fields you need to fill in. So you can easily add your 15 cards, each with a picture, title, paragraph, and link, etc. and each one is basically given a unique ID that you can reference in your CSS files. If there's any way to make fields and templates work more like that, it would be a truly outstanding and efficient CMS. The great advantage of the way Perch is setup is that I can make a card with 10 fields, if need be, and easily duplicate that card out 40 times if I need 40 cards on the page and wouldn't need 10 fields for 40 cards (meaning in PW I would need 400 fields). If there's an easier way to do this in PW I would love to know, but as of right now, from what little I do know about the CMS 400 fields would be the only way to set that up, and that would be much more time consuming than if I could create one card (in PHP) with 10 fields that automatically added a number to the end of each field for each card (if that makes sense).
    • By benbyf
      Never really got my head around field groups and it shows, In my module uninstall I think I figured out how to delete a page, then a template and it's fieldgroup so that nothing gets upset. But for fields that belong to templates that need to stoick around I'm still abit stuck to how you would remove the field and when I try I still get:
      Unable to delete field '[field name]' because it is in use by these fieldgroups: 'user'
      is there a tutorial or best method for removing added fields, pages and templates?
    • By louisstephens
      So I ran into a strange error this morning when trying to publish a page. I went to publish a new page under "clients", but I get an error that says "Cannot be published until errors are corrected". I thought perhaps I had missed a required field so I checked, but none of the fields are marked as required. I then checked to see if I could just add a basic page (default basic-page.php template) under the homepage, but I get the exact same error when trying to publish. When looking at the template, I don't see any error messages being displayed above any fields.
      The odd thing I found though was if I got to "settings"  and uncheck "unpublished", I can then publish the page without errors. I did upgrade earlier today to the newest version to hopefully fix an issue I had yesterday (which it did). Has anyone run into this error before? 
      **EDIT**
      Well, after a lot of staring and pulling my hair out, I found the issues. I had installed multi-language support sometime ago (and due to the project changing, had to remove it). Apparently in my haste, I did not remove all the dependencies so it was still trying to check for the multi-language title (I am guessing) even though it actually wasnt on the page. I went through the database and removed it and can now save/publish pages without issues. 
×
×
  • Create New...