Results 1 to 10 of 10
  1. #1
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Adding a message into the message stack

    I seem to recall doing this before but can't remember where or what mod might have had a sample of this.

    Just need an idea of how to add a message to the stack on the product_info page. Need to make the image upload required. I think I know how to write the code - just don't know where or how to add it in.

    Thanks for any responses!
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,872
    Plugin Contributions
    96

    Default Re: Adding a message into the message stack

    There are two methods. First, if the message is being displayed for the current page load
    Code:
    $messageStack->add('product_info', 'The message to be added');
    Secondly, if the message is to be displayed after a redirect:
    Code:
    $messageStack->add_session('product_info', 'The message to be added');
    The third parameter (severity) defaults to 'error' and can be set to 'warning', 'caution', or 'success' as well.
    Code:
    $messageStack->add_session('product_info', 'The message to be added', 'warning');

  3. #3
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Re: Adding a message into the message stack

    Okay, that's really easy and understandable.

    But I need a tad more info for my situation. You say that the default is error and I see that's the case when I set this up. But I need the error message to also prevent the user from going forward.

    I'm trying to tie an action to the choice of attributes on a product. The buyer has a choice of uploading an image or checking a checkbox that says they will send an image later. As one cannot make either a required field and it is an either/or situation, I think (I hope) I have the php code ready for that. But I need it to act as a required action. Here's the code I have so far:

    PHP Code:
    <?php if(isset($_POST['submit'])) {
     if ((!empty(
    $_POST['id[txt_6]'])) && (!empty($_POST['id[13][21]'])))
    {
        
    $messageStack->add('product_info''Please either upload a file or check the box that you will be sending a photo separately.');
    }
    }
        
    ?>
    <?php 
    if ($messageStack->size('product_info') > 0) echo $messageStack->output('product_info'); ?>
    This is actually something I've found that's been asked about often in the forum but I didn't find any instructions of how to make these types of fields required.
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  4. #4
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Adding a message into the message stack

    Quote Originally Posted by delia View Post
    Okay, that's really easy and understandable.

    But I need a tad more info for my situation. You say that the default is error and I see that's the case when I set this up. But I need the error message to also prevent the user from going forward.

    I'm trying to tie an action to the choice of attributes on a product. The buyer has a choice of uploading an image or checking a checkbox that says they will send an image later. As one cannot make either a required field and it is an either/or situation, I think (I hope) I have the php code ready for that. But I need it to act as a required action. Here's the code I have so far:

    PHP Code:
    <?php if(isset($_POST['submit'])) {
     if ((!empty(
    $_POST['id[txt_6]'])) && (!empty($_POST['id[13][21]'])))
    {
        
    $messageStack->add('product_info''Please either upload a file or check the box that you will be sending a photo separately.');
    }
    }
        
    ?>
    <?php 
    if ($messageStack->size('product_info') > 0) echo $messageStack->output('product_info'); ?>
    This is actually something I've found that's been asked about often in the forum but I didn't find any instructions of how to make these types of fields required.
    This code will post a message if there is information in both fields only, unless the information results in a value of 0 when evaluated by empty, at which point the message will not be displayed. Also, what is the expected/desired action if both are performed? Should it be allowed that an image be provided and submitted later (such as an additional image)? (Just verifying that the conditions have been considered.)
    As for the prevention of continuing, would need to evaluate (through the above code) what to do. Just providing the message is not sufficient to prevent continuation, but would need to have a redirect of some type to either go back or to stay on the same page based on where the form action takes the user. (Meaning, wherever the user is taken based on the form action is where the evaluation needs to take place and something done/set to prevent continuing on. Sorry haven't looked into the specific product_info collect_info/preview_info sections to identify the flow path. I guess I'm also considering these actions to be happening on the admin side, but seems that the usage is on the store side. Regardless, the troubleshooting/development process is the same with different files in question.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,872
    Plugin Contributions
    96

    Default Re: Adding a message into the message stack

    Quote Originally Posted by delia View Post
    Okay, that's really easy and understandable.

    But I need a tad more info for my situation. You say that the default is error and I see that's the case when I set this up. But I need the error message to also prevent the user from going forward.

    I'm trying to tie an action to the choice of attributes on a product. The buyer has a choice of uploading an image or checking a checkbox that says they will send an image later. As one cannot make either a required field and it is an either/or situation, I think (I hope) I have the php code ready for that. But I need it to act as a required action. Here's the code I have so far:

    PHP Code:
    <?php if(isset($_POST['submit'])) {
     if ((!empty(
    $_POST['id[txt_6]'])) && (!empty($_POST['id[13][21]'])))
    {
        
    $messageStack->add('product_info''Please either upload a file or check the box that you will be sending a photo separately.');
    }
    }
        
    ?>
    <?php 
    if ($messageStack->size('product_info') > 0) echo $messageStack->output('product_info'); ?>
    This is actually something I've found that's been asked about often in the forum but I didn't find any instructions of how to make these types of fields required.
    So, what you need is an "extra_cart_action" file (/includes/extra_cart_actions/check_attribute_requirements.php) that looks kind of like:
    Code:
    if (isset ($_GET['action']) && $_GET['action'] == 'add_product') {
      if(isset($_POST['submit'])) {
        if ((!empty($_POST['id[txt_6]'])) && (!empty($_POST['id[13][21]']))) {
    	$messageStack->add('product_info', 'Please either upload a file or check the box that you will be sending a photo separately.');
            $_GET['action'] = '';
        }
      }
    }
    That little bit of code will run whenever there's an "action" set and take action when there's an action=add_to_cart going on. If the condition you specified is found, a message is output to the product_info page and the action is reset so that the actual add-to-cart won't occur.

  6. #6
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Re: Adding a message into the message stack

    both good bits of info. lat9, I see exactly what you are talking about and am very grateful for this addition to my knowledge!

    mc12345678, thanks for looking at my code and pointing out the flaw. I knew something was not quite right there. Let's see if I can wrap my head around this!
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  7. #7
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Re: Adding a message into the message stack

    So I thought I was really close now.

    Here's the code and note if you've been following this thread, the if(isset($_POST['submit'])) is not required:
    PHP Code:
    if (isset ($_GET['action']) && $_GET['action'] == 'add_product') {
        if (empty(
    $_POST['id[13][21]'])) {
        
    $messageStack->add('product_info''Please either upload a file or check the box that you will be sending a photo separately.');
            
    $_GET['action'] = '';
        }

    So first question is the $_POST['id[13][21]'] correct based on the array?

    No matter what I can't add to cart. I swear this worked earlier today but after working on getting the file upload part to work, it definitely isn't working now. I hate to have to post simple php questions but dang it, I'm going around in circles and getting absolutely nowhere.

    The code for what I need should be something like this
    PHP Code:
    if (isset ($_GET['action']) && $_GET['action'] == 'add_product') {
     
    // if(isset($_POST['submit'])) {
        
    if (((!file_exists($_FILES['id[txt_6]']['tmp_name']) || !is_uploaded_file($_FILES['id[txt_6]']['tmp_name']))) && (!$_POST['id[13][21]'])) {
        
    $messageStack->add('product_info''Please either upload a file or check the box that you will be sending a photo separately.');
            
    $_GET['action'] = '';
        }
     
    // }

    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,872
    Plugin Contributions
    96

    Default Re: Adding a message into the message stack

    Quote Originally Posted by delia View Post
    So first question is the $_POST['id[13][21]'] correct based on the array?
    delia, I think that it should be
    Code:
    $_POST['id'][13] == 21
    The $_POST['id'] array is a single dimension array. I'm not sure exactly what you're trying to do but the code above is what you'd use in an if statement to see if option_id #13 was selected as option_value_id of 21.

  9. #9
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Re: Adding a message into the message stack

    Beautiful. So it was my php knowledge at fault! That actually makes me feel good. I'm not crazy after all. So then if I apply that to the files situation? $_FILES['[id][txt_6]' would be correct?

    You know the files are kinda odd. There is the input to upload a file and two hidden ones. The code is
    <input type="file" name="id[txt_6]" id="attrib-6-0" /><br />
    <input type="hidden" name="upload_1" value="6" />
    <input type="hidden" name="txt_upload_1" />

    That makes me think there's more going on than a normal file input. Nothing I've tried has worked with the files which makes me think there's something at work that I'm not seeing. What do you think?

    This is really good and I cannot thank you enough. I may well end up creating some type of mod or instructions for this. I now see why the required bit for everything besides text is not possible but there needs to be an organized way for file uploads or this kind of scenario where there are two separate attributes depend on each other.
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  10. #10
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Re: Adding a message into the message stack

    I did find a mod for requiring the file upload but it changes a number of core files and I'm trying to avoid this. Do you suppose it is possible?
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

 

 

Similar Threads

  1. v151 Add an error to the message stack for checkout shipping?
    By delia in forum General Questions
    Replies: 7
    Last Post: 10 Dec 2012, 02:55 PM
  2. what messages appear in the header message stack?
    By torvista in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 9 Dec 2010, 03:21 PM
  3. Add span class to the message stack text
    By LissaE in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 4 Mar 2010, 11:55 AM
  4. Message Stack Error - Changing the text
    By rkmoore11 in forum General Questions
    Replies: 2
    Last Post: 16 Sep 2007, 02:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg