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
Heres the controller:
and finally heres db.xml:
Thanks for your time!
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">
Viewing 15 lines of 25 lines. View entire code block.
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;
Viewing 15 lines of 28 lines. View entire code block.
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>
Viewing 15 lines of 23 lines. View entire code block.
Thanks for your time!
@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!
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!
Your error message could have included the properties you were trying for, to give you a more complete picture:
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.
When working from within an action_, try the following for your block's properties:
For defined variables, you may need to use the get method.
This should get you started toward testing your submission and updating, please make it known if this has solved the problem.