Posts by hus_hmd

    While I certainly like to see people continue to use Perch, if you are looking for something similar to standard Perch (not Runway), I think Kirby (PHP) and Vapid (Node.js) are the closest in terms of concepts and workflow.

    Hi John,


    The perch:error tags are rendered when Perch performs server-side validation. So you have to submit the form with validation errors in order to see these error messages.


    The HTML5 browser validation typically catches missing required fields and invalid email addresses and prevent the submission. For testing add novalidate to your form tag to disable the browser validation:


    HTML
    1. <perch:form id="contact" method="post" app="perch_forms" novalidate></perch:form>

    Hi drewm


    At the moment entering whitespace into a required field passes PerchAPI_SubmittedForm validation. While I realise this matches the HTML5 built-in validation, I think allowing whitespace-only values is rarely desirable. It would be great if the validation for required fields is stricter by default, or at least if we had an option to turn on stricter validation.

    Hi drewm


    I think being able to use PerchFactory::get_filtered_listing() for admin listings would make it easier for app developers to build more complex filterable admin lists where PerchFactory::get_by() isn't enough.


    For non-paginated lists, the method works fine:

    PHP
    1. $items = $Factory->get_filtered_listing(['skip-template' => true]);
    2. echo $AdminListing->render( $Factory->return_instances($items) );


    However, it is trickier to implement paginated lists this way given PerchAdminListing requires a PerchPaging instance for pagination. It would be nice to be able to pass a PerchPaging instance to get_filtered_listing(). Perhaps with an additional parameter:


    PHP
    1. $items = $Factory->get_filtered_listing(['skip-template' => true], $where_callback, $pre_template_callback, $Paging);


    Or by using the existing paginate option:


    PHP
    1. $items = $Factory->get_filtered_listing([
    2. 'skip-template' => true,
    3. 'paginate' => $Paging,
    4. ]);

    It is worth noting that using a cart system does not mean the user has to pay for the items online. If you have a catalogue of items that you want the user to browse and select to enquire about, using a cart system sounds reasonable.

    But how to I add tags to post.html

    They are not included by default. You can include them with the each option:


    PHP
    1. perch_blog_custom([
    2. 'template' => 'post.html',
    3. 'filter' => 'postSlug',
    4. 'value' => perch_get('s'),
    5. 'count' => 1,
    6. 'each' => function($item) {
    7. $item['tags'] = perch_blog_post_tags($item['postSlug'], 'post_tag_link.html', true);
    8. return $item;
    9. },
    10. ]);


    And in your template:


    HTML
    1. <perch:blog id="tags" html>




    or edit the ones attached to my existing posts?

    In the edit form on the control panel, they should be listed under the "Meta and Social" tab

    One option is to filter the results inside the template with perch:if tags. While this is perhaps the easiest approach, it doesn't work well with pagination (number of results per page is inconsistent) and you cannot easily output a no results message.



    An alternative approach would be to fetch all search results, skip the templating and filter in PHP:


    PHP
    1. $search_items = perch_content_search(perch_get('q'), [
    2. 'skip-template' => true,
    3. 'count' => null,
    4. ]);
    5. // filter $search_items


    Then you can render a template using perch_template() (or pipit_template() if you need pagination).

    Hi,


    Perch-templated forms have conditional tags for errors (perch:error), you may be able to use them directly on perch:input like this:


    HTML
    1. <perch:input id="first_name" type="text" required <perch:error for="first_name" type="required>aria-invalid="true"</perch:error> >


    Although this is not very practical if the field has more than multiple validation criteria:


    HTML
    1. <perch:input id="email" type="email" required
    2. <perch:error for="email" type="required">aria-invalid="true"</perch:error>
    3. <perch:error for="email" type="format">aria-invalid="true"</perch:error>
    4. >


    If you are using the Pipit app, you can use pipit_form_set_error_vars() so you can use a single perch:if:


    HTML
    1. <perch:form id="comment" method="post" app="perch_blog">
    2. <perch:input id="commentEmail" type="email" required <perch:if exists="comment_error_commentEmail">aria-invalid="true"</perch:if> >
    3. <perch:form>



    I don't think Perch expects tags to be used alongside attributes like that which may prevents it from reading all the perch:input tag attributes when validating the submission. So ensure the conditional tags perch:error or perch:if are added at the end (after all the other perch:input tag attributes).

    Hello Tony,


    If your store only accepts payments in one currency, you can hardcode it. Alternatively, you can use the each option to get the currency symbol for each order in the list:




    And in your template you can use currencySymbol:


    HTML
    1. <perch:shop id="currencySymbol"><perch:shop id="orderTotal">

    Nevermind, in this instance keeping multiple forms will be a frustration but manageable.

    You don't need multiple forms. You can add a hidden field to the form:


    HTML
    1. <perch:input id="r" type="hidden">


    You can dynamically populate this field in 2 ways:


    (1) Add a URL query parameter to your URL /account?r=/checkout

    (2) OR pass a variable in PHP to the template engine:

    PHP
    1. PerchSystem::set_var('r', '/checkout');



    And at the top of the page you can redirect:


    PHP
    1. if(perch_member_logged_in() && perch_post('cms-form') && perch_post('r')) {
    2. PerchSystem::redirect(perch_post('r'));
    3. }

    Hi Tony,


    The next attribute is not a valid attribute for <form> in HTML5. Perch only keeps valid attributes and strips the rest.


    The next attribute is actually a Perch tag attribute (like app) that gets stripped when the form is rendered. Some apps like Perch Members and Perch Shop use the next attribute to redirect upon a successful submission. The next attribute cannot have a dynamic value.

    In a master template you would normally include both if you want to add default settings to the region (e.g. template, is it a shared region, is it a multiple-item region, etc). This way the editor does not have to manually configure the region themselves every time they create a new page.



    PHP
    1. perch_content_create('Blocks', ['template' => 'blocks.html']);
    2. perch_content('Blocks');


    A multiple item-region:




    And you can stick all your perch_content_create()s at the top of the page if you prefer: