Forum

Thread tagged as: Question, Shop

Perch Shop: Save and read back message textarea in cart

I am filling in a message on the cart page but the contents are empty when trying to read it back. What am am missing?

Template:

      <perch:form id="add_to_cart" app="perch_shop" > 
           <perch:input id="message" type="textarea" label="Message" rows="6" cols="40" cart-property="message" required="false" /><br />
           <perch:input type="submit" id="submit" value="Save comments" class="btn-primary btn" />
           </perch:form> 

Diagnostics:

    Perch: 3.0.8, PHP: 7.0.12, MySQL: 5.6.32-78.1, with PDO
    Server OS: Linux, cgi-fcgi
    Installed apps: content (3.0.8), assets (3.0.8), categories (3.0.8), perch_forms (1.9.1), perch_shop_orders (1.2.3), perch_shop_products (1.2.3), perch_shop (1.2.3), perch_members (1.6.2)
    App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_members', 'perch_shop', ); ?>
    PERCH_LOGINPATH: /perch
    PERCH_PATH: /home2/cookieg1/public_html/perch
    PERCH_CORE: /home2/cookieg1/public_html/perch/core
    PERCH_RESFILEPATH: /home2/cookieg1/public_html/perch/resources
    Image manipulation: GD Imagick
    PHP limits: Max upload 64M, Max POST 64M, Memory: 256M, Total max file upload: 64M
    F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
    Resource folder writeable: Yes
    DOCUMENT_ROOT: /home2/cookieg1/public_html
    HTTP_HOST: www.cookiegirlbakeshop.com
    REQUEST_URI: /perch/core/settings/diagnostics/
    SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Jerry White

Jerry White 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you doing to read it back?

if (perch_shop_cart_has_property('message')) perch_shop_cart('Message',[ 'message' => perch_get('message') ]);

Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you attempting to do with the below code? From my point of view it's nonsense:

perch_shop_cart('Message',[ 'message' => perch_get('message') ])

This is on the cart page to redisplay the text if it exists: if (perch_shop_cart_has_property('message')) perch_get('message');
perch_shop_cart([ 'template' => 'cart/message.html' ]);

This is on cart_static to display the text if it exists: if (perch_shop_cart_has_property('message')) perch_get('message');

The add-to-cart template for adding the textarea is above.

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_get() reads items from the URL. I think you want perch_shop_get_cart_property()

I am trying to display the value entered by the user in a textarea on the cart page.

The template cart/message.html: <perch:form id="add_to_cart" app="perch_shop"> <perch:input id="message" type="textarea" rows="6" cols="40" cart-property="message" required="false" /><br /> <perch:input type="submit" id="submit" value="Save comments" class="btn-primary btn" /> </perch:form>

perch_shop_get_cart_property() returns nothing, even if I set a value for perch:input directly in the template.

The following displays the set value in the template but doesn't save and redisplay a user-entered value. perch_shop_cart([ 'template' => 'cart/message.html' ]);

Both conditions if (perch_shop_cart_has_property('message', true)) and if (perch_shop_cart_has_property('message') always fail, even after entering content in the textarea and even after merely displaying the textarea in the template with the set value above.

Any suggestions?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does perch_shop_get_cart_property() return?

For: perch_shop_get_cart_property('message')

Using template: /templates/shop/cart/message.html
[1] SELECT cartProperties FROM perch3_shop_cart WHERE cartID=37
[1] SELECT cartProperties FROM perch3_shop_cart WHERE cartID=37
[1] SELECT cartProperties FROM perch3_shop_cart WHERE cartID=37

Array
(
    [type] => 8
    [message] => Undefined variable: prop
    [file] => /home2/cookieg1/public_html/perch/addons/apps/perch_shop/runtime/cart.php
    [line] => 44
)

For: perch_shop_get_cart_property() same diagnostic, but also a message on screen: Warning: Missing argument 1 for perch_shop_get_cart_property(), called in /home2/cookieg1/public_html/cart.php on line 52 and defined in /home2/cookieg1/public_html/perch/addons/apps/perch_shop/runtime/cart.php on line 41

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, it looks like the answer is no in that case.