Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
HTML Form problem in a bespoke admin tab in extensions
Hello
Help please,
I’m writing a plugin to allow me to add new members to a bespoke table.
I’ve registered the tab, callback, created the form all fine added some form validation again fine.
What I can’t seem to do is re-populate the form fields if the validation fails.
I’m using ps(‘submit’) to process the form.
I’m assigning the cleaned field values to variables which i’m trying put back into the value of fInput(.
The form is contained in the function foo($event, $step).
The ps(‘submit’) and validation are processed outside of the function foo($event, $step).
I’ve tried globals which don’t work so all I can assume it’s something about the way the callback function works.
I can get the variables to echo outside of the function foo($event, $step).
I hope the above is clear.
Thanks in advance
Forever learning.
Offline
Re: HTML Form problem in a bespoke admin tab in extensions
Use the dmp($_POST)
function to show what was submitted. That should at least give you an idea if the variables you want to put back in fInput do indeed contain what you think they should contain. Do the same with the cleaned variables. If none of that helps, post the plugin code here.
Offline
Re: HTML Form problem in a bespoke admin tab in extensions
Hello Ruud
Thanks for the reply. I had already used dmp($_POST) and print_r on the arrays.
I think it’s something to do with the callback but not sure.
There will be two tabs one for adding and one for amending/deleting both working from
the same plugin and both using the same boo_mem_form().
The example below just shows the adding.
$html = array();//return to form
$clean = array();//for database
$error = array();//for error messages
$submit = ps('submit');
$errorlist = '';
$firstname = '';
$lastname = '';
function boo_format($format,$value){
//formatting here.....
return $formatted;
};
function cleaner($ctype, $format, $key, $value, $required){
global $html,$clean,$error;
//cleaning here..... and call boo_format
$html[$key] = htmlentities($value, ENT_QUOTES, 'UTF-8');
return $html[$key];
};
if($submit){
$firstname = cleaner('allowed', 'captilize', 'First name', ps('boo_firstname'), 1);
$lastname = cleaner('allowed', 'captilize', 'Last name', ps('boo_lastname'), 1);
//foreach loop on $error to create $errorlist if !empty.....
echo $firstname;//if I echo here variable is fine.
}
function boo_mem_form(){
global $errorlist,$firstname,$lastname;
return
startTable('boo_member').
tr(
td(
$errorlist.
$firstname.//just for testing purposes variable is empty here....
'<form method="post" action="" class="boo_mem_form">'.//scaled down version of form
graf('<label for="boo_firstname" class="boo_firstname">First name</label>'.fInput('text','boo_firstname',$firstname,'','','','20','','boo_firstname','')).
graf('<label for="boo_lastname" class="boo_lastname">Last name</label>'.fInput('text','boo_lastname',$lastname,'','','','20','','boo_lastname','')).
graf(fInput('submit','boo_submit','Add','boo_submit','','','','','boo_submit','')).
'</form>'
)
).
endTable();
};
if(@txpinterface == 'admin'){
add_privs('txp_my_admin_page','1,2,3,4');
register_tab("extensions", "boo_mem_add", "Member Add");
register_callback("boo_mem_add", "boo_mem_add");
}
function boo_mem_add($event, $step){
pagetop('Add new member', '');
echo boo_mem_form();
};
Forever learning.
Offline
Re: HTML Form problem in a bespoke admin tab in extensions
I’d either put the ‘submit’ IF-construct inside boo_mem_form or declare $errorlist, $firstname and $lastname as global variable at the beginning of the plugin. Even though you may think they are global because they appear outside a function there, in reality they’re not because the plugin code is ‘eval’ed.
Offline
Re: HTML Form problem in a bespoke admin tab in extensions
Thanks Ruud
The global variable at the beginning worked. It’s always the simplest things that catch you out.
Again thanks for your time.
Forever learning.
Offline