Posts by hus_hmd

    You would add your form handler to addons/apps/sm_contact/runtime.php:


    PHP
    1. function sm_contact_form_handler($SubmittedForm) {
    2. if($SubmittedForm->validate()) {
    3. // access the data via $SubmittedForm->data instead of $_POST
    4. }
    5. }


    The validate() method will throw the basic errors for you (e.g. required/email fields). You can also programmatically throw an error:


    PHP
    1. $SubmittedForm->throw_error('error_type', 'field_id');
    2. $SubmittedForm->throw_error('max_upload_size', 'cv');


    And you can pass the response to another app (e.g. the perch_forms app):

    PHP
    1. $SubmittedForm->redispatch('perch_forms');

    In your list template, you need to output the rendered HTML of your page links template with page_links:


    HTML
    1. <perch:after>
    2. </div>
    3. </div>
    4. <perch:content id="page_links" encode="false" />
    5. </perch:after>

    'filter-mode' => 'ungrouped' does nothing for collections.


    For reference this is your original code:



    It seems your are passing a year with perch_get('filter_year'). You can't just pass the year (e.g. 2018) to filter by a date field. You need to provide a full date like 2018-01-01 00:00:00. The Blog app comes with an archive page which you can use as a reference for date filtering.


    You need to rewrite the filter as a date range e.g. from 1 January 2018 to 12 December 2018:




    In your case it looks like you also need to check whether $date_to is greater than the current date:


    PHP
    1. $year = perch_get('filter_year');
    2. $now = date('Y-m-d H:i:s');
    3. $date_from = $year . '-01-01 00:00:00';
    4. $date_to = $year . '-12-31 23:59:59';
    5. if(strtotime($date_to) > strtotime($now)) {
    6. $date_to = $now;
    7. }

    Hi Stephen,


    Like JordinB suggested you can build an app with a form handler and use it to handle these forms. Your app's form handler can also pass on the response to the Perch Forms app if you want to use it to store a copy of the response in the database.


    Alternatively, you can build an app that listens to the perch_forms.received event. This approach is useful if you rely on the Forms app for handling spam. See: Multiple apps in the form tag and SPAM!

    Hi James,


    You can give each one a different label:


    HTML
    1. <perch:content id="Heading_l" type="text" label="Left Column: Title" required="true" title="true" />
    2. <perch:content id="Heading_m" type="text" label="Middle Column: Title" required="true" title="true" />

    If you always want to sort them in the same manner, you can define the default sort column and direction. The all() function will use these by default:


    PHP
    1. class MikeEvents_Events extends PerchAPI_Factory {
    2. protected $default_sort_column = 'yourcolumn';
    3. protected $default_sort_direction = 'DESC';
    4. }

    The query looks up products in the category with the category path products/sero-pressure-cushions/. However, based on the screenshot and the context we're discussing it should be a sub-category: products/pressure-cushions/sero-pressure-cushions/.


    I was expecting the URL to include the parent category too with something like /products/parent-category/sub-category. Isn't this what you're after?

    What I would like to do is to pass the value of perch get to the category template too. Then, if this value is equal to catSlug give this category the "active" class.


    Is this possible within perch? Or has anyone come up with a clever solution to do achieve the same thing?


    You can use PerchSystem::set_var() to pass a variable to the templating engine. And you can use perch:if tags to perform your check.


    PHP
    1. PerchSystem::set_var('active_catSlug', perch_get('cat'));
    2. perch_categories();


    HTML
    1. <perch:if id="catSlug" match="eq" value="{active_catSlug}">
    2. <!--* matched *-->
    3. </perch:if>

    Logout only works if you are using an incognito mode. If you use a regular browser window, it will not logout correctly until you dump the browser cache. Is this a bug?


    The fact that it works in incognito mode suggests it is not a bug. Incognito mode gives a fresh session and will still cache and store cookies; it just does not keep them once you close all your incognito browser tabs/windows.


    Have you only tested this in a single browser on a single device? Do you have any browser extensions installed? If you are unsure how to proceed to diagnose this, you can contact a registered developer to assist you with this.

    The following returns the rendered template:


    PHP
    1. $sub_categories = perch_categories([
    2. 'template' => 'product-sub-category.html',
    3. 'filter' => 'catPath',
    4. 'match' => 'regex',
    5. 'value' => '^' . $catPath . '([a-z])+'
    6. ], true);


    So given you have perch:noresults tags in the sub-categories template, it will always return something and hence the following condition will always evaluate to true:


    PHP
    1. if($sub_categories) {
    2. }


    I would move the perch:noresults message to your product list. The logic is:


    • First display top-level categories
    • When you are on a category page, check if it has some sub-categories. If it does, display them.
    • Otherwise display the products within that category. If there is none, display the perch:noresults message


    So you never really need to display the perch:noresults message for sub-categories; only for products.

    When the value for the action is set to target an anchor (ie, action="#anchor") on the same page (no page reload) and not load a separate page,

    A form submission will reload the page even if an anchor is used as the value for the action attribute. It may not be clear if you're testing a fast/cached page, but you can confirm this by opening the browser dev tools and going to the network tab and then submitting the form.


    If you don't want a page reload, you need to submit the form and update the cart count with Javascript.

    What JordinB suggested sounds like it should work. From the debug message it shows you are not passing the category slug correctly. Make sure you assign a value to the variable $categorySlug before calling perch_category():


    This makes sense. However, I'm not sure I understand what you need help with. Could you clarify?


    If I change the action to action="/cart" it works as intended, but I am assuming I need the submit event to reload the page or something similar. Can anyone shed some light on what might be needed for this to work? My intention is to show a modal on submission, but not leave the page.


    Are you looking for a way to submit the add to cart for with Javascript?

    You can get the current page from the URL with perch_get('page') and conditionally set the count:




    Shorthand:


    PHP
    1. perch_blog_custom([
    2. 'count' => (perch_get('page') > 1) ? 12 : 13,
    3. 'paginate' => true,
    4. ]);