Viewing 10 reply threads
  • Author
    Posts
    • #6043
      digger149
      Member

      Hello,

      I am trying to build a simple ticketing system in Piklist. In simple terms, I have:

      price per ticket – currently set to a default value, will be sent to the form
      Select Quantity – 1,2 or 3
      Update Total Cost based on price * quantity
      I have been trying dozens of different methods, but I cannot figure out how to set $price in the code below:

      piklist('field', array( 'type' => 'text'
      
       ,'field' => 'price'
      , 'value' => '20'
      ,'label' =>'price'
      
       )) ;
      
        piklist('field', array(
          'type' => 'select'
          ,'field' => 'master_field'
          ,'label' => 'Master field'
          ,'choices' => array(
            '1' => '1'
            ,'2' => '2'
             ,'3' => '3'
          )
          ,'conditions' => array(
            array(
              'type' => 'update'
              ,'value' => '1'
              ,'field' => 'my_field'
              ,'update' => 1*$price
            )
            ,array(
               'type' => 'update'
              ,'value' => '2'
              ,'field' => 'my_field'
              ,'update' => 2*$price
            )
             ,array(
               'type' => 'update'
              ,'value' => '3'
              ,'field' => 'my_field'
              ,'update' => 3*$price
            )
          )
        ));
      
        piklist('field', array(
          'type' => 'text'
          ,'field' => 'my_field'
          ,'label' => 'Show/Hide Field'
          ,'value' => 1 * $price
          ,'description' => 'This field is updated by the Select field above'
        ));
    • #6053
      Steve
      Keymaster

      @digger149

      Your code works for me if I add this at the top to define the price.

      $price = '20';

    • #6060
      jrcreative
      Member

      That works globally, but it doesn’t allow you to change the price per post.

      It seems like you’d want to do something like:

      $price = get_post_meta(get_the_ID(), 'price', true)

    • #6062
      digger149
      Member

      Thanks, but

      It works if I say:
      $price = '20';

      but it doesn’t (it returns zero) if I say:
      $price = get_post_meta(get_the_ID(), 'price', true)

      The price of the ticket can vary, so it is a variable field in the form

    • #6063
      digger149
      Member

      On further investigation, I wanted to check out bits of the functionality

      If I use
      $price = get_the_ID();
      It correctly finds the PostID and multiplies it, its is just not picking up the meta value for ‘price’

    • #6065
      Steve
      Keymaster

      @digger149get_post_meta() works once the post is saved and the page refreshes.

      You may want to divide this up into Workflow tabs. The first tab can be your price field, and the second tab can be the calculation.

    • #6071
      digger149
      Member

      Yep, that was it – you need to save (update) the form before you can use the variables.

      Can anyone think of a way round this?

    • #6081
      jrcreative
      Member

      It’ll be a javascript or AJAX solution if you want real time data-binding.

    • #6090
      digger149
      Member

      Hi Steve

      I’m struggling with how to get workflows on front end forms – is it possible?

      Cheers
      Ian

    • #6096
      Steve
      Keymaster

      @digger149– Sorry, Workflows are an admin only feature right now.

    • #6097
      digger149
      Member

      Would be great on the front-end as well.

      Oh well, I will have to get my Jquery toolbox out

      Many thanks for your help

Viewing 10 reply threads
  • You must be logged in to reply to this topic.