Dependent dropdown is not showing selected value when update - php

I am new to yii. I have a dependent dropdown, my problem is that in dependent dropdown when someone is editing, while editing the dropdown is not automatically selected.
Here is my form code:
<div class="row">
<?php
Yii::app()->clientScript->registerScript('courseDropdown','jQuery(function($) {
$("#Subject_Subjectid").trigger("change");
$("#Subjectcourse_CourseId").val(\''.$model->CourseId.'\');
});
');//write this code on _form.php file
?>
<?php echo $form->labelEx($model,'Subjectid'); ?>
<?php
$sub = CHtml::listData(Subject::model()->findAll(array("condition"=>"School_Id='$School' and Status=1")),'Subjectid','SubjectName');
echo CHtml::activeDropDownList($model,'Subjectid',CHtml::listData(Subject::model()->findAll(array("condition"=>"School_Id='$School' and Status=1")),'Subjectid','SubjectName'),
array(
'empty'=>'--Select a Subject--',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Timetable/subjectid'), //url to call.
'data'=>array('Subjectid'=>'js: $(this).val()'),
'update'=>'#CourseId', //selector to update
)));
echo $form->error($model,'Subjectid');
echo $form->labelEx($model,'CourseId');
echo CHtml::dropDownList('CourseId','', array(), array('empty' => '-- Select a Course --'));
echo $form->error($model,'CourseId');
?>
</div>
This is my controller action
public function actionSubjectid()
{
$SchoolId=Yii::app()->session['Schoolid'];
$subjectid=$_POST['Subjectid'];
$subject = Subject::model()->findByPk($subjectid);
$data = Subjectcourse::model()->findAll(array("order"=>"CourseName ASC", "select"=>"CourseId,CourseName","condition" => "SubjectId='$subjectid' AND Status=1 AND School_Id='$SchoolId'"));
$data=array('empty'=>'-- Select a Course --') +CHtml::listData($data,'CourseId','CourseName');
foreach($data as $value=>$name)
{
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);
}
}
This is my action update
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Timetable']))
{
$model->attributes=$_POST['Timetable'];
$model->School_Id=Yii::app()->session['Schoolid'];
$CourseId=$_POST['CourseId'];
if($CourseId=="empty")
$model->CourseId='';
else
$model->CourseId=$_POST['CourseId'];
$model->Status=1;
if($model->save())
$this->redirect(array('view','id'=>$model->Id));
}
$this->render('update',array(
'model'=>$model,
));
}

As your second drop down will only work when a change event occurs in your first drop down, you can trigger this event when the page loads, something like this:
<?php
Yii::app()->clientScript->registerScript('courseDropdown','jQuery(function($) {
$("#Subject_Subjectid").trigger("change");
$("#Subjectcourse_CourseId").val(\''.$model->CourseId.'\');
});
');//write this code on _form.php file
?>
Edit: Alternatively, you could populate the second dropdown by querying data from the value of first dropdown:
if(!$model->isNewRecord) {
$courseArr = Chtml::listData(Subjectcourse::model()->findAllByAttributes(array('SubjectId'=>$model->Subjectid)), 'CourseId','CourseName'); //your query, modify according to need
} else {
$courseArr = array();
}
echo $form->labelEx($model,'CourseId');
echo CHtml::dropDownList('CourseId','', $courseArr, array('empty' => '-- Select a Course --'));
echo $form->error($model,'CourseId');

Related

Yii 1.1.19 Join Table Update not working fully

The Problem: If I select the new checkbox, it will update the data, but when I unchecked all the existing checkbox, it is not working. Even when I unchecked multiple checkboxes and leave one, it still works. Just not working when I select all unchecked checkbox to update data. Any suggestion would be greatly appreciated
This is my model that I am using get join table ID:
public function getProfileCampaigns($campaignIds = true) {
$campaignData = array();
$campaignProfiles = Yii::app()->db->createCommand()->select('campaign_id')
->from('campaign_profiles')
->where('profile_id = :profile_id',array(':profile_id' => $this->profile_id))
->queryAll();
// Check if need to send only campaign ids
if ($campaignIds) {
foreach ($campaignProfiles as $campaignProfile) {
$campaignData[] = $campaignProfile['campaign_id'];
}
}
return $campaignData;
}
This my controller for update action:
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$model->setScenario(Profile::SCENARIO_UPDATE);
// Get active campaigns
$campaigns = Campaign::model()->findAll();
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
// Check if profile have any releated profile
$model->campaignIds = $model->getProfileCampaigns();
if(isset($_POST['Profile']))
{
$model->attributes=$_POST['Profile'];
if($model->validate()) {
$model->save();
// Check if any campaign choosed
if ($_POST['Profile']['campaignIds']) {
Yii::app()->db->createCommand()->delete('campaign_profiles', 'profile_id = :profile_id', array(':profile_id' => $model->profile_id));
foreach ($_POST['Profile']['campaignIds'] as $campaignId) {
$campaignProfile = new CampaignProfile();
$campaignProfile->setIsNewRecord(true);
$campaignProfile->campaign_id = $campaignId;
$campaignProfile->profile_id = $model->profile_id;
$campaignProfile->save();
}
Yii::app()->user->setFlash('success', 'The Profile was successfully updated.');
$this->redirect(array('update','id'=>$model->profile_id));
}
}
}
$this->render('update',array(
'model' => $model,
'campaignListData' =>$campaigns,
));
}
This is form for getting checkbox select for update:
<div class="form-group">
<?php echo $form->labelEx($model,'campaignIds'); ?>
<div class="col-sm-9">
<?php echo $form->checkBoxList($model, 'campaignIds', CHtml::listData($campaignListData, 'id', 'name')); ?>
<?php echo $form->error($model,'campaignIds'); ?>
</div>
</div>
That is because only selected checboxes are send as form data. When no checkbox is checked, no data is sent, so probably default/old value from model is used.
You may use uncheckValue setting to define default value which will be send, when no checkbox is checked:
<div class="form-group">
<?php echo $form->labelEx($model,'campaignIds'); ?>
<div class="col-sm-9">
<?php echo $form->checkBoxList(
$model,
'campaignIds',
CHtml::listData($campaignListData, 'id', 'name'),
['uncheckValue' => '']
); ?>
<?php echo $form->error($model,'campaignIds'); ?>
</div>
</div>
Since 1.1.7, a special option named 'uncheckValue' is available. It can be used to set the value that will be returned when the checkbox is not checked. By default, this value is ''. Internally, a hidden field is rendered so when the checkbox is not checked, we can still obtain the value. If 'uncheckValue' is set to NULL, there will be no hidden field rendered.
https://www.yiiframework.com/doc/api/1.1/CHtml#activeCheckBoxList-detail

Yii dropdown with AJAX not working as expected

I have the following view named 'findreseller.php':
<?php
$countries = CHtml::listData(Country::model()->findAll(), 'id', 'name');
echo CHtml::dropdownlist('find_reseller', '', $countries,
array('ajax'=>array(
'type'=>'POST',
'url'=>Yii::app()->getController()->createAbsoluteUrl('/webcare/reseller/loadAjaxData'),
'update' =>'#data',
)
)
);
?>
<div id="data">
<?php $this->renderPartial('_ajaxContent', array('dataProvider'=>$dataProvider))?>
</div>
_ajaxContent just echoes the result, nothing special there...
The dropdown, as you can see is generated with CHtml because I dont't need a form. I just need an onChange event to do something...
As per the code that follows, in '/webcare/reseller/loadAjaxData' I have:
public function actionLoadAjaxData() {
$country = $_POST['find_reseller'];
//do something...
$dataProvider=new CArrayDataProvider($country_reseller);
$this->render('findreseller', array('dataProvider' => $dataProvider));
}
I can tell that I am missing something, but I am not sure what exactly.
Edit
Modified like this:
<?php
//CHtml::form();
$countries = CHtml::listData(Country::model()->findAll(), 'id', 'name');
echo CHtml::dropdownlist('find_reseller', '', $countries,
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('/webcare/reseller/loadAjaxData'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city_id', //selector to update
'data'=>'js: $(this).val()',
//leave out the data key to pass all form values through
)
)
);
//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('city_id','', array());
//CHtml::endForm();
?>
<div id="data">
<?php $this->renderPartial('_ajaxContent', array('dataProvider'=>$dataProvider))?>
</div>
And now I get:
http://prntscr.com/42wwx6
And I have the following controller action:
public function actionLoadAjaxData() {
$country = $_POST['country_id'];
...
$dataProvider=new CArrayDataProvider($country_reseller);
$data = User::model()->findAll('country_id=:country_id AND reseller=:reseller',
array(':country_id'=>(int) $_POST['country_id'], ':reseller'=>1));
$data=CHtml::listData($data,'city','city');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
$this->render('action_name', array('dataProvider' => $dataProvider));
}
Edit 2
If I write a die in actionLoadAjaxData(), right at the beginning, the method is loaded fine, the action is ok and the server answers 200.

Passing PHP Variable to controller and get it back

I have a variable and I want to update the value in the controller and render a part of the page based on the value.
This works very well in the first time but the variable doesn't get the value, stay with the first. Here my code:
Model:
public function actionCreate()
{
$model=new CadTeste;
$teste=1;
if(isset($_POST['CadTeste']))
{
$model->attributes=$_POST['CadTeste'];
if($model->save())
$this->redirect(array('view','id'=>$model->icd_teste));
}
$this->render('create',array(
'model'=>$model,
'teste'=>$teste,
));
}
Form:
<div id="data">
<?php $this->renderPartial('_ajaxContent', array('teste'=>$teste)); ?>
</div>
<?php
echo CHtml::ajaxSubmitButton('Alterar Num',CController::createUrl('CadTeste/UpdateAjax'),
array('type'=>'POST',
'data' => array('teste'=> $teste),
'update' => '#data'
)
); ?>
The Controler
public function actionUpdateAjax()
{
$teste = $_POST['teste'];
$teste += 10;
$this->renderPartial('_ajaxContent', array('teste'=>$teste), false, true);
}
And the _ajaxContent
<?php echo $teste; ?>
Every time I click on the button I get the value "11" instead of "11, 21, 31, 41".
How can I do that? Should I change the value every time in the controller?
Try Using Sessions . This Works for me
View File
<?php Yii::app()->session['teste']=$teste ?>
<div id='data'>
<?php $this->renderPartial('_ajaxContent', array('teste'=>$teste)); ?>
</div>
<?php
echo CHtml::ajaxSubmitButton('Alterar Num',$this->createUrl('CadTeste/UpdateAjax'),
array('type'=>'POST',
// 'data' => array('teste'=> $teste),
'update' => '#data'
)
); ?>
Your Controller
public function actionUpdateAjax()
{
$teste = Yii::app()->session['teste'];
$teste += 10;
$this->renderPartial('_ajaxContent', array('teste'=>$teste));
unset(Yii::app()->session['teste']);
Yii::app()->session['teste']=$teste;
}
And Your Model As it Is
public function actionCreate()
{
$model=new CadTeste;
$teste=1;
if(isset($_POST['CadTeste']))
{
$model->attributes=$_POST['CadTeste'];
if($model->save())
$this->redirect(array('view','id'=>$model->icd_teste));
}
$this->render('create',array(
'model'=>$model,
'teste'=>$teste,
));
}
Not sure if this is your problem, but renderPartial() does not play well with AJAX. It is a known Yii issue:
http://www.yiiframework.com/forum/index.php/topic/24699-yii-20-ajaxrenderpartial-conflict/
Try using this for the view:
<?php
echo CHtml::ajaxSubmitButton('Alterar Num',CController::createUrl('CadTeste/UpdateAjax',array('teste'=>$teste)),
array('type'=>'POST',
'update' => '#data'
)
); ?>
This for the controller:
public function actionUpdateAjax($teste)
{
$teste += 10;
$this->renderPartial('_ajaxContent', array('teste'=>$teste));
}
This way you can POST to action/ajaxupdate/teste/1
Its called Parameter Binding, the parameter in $teste is populated automatically from the url, if it's not present, it will give you an error. (You could put a default value $teste=1 to make it optional)

Renderpartial() Don't Generate New Jquery Code For AjaxSubmitButton

There is two actions in the controller:
CProfile:
public function actionCProfile()
{
$model=$this->loadModel(Yii::app()->user->id);
$model->scenario = 'updateProfile';
$this->performAjaxValidation($model);
if(isset($_POST['User'])){
$model->attributes=$_POST['User'];
if($model->validate())
if($model->save()){
if(Yii::app()->request->isAjaxRequest)
Yii::app()->end('saved');
else{
Yii::app()->user->setFlash('status','saved');
}
}
if(Yii::app()->request->isAjaxRequest)
if(!$model->validate())
Yii::app()->end('!validate');
}
if(Yii::app()->request->isAjaxRequest)
$this->renderPartial('_cprofile',array('model'=>$model));
else
$this->render('update',array('model'=>$model,'form'=>'_cprofile'));
}
And CPass:
public function actionCPass()
{
$model = $this->loadModel(Yii::app()->user->id);
$model->scenario = 'CPass';
$this->performAjaxValidation($model);
if(isset($_POST['User'])){
$model->attributes = $_POST['User'];
if($model->validate()){
if($model->verifyPassword($model->currentPass)){
$model->changePassword($model->newPass);
Yii::app()->end('changed');
}
}
}
if(Yii::app()->request->isAjaxRequest)
$this->renderPartial('_cpass',array('model'=>$model));
else
$this->render('update',array('model'=>$model,'form'=>'_cpass'));
}
And three view files:
update.php:
<?php
$cs = Yii::app()->clientScript;
$cs->registerCssFile('/x/css/myDetailview.css');
$cs->registerCssFile('/x/css/upanel/user-profile.css');
$url = Yii::app()->getBaseUrl().'/js/upanel.js';
$cs->registerScriptFile($url,CClientScript::POS_HEAD);
?>
<div id='user-profile-menu'>
<ul>
<li><?php echo CHtml::link('profile',Yii::app()->createUrl('/upanel/user/CProfile'),array('id'=>'profile-change-link')) ?></li>
<li><?php echo CHtml::link('change email',Yii::app()->createUrl('/upanel/user/CPass'),array('id'=>'pass-change-link')) ?></li>
</ul>
</div>
<div id='container'>
<?php $this->renderPartial($form,array('model'=>$model)); ?>
</div>
_cprofile.php:
<div class="form" >
<?php
$form = $this->beginWidget('CActiveForm',array(
'id'=>'change-profile-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'action' => 'index.php?r=upanel/user/cprofile',
'method' => 'post',
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>false,
),
));
?>
.
.
.
<div class="row">
<?php
$url=Yii::app()->createUrl('upanel/user/CProfile');
echo CHtml::ajaxSubmitButton('update',$url,
array(
'type'=>'POST',
'data'=>"js:$('#change-profile-form').serialize()",
'success'=>'callback',
'beforeSend'=>'before',
),
array(
'id'=>'update-button',
'class'=>'submit-button',
)
);
?>
</div>
<?php $this->endWidget() ?>
<?php echo $form->errorSummary($model,'resolve following errors: ') ?>
_cpass.php:
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm',array(
'id'=>'change-pass-form',
'enableAjaxValidation' => 'true',
'action' => Yii::app()->createUrl('upanel/user/CPass'),
'method' => 'POST',
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => true,
'validateOnType' => false,
)
));
?>
.
.
.
<div class="row">
<?php
$url=Yii::app()->createUrl('upanel/user/CPass');
echo CHtml::ajaxSubmitButton('update',$url,
array(
'type'=>'POST',
'data'=>"js:$('#change-pass-form').serialize()",
'success'=>'callback',
'beforeSend'=>'before',
),
array(
'id'=>'update-button',
'class'=>'submit-button',
)
);
?>
</div>
<?php $this->endWidget() ?>
</div> <!-- End Password Form -->
<?php echo $form->errorSummary($model) ?>
*Edit #1: *
See, i have a view page named update.php that in this page there is two links:
<div id='user-profile-menu'>
<ul>
<li><?php echo CHtml::link('profile',Yii::app()->createUrl('/upanel/user/CProfile'),array('id'=>'profile-change-link')) ?></li>
<li><?php echo CHtml::link('Change Password',Yii::app()->createUrl('/upanel/user/CPass'),array('id'=>'pass-change-link')) ?></li>
</ul>
The following JQuery code runs exsist actions in controller, that result is a renderpartial() one of these view files: _cpass.php or _profile.php
$('document').ready(function(){
$('#profile-change-link').click(function(){
var link = $(this).attr('href');
$('#container').load(link);
return false;
})
$('#pass-change-link').click(function(){
var link = $(this).attr('href');
$('#container').load(link);
return false;
})
});
In the controller CProfile action defined as default action. with this action there is no any problem in which of POST and Ajax methods.
But main problem: after that _cpass.php view replaced with _profile and have send the exist form in the _profile to CPass action for processing encountered with problem.
The problem is this:
Output of following code as expected is 1:
public function actionCPass()
{
$model = $this->loadModel(Yii::app()->user->id);
$model->scenario = 'CPass';
$this->performAjaxValidation($model);
if (1==1)
Yii::app()->end('1');
}
But output of following code is not that thing we expected. Returned value is a renderpartial() of _profile view. while there is no any related code about _cprofile view in CPass action code!
public function actionCPass()
{
$model = $this->loadModel(Yii::app()->user->id);
$model->scenario = 'CPass';
$this->performAjaxValidation($model);
if(isset($_POST['User'])){
$model->attributes = $_POST['User'];
if($model->validate()){
if($model->verifyPassword($model->currentPass)){
$model->changePassword($model->newPass);
Yii::app()->end('changed');
}
}
}
if(Yii::app()->request->isAjaxRequest)
$this->renderPartial('_cpass',array('model'=>$model));
else
$this->render('update',array('model'=>$model,'form'=>'_cpass'));
}
Output of above code:
<div class="form" >
<form id="change-profile-form" action="index.php?r=upanel/user/cprofile" method="post">
.
.
.
<div class="row">
<input id="update-button" class="submit-button" type="submit" name="yt0" value="update" /> </div>
</form>
</div> <!-- End The Profile Form -->
<div id="change-profile-form_es_" class="errorSummary" style="display:none">resole following errors:
<ul><li>dummy</li></ul></div>
Now understand what is the issue? The problem there is only with Ajax request and when disabled the javascript in the browser the CPass action acts truly.
Excuseme if firstly explained very bad.
Thanks friends
*Edit #2: *
When debugging with Firebug i noticed that snippet of JQuery code didn't change.
When firstly in default action of controller this code:
$this->renderPartial('_cprofile',array('model'=>$model));
be run following JQuery code will create: (As you know following code is related to CHtml::ajaxSubmitButton)
$('body').on('click','#update-button',function(){jQuery.ajax({'type':'POST','data':$('#change-profile-form').serialize(),'success':callback,'beforeSend':before,'url':'/x/index.php?r=upanel/user/CProfile','cache':false});return false;});
So when _cpass view renders with renderpartial() method in CPass action, the above JQuery code must be changed but will not change. I guess it must be the following code:
$('body').on('click','#update-button',function(){jQuery.ajax({'type':'POST','data':$('#change-cpass-form').serialize(),'success':callback,'beforeSend':before,'url':'/x/index.php?r=upanel/user/CPass','cache':false});return false;});
So my problem is with JQuery code generated for CHtml::ajaxSubmitButton. Can anyone help me?
Solved
With applying uniqueId for ajaxSubmitButton and setting CController::processOutput() to True in Controller Action solved.
Summary Code:
actionCPass:
public function actionCPass()
{
$model = $this->loadModel(Yii::app()->user->id);
$model->scenario = 'CPass';
$this->performAjaxValidation($model);
if(isset($_POST['User'])){
$model->attributes = $_POST['User'];
if($model->validate()){
if($model->verifyPassword($model->currentPass)){
$model->changePassword($model->newPass);
Yii::app()->end('changed');
}
}
}
if(Yii::app()->request->isAjaxRequest)
$this->renderPartial('_cpass',array('model'=>$model),false,true);
else
$this->render('update',array('model'=>$model,'form'=>'_cpass'));
}
_cpass.php:
.
.
.
<?php
echo CHtml::ajaxSubmitButton(
'update',
Yii::app()->createUrl('upanel/user/CPass'),
array(
'type'=>'POST',
'data'=>"js:$('#change-pass-form').serialize()",
'success'=>'callback',
'beforeSend'=>'before',
),
array(
'id'=>'update-button'.uniqid(),
'class'=>'submit-button',
)
);
.
.
.
?>
Rename one/both of your button ids. This means the event handlers will be attached to different buttons.
Use renderPartial('view.path',array(parameter_array),false,true); when returning a view via Ajax. The last parameter of CController::renderPartial() calls CController::processOutput() which inserts the required client scripts at appropriate places.
I think I understand your problem, you are wondering why the page does not have the surrounding <div id='profile-container'> and </div>.
I think this may have something to do with the render functions only being able to run once per view called (so it only renders the inside view), you can test this by removing the renderPartial from the update page and see if it prints the blank div.
One way you could get around this is to instead of doing the two renders, always call each page (even in the ajax requests) but pass an extra attribute if it was an ajax request. Then on each of the pages begin and end a custom widget that contains the surrounding template you want on those pages (or just write it in manually).
Example:
controller
public function actionCProfile()
{
// ... same as your example
if(Yii::app()->request->isAjaxRequest){
$this->renderPartial('_cprofile',array('model'=>$model, 'wasAjax'=>false));
} else {
$this->renderPartial('_cprofile',array('model'=>$model, 'wasAjax'=>true));
}
}
then in your view just check if wasAjax is true, if it is then print the surrounding div (or extra elements). If this is big or could change later on, put it in a custom widget.

Codeigniter update form

I'm really new to CI and have been trying to create an update form class today, but I'm running into a dead end. I have my functions set up to create the form and publish the data to the database, I now need to be able to update this.
My edit form function is below:
public function edit_event()
{
$vars = array();
$data['form_url'] = $this->form_url;
if ($form_id = $this->EE->input->get('form_id'))
{
$data['form_id'] = $form_id;
}
return $this->EE->load->view('edit_event', $data, TRUE);
}
and the edit_event file loaded within the function is:
<?php
$this->EE=& get_instance();
$this->load->helper('form');
$attributes = array('class' => 'event_form', 'id' => 'my_event_form');
echo form_open($form_url.AMP.'method=update_form', $attributes);
$this->EE->load->library('table');
$this->EE->table->set_heading(
'Preference',
'Setting'
);
$query = $this->EE->db->query("SELECT * FROM exp_events WHERE id = '$form_id'");
foreach($query->result_array() as $row)
{
$this->EE->table->add_row(
form_label('Application Key', 'app_key'),
form_input('app_key',$row['app_key'])
);
$this->EE->table->add_row(
form_label('Access Token', 'access_token'),
form_input('access_token',$row['access_token'])
);
$this->EE->table->add_row(
form_label('User Key', 'user_key'),
form_input('user_key',$row['user_key'])
);
}
echo $this->EE->table->generate();
echo form_reset('reset', 'Clear Form');
echo form_submit('mysubmit', 'Submit Post!');
echo form_close();
?>
I then have my update form function:
public function update_form()
{
$form_id = $this->EE->input->get('form_id');
$data['form_id'] = $form_id;
$form_data = array(
'app_key' => $this->EE->input->post('app_key'),
'access_token' => $this->EE->input->post('access_token'),
'user_key' => $this->EE->input->post('user_key')
);
$this->EE->db->where('id', $form_id);
$this->EE->db->update('exp_events', $form_data);
$this->EE->functions->redirect($this->base_url);
}
When removing the $form_if option I can get the data to update, but it updates for every single item in the database. I obviously need this to only update the data with the form id of the form being edited.
As it stands, when I submit the update form, I get redirected to my $base_url which is correct, but no data gets updated, therefore I am clearly doing something wrong when defining the form id?
As I said I'm new to this, so if anyone notices any preferred methods feel free to let me know :).
Any pointers appreciated.
Thanks in advance.
Ben
You need to include a 'hidden' field in your form, with the form_id. At the moment your 'form_id' is not part of your input, so when you go and get the form_id it is failing.
change
echo $this->EE->table->generate();
echo form_reset('reset', 'Clear Form');
echo form_submit('mysubmit', 'Submit Post!');
to
echo $this->EE->table->generate();
echo form_hidden('form_id', $form_id);
echo form_reset('reset', 'Clear Form');
echo form_submit('mysubmit', 'Submit Post!');

Categories