View previous topic :: View next topic |
Author |
Message |
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
Posted: Sun Feb 17, 2008 11:47 pm Post subject: [resolved] SmartyValidate V2.9 validate file form |
|
|
hello community,
i have a problem to validate file forms. here some infos:
Template Code:
Code: | {include file = 'page_header.tpl'}
{include file = 'admin.inc.tpl'}
<div class="content-box">
<h4>Bild hinzufügen</h4>
{if $smarty.get.produkt eq ''}
<form method="post">
Produkt
<select name="product" style="width:50%;">
<option>Produkt (ID | Kategorie | Name)</option>
<option></option>
{foreach from=$products item=product_item}
<option value="{$product_item.products_id}">
{$product_item.products_id} | {$product_item.categories_name} | {$product_item.name}
</option>
{/foreach}
</select>
<input name="choose" type="submit" value="auswählen" />
</form>
{else}
{if $error_product ne 'not_exist'}
Sie bearbeiten gerade das Produkt <span class="bold">{$products.0.name}</span> mit der ID <span class="bold">{$products.0.products_id}</span>.<br /><br />
<form enctype="multipart/form-data" method="post">
Bild <input maxlength="255" name="picture" type="file" value="{$picture|default:''|escape}" /> <input type="submit" name="send" value="hochladen" />
</form>
{validate id='picture_empty' message='<p class="error">Bitte gib ein Bild zum hochladen an.</p>'}
{validate id='picture_too_large' message='<p class="error">Das Bild ueberschreitet die maximale Größe von 1MB.</p>'}
{validate id='picture_wrong_format' message='<p class="error">Erlaubt sind nur die Formate: GIF, JPG und PNG.</p>'}
{else}
<p class="error">Dieses Produkt existiert nicht.</p>
{/if}
{/if}
</div>
{include file = 'page_footer.tpl'}
|
PHP Code:
Code: | if (empty($_POST['send'])) {
SmartyValidate::connect($tpl, true);
SmartyValidate::register_validator('picture_empty', 'picture', 'notEmpty', false, false, 'trim');
SmartyValidate::register_validator('picture_too_large', 'picture:1m', 'isFileSize', false, false, 'trim');
SmartyValidate::register_validator('picture_wrong_format', 'picture:jpg,gif,png', 'isFileType', false, false, 'trim');
}
else {
SmartyValidate::connect($tpl);
if (SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect();
do_something();
else {
$tpl -> assign($_POST);
}
}
|
submit Error
Code: | Notice: Undefined index: picture in ***/htdocs/lib/smarty/SmartyValidate.class.php on line 185
Notice: Undefined index: picture in ***/htdocs/lib/smarty/SmartyValidate.class.php on line 199
|
$_FILES
Code: | Array
(
[picture] => Array
(
[name] => 0157_xxl.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phppphg34
[error] => 0
[size] => 175245
)
)
|
{debug}
Code: | assigned template variables:
{$SCRIPT_NAME} bild_hinzufuegen.php
{$isAuthenticated} true
{$navigation_admin_active_link} bild_hinzufuegen.php
{$picture} empty
{$send} hochladen
assigned config file variables (outer template scope):
{#files#} Array (0)
{#vars#} Array (0)
|
it seems the validation doesn't work.
if i upload a standard conform jpg (also checked the mime type) this validate is activated:
Code: | {validate id='picture_empty' message='<p class="error">Bitte gib ein Bild zum hochladen an.</p>'} |
edit:
$_SESSION
Code: | Array ( [is_authenticated] => true [SmartyPaginate] => Array ( [default] => Array ( [item_total] => 1 [item_limit] => 15 [urlvar] => start [current_item] => 1 [first_text] => << [last_text] => >> [prev_text] => < [next_text] => > ) ) [SmartyValidate] => Array ( [default] => Array ( [registered_funcs] => Array ( [criteria] => Array ( ) [transform] => Array ( ) ) [validators] => Array ( ) [is_error] => [is_init] => 1 ) ) ) |
enough information to help me?
i read the readme over and over, also search the forum. but nothing helped.
edit:
solution
check out the latest cvs...
Last edited by psycco on Mon Feb 18, 2008 5:50 pm; edited 2 times in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 18, 2008 3:37 am Post subject: |
|
|
Have you tried one validator at a time to see if it's a certain one causing the trouble?
Last edited by mohrt on Mon Feb 18, 2008 3:45 am; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 18, 2008 3:42 am Post subject: |
|
|
Actually, I may have an idea what the problem is. I don't think the notEmpty validator will work on a variable that is of type file, it is looking for the variable in the POST. Try disabling the notEmpty validator, see if that helps. You may have to make your own validator function to test the picture file is not empty. |
|
Back to top |
|
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
Posted: Mon Feb 18, 2008 12:26 pm Post subject: |
|
|
hello mohrt,
you're alright if i disable the notempty validator it works, but not without errors. it get still these error messages:
submit error:
Code: | Notice: Undefined index: picture in ***/htdocs/lib/smarty/SmartyValidate.class.php on line 185
Notice: Undefined index: picture in ***/htdocs/lib/smarty/SmartyValidate.class.php on line 199 |
Code: | Notice: SmartyValidate: [validate plugin] form 'default' is not registered. in ***/htdocs/lib/smarty/plugins/function.validate.php on line 53
Notice: SmartyValidate: [validate plugin] form 'default' is not registered. in ***/htdocs/lib/smarty/plugins/function.validate.php on line 53 |
If i disable eg 'isfilesize' only one undefined index (at the last box) appears.
edit:
when i comment out: SmartyValidate::disconnect(); the two Notice errors gone :-/ |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 18, 2008 3:03 pm Post subject: |
|
|
Only disconnect() when you are all done, and do NOT redraw the form or you will get errors. disconnect() erases the session data.
What I usually do is after a disconnect(), immediately do an http redirect so if the form does get redrawn, validation will register properly. |
|
Back to top |
|
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
Posted: Mon Feb 18, 2008 3:49 pm Post subject: |
|
|
ok thank you, but this is not the problem. the problem is that the "undefined index" errors doesn't let the page redirects (because of the output).
the undefinded index errors are everytime (SmartyValidate.class.php) you push the submit button (error_reporting e_all).
it is regardless if the validation works or not, the errors still comes up. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 18, 2008 5:04 pm Post subject: |
|
|
Those are just notices, and its because there is no POST var named picture. I don't think the validator understands that these are validators for _FILE types at that point, something I should get fixed.
In the meantime, you can suppress the notices by adding "@" in front of $formvars[$_field] on those lines giving the error. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 18, 2008 5:14 pm Post subject: |
|
|
Another problem I notice, you are applying the "trim" transform on the file field, which makes no sense. You don't want to trim them. This may be contributing to the notice errors too. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 18, 2008 5:25 pm Post subject: |
|
|
Try the latest CVS, I fixed the notice errors for non-existing form vars. |
|
Back to top |
|
psycco Smarty Rookie
Joined: 08 Aug 2006 Posts: 8
|
Posted: Mon Feb 18, 2008 5:49 pm Post subject: |
|
|
ok i checked out the latest cvs and it seems to be fixed
thanks for your tip with the trim and overall thank you for your fast help and good support.
++ |
|
Back to top |
|
hankejh Smarty n00b
Joined: 22 Aug 2007 Posts: 3 Location: New York, NY
|
Posted: Mon Nov 30, 2009 6:31 pm Post subject: [resolved] SmartyValidate V2.9 validate file form |
|
|
Hi Monte,
Are the updates mentioned in this subject's thread (t=12759 -- sorry can't post urls yet) also available at the download link on phpinsider? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Nov 30, 2009 6:53 pm Post subject: |
|
|
Probably not, you can get them via the anonymous CVS though. I need to get an update out I suppose |
|
Back to top |
|
hankejh Smarty n00b
Joined: 22 Aug 2007 Posts: 3 Location: New York, NY
|
Posted: Mon Nov 30, 2009 10:51 pm Post subject: [resolved] SmartyValidate V2.9 validate file form |
|
|
Thanks M!
CVS version solved the issue mentioned in this thread. |
|
Back to top |
|
|