|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Thu Jul 17, 2003 5:14 am Post subject: Smarty Woes |
|
|
I'm about to give up on Smarty. I am fighting the simplest of tasks with this thing. I wonder if it's really worth it. My latest problem is with form validation. I have two identical scripts, one for user login and one for a contact form. If fields are improperly filled out, a session is established and an error message printed when the script gets called and reloads the template.
This set up works fine on my login script, but using the identical set up on the contact script, i mean verbabtim, i get no error message. I know smarty sees the error session because it reloads the page if the proper values are not filled out, but it absolutely will not print the message for anything! I'm using a clause like this, which works on the login: Code: | { if $smarty.session.valError } print a message { /if }. |
Works on one, but not the other. Anyone know what the cause may be. I'm to my wits end and I need to get work done. Sorry for the rant, but I feel better now. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Thu Jul 17, 2003 10:50 am Post subject: |
|
|
Perhaps if you posted a bit more of the templates we could see the problem. I can't help you if you only provide one line of code. BTW I started using the FormProcessor class from http://simon.incutio.com/archive/2003/06/17/theHolyGrail to validate and display messages on all my forms. _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Thu Jul 17, 2003 6:02 pm Post subject: |
|
|
Sorry to be so vague, but the code is in different pages and I thouhgt I'd try to get away with explaining it instead. I've read that article the you mentioned before. It looks really good. Also PEAR QuickForm is nice, but using it with Smarty can be tedious. I think I'm going to try out your advice and put this thing to use (great, something else I have to learn on top of Smarty and PEAR). Thanks for the tip. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Jul 17, 2003 6:51 pm Post subject: |
|
|
reformed1 wrote: | Sorry to be so vague, but the code is in different pages and I thouhgt I'd try to get away with explaining it instead. [...snip...] (great, something else I have to learn on top of Smarty and PEAR). |
hmm--alas, reformed1, quality code demands a quality effort. In this case, you neither took the time to properly document your issue nor explain it in a way that anyone could help you solve it (and we do want to help!). I well understand your frustration, but to be frank, your posts leave me feeling little sympathy for your plight.
If you take the time to properly illustrate your issue you will likely either find the problem yourself or at least enable someone else to provide real help.
Good Luck! I hope you solve your issues quickly or perhaps try asking again here if you are still stuck.
Aside: On the other hand, sometimes a good rant is all we really need, yes? Perhaps we need a new forum where people can vent rhetorically ? |
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Thu Jul 17, 2003 9:02 pm Post subject: |
|
|
Yeah, I just got lazy. I've decided to take another approach entirely on that problem. Thanks for setting me straight. _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
reformed1 Smarty Rookie
Joined: 13 Jun 2003 Posts: 19 Location: Sunny Phoenix, AZ
|
Posted: Fri Jul 18, 2003 1:46 am Post subject: |
|
|
Well my new approach failed so here is the code that I should have originally included in my first post. This snippet is my validation class in action. If validation errors occure, a session is registered containing the errors and the page is reloaded so the errors can be shown. I nullify the session after display so it errors won't be displayed when there are none.
Code: | //if the add new time form is sent, handle it
if($_GET['action'] == 'AddNew') {
//call the form validator
$fv = new FormValidator();
//check the fields
$fv->isEmpty("date", "You must enter a date");
$fv->isEmpty("shortDesc", "You must enter a description");
$fv->isEmpty("hours", "You must enter your hours");
$fv->isFloat("hours", "You must enter only numbers with decimals for hours");
$fv->isAlpha("shortDesc", "Use only letters for description");
//if errors exist, redisply the form with error messages
if($fv->isError()) {
//get the error list
$errors = $fv->getErrorList();
//register an error session
$_SESSION['valError'] = $errors;
//reload the page and exit to display errors
header("location:timesheets.php");
//kill the error session after display
$_SESSION['valError'] = null;
exit();
} |
Now that I have a session called valErrors, I enter the following into my template so the error message can be displayed:
Code: | {if $smarty.session.valError }Some Error Message{/if} |
and I can be more specific by using the errors in the array by referencing their keys. Now this exact method works on a user login script I'm using and I have even taken the exact code from that script and pasted it into this one, but this one won't work.
The page reloads but no session variable can be seen by smarty so the error message is not displayed. Very strange. Any ideas of what the cause of this strangeness may be? Are there any known problems with smarty and sessions or are the problems just in my head? _________________ We are no longer the knights who say......nee! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|