Help about how to use external form and store form data in c5 db

Permalink
I wish to *coding* a simple contact form where user can insert name, date of birth (using a date picker) and other stuff using the concrete5 widget, then validate this form and save the form data such as the simple form add-on way . In other word I wish to see and export data in dashboard --> Reports --> Result Form

I tried in the MVC way starting with this examplehttp://www.concrete5.org/documentation/how-tos/shopping_cart_tutori... renaming the various cart.php to pippo.php then pointing tohttp://127.0.0.1/concrete5/index.php/pippo... but I’ve got the following error,

cart = new PippoModel(); $this->set('items', $this->cart->get()); } public function add() { $productID = $this->post('productID'); $this->cart->add($productID); $this->set('message', 'Product added successfully.'); } public function remove($productID) { $this->cart->remove($productID); $this->set('message', 'Product removed successfully.'); } } 
Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\xampp-win32-1.7.3\xampp\htdocs\concrete5\controllers\pippo.php:26) in C:\Programmi\xampp-win32-1.7.3\xampp\htdocs\concrete5\concrete\libraries\view.php on line 758


looking at the attached files you will find screenshot and the three files in one .txt file and relative path of them.
Does anybody have some idea to solve this problem or some block to install, some snip of code to use as starting point. If is possible even with the save method to store data into db.

My C5 version is the 5.4.1 the the last one

I hope is not depending by a bracket
Thanks in advance
Giovanni

2 Attachments

iddue
 
jordanlev replied on at Permalink Reply
jordanlev
I don't see anything in your code that would obviously cause that error.
You might want to check and make sure there are no spaces before the opening "<?php" tags in each file -- sometimes if there are spaces before those it can cause this error.
iddue replied on at Permalink Reply
iddue
I've check it but the problem still continue ... it's quite strange coz it come from a cut&paste example I've just use it and add pippo in the dashboard -->pages and themes -->single pages with path /pippo

BTW Thanks for your support
iddue replied on at Permalink Best Answer Reply 1 Attachment
iddue
Finally uff...
the example at link above was not correct
put your model
<?php 
defined('C5_EXECUTE') or die(_("Access Denied."));
class PippoModel {
    /** 
     * Returns the total number of items in the 
        user's cart
     */
    public function getTotal() {
        return count($_SESSION['cart']);
    }
    /** 
     * Gets the contents of our cart, in a list of IDs
     */
    public function get() {
        return $_SESSION['cart'];

under this path
\htdocs\concrete5\concrete\models\custom\pippo.php

puth your controller
<?php  
Loader::model('custom/pippo'); 
class PippoController extends Controller {
    private $cart;
    public function on_start() {
        $this->cart = new PippoModel();
        $this->set('items', $this->cart->get());
    }
    public function add() {
        $productID = $this->post('productID');
        $this->cart->add($productID);
        $this->set('message', 
              'Product added successfully.');
        $this->set('items', $this->cart->get());       
    }

under \htdocs\concrete5\concrete\controllers\pippo.php

Put your single_page
<?php
Loader::model('custom/pippo'); 
if (isset($message)) {
    print $message . '<br><br>';
}
$cart = new PippoModel();
 foreach($items as $it) { 
    echo 'Product ID '.$it.' in the cart   <a href="'.$this->action('remove', $it).'">Remove product</a><p></p>';
 } 
 echo "Total ".$cart->getTotal();
echo "<h2>Add a Product</h2>".$total;
?>
<form method="post"   action="<?php echo $this->url('pippo', 'add')?>">
  Enter the product ID:
<input type="text" name="productID" value="" />

under \htdocs\concrete5\single_pages\pippo.php

Add single page in dashboard--> pages and theme --> single pages and try it
poinging athttp://127.0.0.1/concrete5/index.php/pippo/...

Be care to spaces and/or empyty lines at the beginning of each file to avoid "header already sent " errors

attached the three files in one .txt file

I hope it can be a good starting point with MVC under C5
Enjoy !