|
![Picture of Konrad Picture of Konrad](/graphics/unknown.gif) Konrad - 2007-05-15 17:39:51
I am having the following problem:
My data is drawn from the database and then put in the array. I want to use this data to PREPOPULATE the form. so that the user can then change the values of the data from they are, to what they should be.
I've tried to assing these values manually, but it doesn't seem to display them on the template
$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"company",
"ID"=>"company",
"MAXLENGTH"=>100,
"LABEL"=>"<u>C</u>ompany Name",
"VALUE"=>"blah"
));
$form->SetInputValue('company',"blah");
I'd much rather want to pass an array of values to the form object and just have them assigned.
Could you let me know how I should do this?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-05-15 18:15:30 - In reply to message 1 from Konrad
What kind of template system are you using? Are you using Smarty? If so, does it have content caching enabled?
![Picture of Konrad Picture of Konrad](/graphics/unknown.gif) Konrad - 2007-05-15 18:34:14 - In reply to message 2 from Manuel Lemos
I am not using Smarty, or any "system" for that matter. I basically wrote my own little framework that I use.
The field is being displayed, but there is no "value" in there, even when I look at the source code
this is the template code:
<tr>
<th align="right">
<?php $form->AddLabelPart(array("FOR"=>"company")); ?>:</th>
<td><?php $form->AddInputPart("company"); ?></td>
<td><?php echo (IsSet($verify["company"]) ? "[Verify]" : ""); ?></td>
</tr>
and here is the complete code for the page:
///////////////////////////////////////////////////
<?php
// UPDATE
$form=new FORM_CLASS;
$form->NAME="subscription_form";
$form->METHOD="POST";
$form->ACTION="";
$form->ResubmitConfirmMessage=
"Are you sure you want to submit this form again?";
$form->OutputPasswordValues=1;
$form->OptionsSeparator="<br />\n";
$form->ShowAllErrors=1;
$form->InvalidCLASS='invalid';
echo $GLOBALS['account']->account['company'];
$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"company",
"ID"=>"company",
"MAXLENGTH"=>100,
"LABEL"=>"<u>C</u>ompany Name",
"VALUE"=>$GLOBALS['account']->account['company']
));
$form->SetInputValue('company',"ok");
$form->AddInput(array(
"TYPE"=>"submit",
"ID"=>"button_subscribe",
"VALUE"=>"Submit subscription",
"ACCESSKEY"=>"u"
));
$form->AddInput(array(
"TYPE"=>"image",
"ID"=>"image_subscribe",
"SRC"=>"http://www.phpclasses.org/graphics/add.gif",
"ALT"=>"Submit subscription",
"STYLE"=>"border-width: 0px;"
));
$form->AddInput(array(
"TYPE"=>"hidden",
"NAME"=>"doit",
"VALUE"=>1
));
$form->AddInput(array(
"TYPE"=>"hidden",
"NAME"=>"user_track",
"VALUE"=>"0",
"ValidateAsInteger"=>1,
"DiscardInvalidValues"=>1
));
$form->LoadInputValues($form->WasSubmitted("doit"));
$verify=array();
// FORM WAS SUBMITED
if($form->WasSubmitted("doit"))
{
if(($error_message=$form->Validate($verify))=="")
{
$js = new JAVASCRIPT;
/*
if($GLOBALS['account']->account_update($_POST))
{
}
*/
echo $js->redirect($_POST['return_url']);
$doit=1;
}
else // ERRORS
{
$doit=0;
$error_message=nl2br(HtmlSpecialChars($error_message));
}
}
// FORM WAS NOT SUBMITED NO ERRORS OR PROCESSING
else
{
$error_message="";
$doit=0;
}
if($doit)
{
$form->ReadOnly=0;
}
if(!$doit)
{
if(strlen($error_message))
{
Reset($verify);
$focus=Key($verify);
}
else
{
$focus='company';
}
$form->ConnectFormToInput($focus, 'ONLOAD', 'Focus', array());
}
$form->StartLayoutCapture();
$title="Form class test";
$body_template="account_body.html.php";
require("account_frame.html.php");
$form->EndLayoutCapture();
$form->DisplayOutput();
?>
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-05-15 22:15:17 - In reply to message 3 from Konrad
It is hard to tell without seeing the whole script, but could you be passing the form object to a function on which you set the form input values?
If you do that you need to pass the object form by reference, or else you will be creating a copy of the object under PHP 4.x, instead of the object that you created originally.
|