having problems figuring out the codes that needs to be in ADD CODE HERE

  • submissions - Holds the submitter’s name and email

    • products_ordered - Holds how much of each product the submitter ordered

    • The products are stored in a products table, but you shouldn’t need

    • anything from there to save. Here are the structure of all three tables:

    • submissions

    •  `id`			int				- Primary Key, auto-incrementing
      
    •  `first_name`	varchar(64)
      
    •  `last_name`		varchar(64)
      
    •  `email`			varchar(64)
      
    • products

    •  `id`			int				- Primary Key, auto-incrementing
      
    •  `name`			varchar(64)
      
    •  `price`			float
      
    • products_ordered

    •  `id_submissions`	int			- `submissions` table foreign key
      
    •  `id_products`		int			- `products` table foreign key 
      
    •  `quantity`			int			- # of product ordered by the submitter for this product
      
    •  `ordered_on`		timestamp	- timestamp
      
    • @param array $data prepared data to insert into the database

    • @return mixed TRUE if the save was successful otherwise an array of error messages.
      */
      function save($data) {

      // — ADD CODE HERE —

    }

    /**

    • Gets the product data from the DB

    • @return array 2-dimensional array of products data from the DB
      */
      function getProducts() {

      $rows = $this->db->query(‘SELECT * FROM products ORDER BY name ASC’);

      $return = array();
      while ($row = $rows->fetch_assoc()) {
      $return[] = $row;
      }
      return $return;

    }
    }

// ---------------------------------------------------------------
// There is one place in SimpleFormView that needs to be coded
// ---------------------------------------------------------------

/**

  • View class
    */
    class SimpleFormView
    {

    /**

    • Displays a template file to output buffer

    • @param string $tpl The file name of the template file to display

    • @param array $data any data that should be available to the template file being displayed

    • @return bool True if the template file was able to be read and outputted successfully
      */

      // Tip: The template files contain PHP code so they must be read
      // in a manner that evalutates/executes that code.
      // — ADD CODE HERE —

    }

    /**

    • Cleans _POST data and adds it to the POST key of the input array
    • this is used to auto-populate form fields when the form needs
    • to reload after an error. It’ll help prevent against JS injection
    • attacks.
    • @param array &$data
    • @return void
      */
      function addPost(&$data) {
      if(count($_POST)) {
      $data[‘POST’] = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
      } else {
      $data[‘POST’] = array(
      ‘first_name’ => ‘’,
      ‘last_name’ => ‘’,
      ‘email’ => ‘’,
      );
      }
      }
      }
      ?>

Duplicate post, original post didn’t have a question tied to it.

Sponsor our Newsletter | Privacy Policy | Terms of Service