Jump to content

gRegor

Members
  • Posts

    111
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by gRegor

  1. In early August I installed the dev branch of ProcessWire 2.5. I'd like to upgrade to the latest dev version. Does that entail just uploading the latest version of the files, then checking the install.sql file and making changes to the database manually? Unfortunately, I did not make note of which Git commit it was I installed from, though I could probably narrow it down to the date. The footer reports v2.4.10, but I don't think that's correct? Thanks for any help. I'm new to running dev versions of PW.
  2. $var = (int) NULL; Will result in zero, unless there is some weird PHP setup I'm not aware of.
  3. Currently, I have chosen to set up a module based on the Auto Paragraph module linked above, except it's a general-use module that I load on demand and pass the text into. It seems to work well. I'd still appreciate feedback if there is an easier / preferred method for doing this, though. Thanks!
  4. Personally, I'd prefer casting it explicitly to an integer. That way if it's empty, it will become a zero. Also, since you set the average flying time to a shorter variable, might as well re-use it. $farflung = ''; $airport = $page->DMC_select->DMCstats_Airports->first(); $flying_time = (int) $page->DMC_select->DMC_Average_Flying_Time_hours; if ( $flying_time > 1 ) { $plural = 's'; } if ( $flying_time > 0 && $flying_time < 6 ) { $flying_message .= "With the average flight from a UK airport to {$airport->title} ({$country}) at just {$flying_time} hour{$plural} this is an ideal short haul destination."; } else { $farflung = "far flung {$flying_time}"; }
  5. Hello, I have built a form that allows authenticated members to submit articles through a front-end form. I was under the impression that 2 newlines would automatically be converted to paragraph elements, but I'm pretty sure that's incorrect as I re-acquaint myself with this aspect of PW.** Then I was thinking there was a TinyMCE configuration to convert newlines to paragraphs. There is, but I'm pretty sure that applies only during entry into the textarea, not when the text data is first loaded into the TinyMCE textarea. First, is there a built-in PW paragraph formatting function that I'm missing/forgetting? If not, would the "preferred" method to achieve this be using TinyMCE on the front-end form, so newlines are converted to paragraphs before the form is submitted and the page fields are stored? If so, can someone point me to an example of using the PW API to include a TinyMCE field input? Or would the preferred method be to process the raw input to convert newlines to paragraphs (through another module, or custom code) before saving the page fields? I'm aware there is an Auto Paragraph TextFormatter module, but I believe that only applies when the data is output — not when the data is shown in backend. Thanks for any assistance! ** I have confirmed that the newlines are stored in the database, so I've confirmed they're neither being removed nor converted.
  6. For the sake of time (I need to get this form set up rather quickly), I'm doing something similar to Soma's code here: https://gist.github.com/somatonic/5233338 I'm still curious if there's a method to achieve what I want without additional code to process the fields - using mostly native API methods, that is. Please let me know any suggestions.
  7. Thanks, adrian. That actually adds to the error message array, so both messages appear, which is undesirable. I had experimented with that a bit previously. My form is set up in the same way as soma's first post in that thread, using the render() method to display the form after building all the fields via the API.
  8. Hi, all. I've read through most of soma's thread "Create simple forms using API" and think I understand the basics pretty well. I fall in love more and more with Processwire each day. First, I am wondering if it's possible to not display the error messages inline, with each form field, and instead show a list of errors at the top of the form. The typical UI I use for form error messages is "Please fix the following errors and re-submit the form" followed by an unordered list of the error messages. I see that the getErrors() method returns an array of the field names and error messages, so that is simple enough. I'm not sure how to turn off the error messages that display with each form field, though. Secondly, I am wondering if it's possible to customize the error message for each field, via the API. I understand the text can be internationalized, but I am looking for more specific messages like "Please enter your First Name" instead of "First Name: Missing required value." Thanks for any help!
  9. Thanks, onjegolders! I was not aware of that. I'd searched the API and forums a bit, but had not looked at modules yet.
  10. Hello, I am trying to set up a multi-level menu in nested unordered lists. Specifically, I want to get pages from the first three levels in the page hierarchy. Since the page structure is somewhat complex and I wanted it to be flexible in the future, I added a checkbox field named "in_main_menu" that I can then use as a selector, in case some pages should not appear in the menu. The top level menu was easy: $main_menu = $pages->find('parent=/, in_main_menu=1, sort=sort, limit=7'); Then, as I was thinking through how to set up the nested navigation under each main menu item, I was thinking a "maximum depth" selector would be handy. Return all pages matching this selector that are no more than 3 levels deep in the hierarchy. I could not find a way to do that with selectors, though. I believe such a method would not return the pages in the exact order I want, anyway. My next thought was that I can just perform a find that returns all pages with in_main_menu, then process the results and build an array in the desired format. I'm not totally sure how that processing would work; I think it would be a bit complicated. Rather than dive into that . . . my final attempt (before posting now ) was to loop through the main menu pages and call children() on each of those. Then repeat for the third level. This seems to work, except for the third level, where I get an error. # loop: main menu pages foreach ( $main_menu as $main ) { // output top-level menu item # if: secondary menu if ( $secondary_menu = $main->children('in_main_menu=1') ) { # loop: secondary menu pages foreach ( $secondary_menu as $second ) { // output second-level menu item # if: tertiary menu if ( $tertiary_menu = $second->children('in_main_menu=1') ) { # loop: tertiary menu pages foreach ( $tertiary_menu as $third ) { // output third-level menu item } # end loop: tertiary menu pages } # end if: tertiary menu } # end loop: secondary menu pages } # end if: secondary menu } # end loop: main menu pages And it looks like this will work! My question, though, is whether I'm overlooking a simpler method. I would welcome your feedback. I realize I could abstract my code into a function (that would also allow N-levels), but I'm curious if there's even easier ways with the PW API.
×
×
  • Create New...