Form block method action_submit_form wont properly submit the form...

Permalink
While I'm not new to programming I am new the MVC model, so please forgive any obviously incorrect things.
With that being said Im attempting to create a block that adds hyperlinks to a database. Unfortunately, my action_submit_form method is not working properly and I am unable to figure out why.
heres: view.php
<?php defined('C5_EXECUTE') or die("Access Denied.");
$form=Loader::helper('form');
$myForm=$controller;
?>
<div class="entry_box">
<p><?php echo $linkGroupName.'-'.$bID?></p>
<br>
<?php  if ($invalidIP) { ?>
<div class="ccm-error"><p><?php echo $invalidIP?></p></div>
<?php  } ?>
<?php if (isset($response)) { ?>
   <?php echo $response?>
<?php  } ?>
<form class="addLinkView" method="post" action="<?php  echo $this->action('submit_form')?>">
<div class="linkName">


Heres the controller:
<?php
   class BasicTestCopyFormBlockController extends BlockController {
      //var $pobj;
      protected $btDescription = "A simple form that adds a link to a db.";
      protected $btName = "Basic Test Copy Form";
      protected $btTable = 'btBasicTestCopyForm';
      public $btBasicTestCopyLinkTableName = 'btBasicTestCopyFormLinkTable';
      protected $btInterfaceWidth = "350";
      protected $btInterfaceHeight = "300";
   }
   function action_submit_form() {
      $this->set('response', t('Thanks!'));   
      $db = Loader::db();   
      $linkname=$_POST['linkname'];
      $groupID=$bID;


and finally heres db.xml:
<?xml version="1.0"?>
<schema version="0.3">
   <table name="btBasicTestCopyForm">
      <field name="bID" type="I">
         <key />
         <unsigned />
      </field>
      <field name="linkGroupName" type="C" size="30">
      </field>      
   </table>
   <table name="btBasicTestCopyFormLinkTable">
      <field name="lid" type="I">
         <key />
         <unsigned />
      </field>


Thanks for your time!

 
joseajohnson replied on at Permalink Reply
joseajohnson
From the bottom up:

Your error message could have included the properties you were trying for, to give you a more complete picture:

throw new Exception(t("Oops, something is wrong with the form you posted." . " name =  " . $linkname . " ; url = " . $url . " ; bID = " . $groupID));


This inclusion would have gone a long way in helping you diagnose the issue.

Assigning the value of an object's property to a local var is great, but only if you use it; using the $groupID to test would be more useful if you have plans for it later.

if($groupID==0)


When working from within an action_, try the following for your block's properties:

$groupID=$this->bID;


For defined variables, you may need to use the get method.

$myVar=$this->get('myVar');


This should get you started toward testing your submission and updating, please make it known if this has solved the problem.
jordanlev replied on at Permalink Reply
jordanlev
@joseajohnson has a great response.
You also might be interested in looking through this sample boilerplate code I have for a contact form block:
https://github.com/jordanlev/c5_custom_contact_form...

Note that things get a bit confusing when you have a form that allows people viewing the page to submit data (e.g. a contact form in my example or link url's in your example), because now the block actually has TWO parallel MVC things going on -- one for the site admin who is adding/editing the block, and another for people viewing the page and submitting the front-end form.

Good luck!