Product Waitlist Form - Pass Slug or Product Title to a Form

  • Hi there,


    I'm trying to create a form for customers to leave their email and get notified when a certain product comes back in stock.


    The form sits in a `perch:layout`in `product.html`.


    The form collects the emails perfectly well, but I cannot get any product details, or page details to pass into the form.

    I would even settle for the URL the form was submitted on, as it would contain the slug.


    I've tried several things, including using

    Code
    1. <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />

    similar to passing the product ID to the cart.


    Any idea how I can get some page or product info into a form?


    Thank you!!


    -Olympia

  • drewm

    Approved the thread.
  • Perhaps you could set the product title for example as a variable. In your top layout you could add something like this:

    Code
    1. if (perch_layout_has('product')) {
    2. $product_data = perch_shop_product('', [
    3. 'skip-template' => true,
    4. 'filter' => 'slug',
    5. 'match' => 'eq',
    6. 'value' => perch_get('s'),
    7. ]);
    8. $product_title = $product_data[0]['title'];
    9. PerchSystem::set_var('product_title', $product_title);
    10. }

    On your product page you could add the product statement to your layout:

    Code
    1. perch_layout('top', array(
    2. 'product' => true,
    3. ));

    Then in your form template you can set the variable as the value:

    <perch:input id="product" type="hidden" value="<perch:shop id="product_title" type="hidden" />" />


    Note, this only works for templates which are parsed at runtime – such as content rendered with perch_content_custom() rather than the precompiled output from perch_content().