View Full Version : Admin CP Form
RobDog888
09-30-2007, 05:49 AM
When creating a new admin control panel page I need to do some validation but maybe Im just staring at this too long.
Its not evaluating correctly and evals as true each and every time under any condition - blank or populated.
uploads_location is the input element name control.
if (empty($vbulletin->GPC['uploads_location']))
{
print_stop_message('fieldmissing');
}
What am I doing wring lol?
Opserty
09-30-2007, 09:05 AM
Run var_dump($vbulletin->GPC['uploads_location']); die(); on line above the code you posted and see what it returns. If it doesn't return anything you have probably made a typo in one of the names or something.
RobDog888
09-30-2007, 09:51 AM
Ok, on the submitted page it printed out "NULL". :(
The spelling is correct and I use print_input_row with the second parameter as 'uploads_location' and third with a 'test' value. So its even loaded upon page load but if I type anyting into it or leave it as is it still evals to an empty field.
How should I be validating upon the submit? I already have a do value specified on the form opening line. I cant have it reload the page and eval the do with any variables passed as it will never match the if($_POST['do'] ==
Opserty
09-30-2007, 10:08 AM
Part 1) What code are you using to clean the variable then?
Part 2) Submit it to another do action. e.g. if($_REQUEST['do'] == 'doadd') or something of the sort or you can add a hidden field to the form and check if that has been submitted in order to switch between processing the form or displaying the form.
RobDog888
09-30-2007, 04:58 PM
Clean? Im still new to vB and PHP but I think clean writes a value to a cookie?
So I should be storing the element id and value to a cookie using something like...
$vbulletin->input->clean_array_gpc('p', array(
'uploads_location' => TYPE_STR,
'txtUploadLocation' => TYPE STR'
));
If so, where would I place it?
Opserty
09-30-2007, 05:08 PM
Doesn't that give you any parse errors? You have a rouge apostrophe after the TYPE STR, which should also be TYPE_STR.
Try this:
$vbulletin->input->clean_array_gpc('p', array(
'uploads_location' => TYPE_STR,
'txtUploadLocation' => TYPE_STR
));
RobDog888
09-30-2007, 05:35 PM
Ok changes made (yes it did parse error but I hadnt updated my post yet :D). Still doesnt read the inputbox value. I placed the code in the forms construction between the form tags.
I have searched the vB documentation over at vB.com and searched all over here too. Doesnt seem to be too much on form validation :(
Opserty
09-30-2007, 07:39 PM
run:
var_dump($_POST['uploads_location']);
die();
To see if any data is being submitted to the code.
RobDog888
09-30-2007, 07:58 PM
Arrg, still NULL.
This is what I have...
// ...
print_form_header('mypage_admin', 'updatemanager');
print_table_header($vbphrase[my_manager]);
print_input_row('File Uploads Location:', 'uploads_location', 'testdata', 'false', '50', '260');
$vbulletin->input->clean_array_gpc('p', array(
'uploads_location' => TYPE_STR
));
print_submit_row($vbphrase['save'], $vbphrase['reset']);
print_table_footer(3, '', '', 0);
// ...
if ($_REQUEST['do'] == 'updatemanager')
{
// VALIDATE ENTERED DATA
var_dump($vbulletin->GPC['uploads_location']);
die();
if (!$vbulletin->GPC['uploads_location'])
{
print_stop_message('fieldmissing');
}
}
// ...
Opserty
09-30-2007, 08:05 PM
Try:
// ...
if($_REQUEST['do'] == '')
{
print_form_header('mypage_admin', 'updatemanager');
print_table_header($vbphrase[my_manager]);
print_input_row('File Uploads Location:', 'uploads_location', 'testdata', 'false', '50', '260');
print_submit_row($vbphrase['save'], $vbphrase['reset']);
print_table_footer(3, '', '', 0);
}
// ...
elseif ($_REQUEST['do'] == 'updatemanager')
{
// VALIDATE ENTERED DATA
$vbulletin->input->clean_array_gpc('p', array(
'uploads_location' => TYPE_STR
));
if (!$vbulletin->GPC['uploads_location'])
{
print_stop_message('fieldmissing');
}
}
RobDog888
10-01-2007, 07:20 AM
Nope :(
Looking through the vB admin cp files, maybe I should be writting the values out to a cookie upon submit. Then do various verification checks in the do=updatemanager part of the code with a cookie read?
Opserty
10-01-2007, 02:52 PM
Change print_table_footer(3, '', '', 0);
To print_table_footer();
You don't need to specify default values.
Changeprint_submit_row($vbphrase['save'], $vbphrase['reset']);
Toprint_submit_row();
Also here.. if (!$vbulletin->GPC['uploads_location'])
I think that might work but to be safe use if(empty //...
Otherwise I can seem much reason wrong with your script. Maybe you have made an error somewhere else in the page?
RobDog888
10-01-2007, 04:32 PM
<font color="darkgreen">Where can I find documentation on clean_array_gpc or clean_gpc or GPC? php.net doesnt have these so I assume they are vB specific but there in nothing on vb.org about it but members code.
Edit: found it at vb.com and still no help from it. Telling me GPC is a wrapper doesnt help the situation at all. Why is vB so damn freaking limited on its technical documentation.</font>
Opserty
10-01-2007, 04:57 PM
Well modifications aren't exactly supported so :p
If you haven't already you can try
http://members.vbulletin.com/api/
vBulletin 3.6 Code Documentation
Other just check the source code, if you know PHP it should be quite easy to understand whats going on.
Did you get anywhere even with the changes I suggested?
RobDog888
10-01-2007, 05:13 PM
That API link should come in handy. Thanks :)
Part of the issue is that I am learning PH and vB code stuff at the same time.
I dont think its hard at all just lacking information. I have got as far as I have by going over all the code in vB and trying to decipher it. So far so good. I have custom pages added and tempaltes etc but its so much easier with templates/php code but to go on php alone is harder for me.
I originally started with this https://vborg.vbsupport.ru/showthread.php?t=83122 but it doesnt have anything on validating the data and whats the proper safe logic.
This is taking way too long for something that I think is simple. I just need to know how its done so I can integrate that into my code.
print_cp_blah(blah, ...);
print_submit_row(blah);
//...
if(empty($vbulletin->GPC['uploads_location'])
{
//Do validation before entering into db table
}
I did get it to dump once with a value but I dont know what was the issue as it didnt retain and other changes I made may be diff now.
--------------- Added at 11:18 ---------------
What is the diff of "...clean_array_gpc('r'" and "...clean_array_gpc('p'"?
Its not in the docs.
--------------- Added at 20:46 ---------------
I ended up recoding the code block from scratch. I clean_array_gpc'd in each if/elseif conditional along with the vars set by the GPC call. Seems to work now. Guess it was some code error that I just couldnt track down.
I did find that
die('<pre>'.print_r($vbulletin->GPC, true).'</pre>');
will give me the output of whats in the array for "debugging" which helped too.
Thanks for all your time and assistance :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.