Hello..
I am new to PHP and I was hoping someone could help me determine what the best way to go about creating a reusable view would be. What I have is a form that will be used to Add or Edit data. Therefore the view will be identical except in the case of an Edit the form fields will be populated.
So I am creating an HTML helper that takes 2 parameters. The first will be form data (if there is any{edit}) and the second will be a bool that flags whether this is an insert or and edit(to change form action).
My question is... how should I handle the first parameter if the form is to used to Add data and therefore does not contain data? Optional parameter?
EDIT--
I am using CodeIgnitor as my MVC framework. That is what those form functions are being inherited.. fyi
Thanks..
<?php
if(!defined('BASEPATH') ) exit('No direct script access allowed');
if(!function_exists('WorkOrderForm'))
{
function WorkOrderForm($array = array('$query'),$edit)
{
$formHtml = "";
$attributes = array('class'=>'order','id'=>'orderForm');
if($edit)
{
$formHtml += form_open('order/update',$attributes);
}
else
{
$formHtml += form_open('order/add',$attributes);
}
$formHtml += form_input('name',$query[0]->name);
$formHtml += form_textarea('name',$query[0]->description);
$dropOptions = array('nstarted'=>'Not Started','complete'=>'Done','started'=>'In Progress');
$formHtml += form_dropdown('status',$dropOptions,$query[0]->status);
$formHtml += form_input('name',$query[0]->startDate);
$formHtml += form_input('name',$query[0]->endDate);
$formHtml += form_close();
return $formHtml;
}
}
?>