Re: [SMARTY] Problem using SmartyValidate 2.6, Smarty-2.6.10 with php safe mode etc.
Patrick Ben Koetter <[email protected]>
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
As always when you ask for help you find the solution the second you've hit "send"... I hadn't copied the SmartyValidate libs to the Smarty-2.6.10 plugins dir. p@rick * Patrick Ben Koetter <[email protected]>: > Hi, > > I need assistance in debugging and fixing a problem I have with a contact > form. > > Let me describe the setup first, because I think this is where things go > astray: > > + On my development server things work, but they break on the target host. > > + The target host uses AFS. Templates are being compiled and once I give > correct permissions to files in templates_c pages are displayed. I needed to > disable caching though, but that's something the customer can live with. > > + The target hosts permits sessions. From reading the SmartyValidate README I > believe this is required. > > I have very limited access to the machine. I can only access logs from the day > before using a webinterface making it very hard to debug this for me. > > Here's what happens: > If I leave the contact form and the corresponding kontakt.tpl the way they > are, I get an empty page in the browser. The Server says "200 OK" and insists > it delivered the page successfully. (The admin told me that...) > > If I remove any code starting from <form> through </form> - including any > SmartyValidate calls - I can display the page without the form. > > In yesterdays error log I noted this: > > [Wed Jan 25 11:04:21 2006] [error] PHP Fatal error: Smarty error: [in > kontakt.tpl line 20]: syntax error: unrecognized tag 'validate' > (Smarty_Compiler.class.php, line 580) in > /afs/--replaced--/webserver/Smarty/libs/Smarty.class.php on > line 1088 > > To me this means Smarty does not know what 'validate' should do, right? > It loads Smarty.class.php, though. Registering? You see I am speculating. > Something I hate to do. I'd rather measure... > > Any ideas what I can do? > > TIA, > > p@rick > > > > Here's the kontakt.php: > > <?php > session_start(); > require('/afs/-- replaced -- /Smarty/libs/Smarty.class.php'); > require('/afs/-- replaced -- /Smarty/email_message.php'); > require('/afs/-- replaced -- /SmartyValidate/libs/SmartyValidate.class.php'); > $smarty = new Smarty(); > $smarty->template_dir = '/afs/-- replaced -- /webserver/smarty/templates'; > $smarty->compile_dir = '/afs/-- replaced -- /webserver/smarty/templates_c'; > $smarty->cache_dir = '/afs/-- replaced -- /webserver/smarty/cache'; > $smarty->config_dir = '/afs/-- replaced -- /webserver/smarty/configs'; > // $smarty->debugging = 'true'; > > if(empty($_POST)) { > // new form, we (re)set the session data > SmartyValidate::connect($smarty, true); > // register our validators > SmartyValidate::register_validator('form_subject', 'Subject', 'notEmpty', false, false, 'trim'); > SmartyValidate::register_validator('form_message', 'Message', 'notEmpty', false, false, 'trim'); > SmartyValidate::register_validator('form_firstname', 'Firstname', 'notEmpty', false, false, 'trim'); > SmartyValidate::register_validator('form_lastname', 'Lastname', 'notEmpty', false, false, 'trim'); > SmartyValidate::register_validator('form_sender_empty', 'Sender', 'notEmpty', false, false, 'trim'); > SmartyValidate::register_validator('form_sender_valid', 'Sender', 'isEmail', false, false, 'trim'); > // display form > $smarty->display('kontakt.tpl'); > } else { > // validate after a POST > SmartyValidate::connect($smarty); > if(SmartyValidate::is_valid($_POST)) { > $smarty->assign($_POST); > // no errors, done with SmartyValidate > $from_name=$smarty->get_template_vars('Firstname')." ".$smarty->get_template_vars('Lastname'); > $from_address=$smarty->get_template_vars('Sender'); > $reply_name=$from_name; > $reply_address=$from_address; > $reply_address=$from_address; > $error_delivery_name=$from_name; > $error_delivery_address=$from_address; > $to_name="example"; > $to_address="[email protected]"; > $subject=$smarty->get_template_vars('Subject'); > $message="".$smarty->get_template_vars('Message')."\n\n--\n".$smarty->get_template_vars('Firstname')." ".$smarty->get_template_vars('Lastname')."\n".$smarty->get_template_vars('Contact')."\n"; > $email_message=new email_message_class; > $email_message->SetEncodedEmailHeader("To",$to_address,$to_name); > $email_message->SetEncodedEmailHeader("From",$from_address,$from_name); > $email_message->SetEncodedEmailHeader("Reply-To",$reply_address,$reply_name); > /* > Set the Return-Path header to define the envelope sender address to which bounced messages are delivered. > If you are using Windows, you need to use the smtp_message_class to set the return-path address. > */ > if(defined("PHP_OS") > && strcmp(substr(PHP_OS,0,3),"WIN")) > $email_message->SetHeader("Return-Path",$error_delivery_address); > $email_message->SetEncodedEmailHeader("Errors-To",$error_delivery_address,$error_delivery_name); > $email_message->SetEncodedHeader("Subject",$subject); > $email_message->AddQuotedPrintableTextPart($email_message->WrapText($message)); > $error=$email_message->Send(); > if(strcmp($error,"")) > echo "Error: $error\n"; > $smarty->display('success.tpl'); > SmartyValidate::disconnect(); > } else { > // error, redraw the form > $smarty->assign($_POST); > $smarty->display('kontakt.tpl'); > } > }; > > ?> > > > Here's an excerpt from kontakt.tpl (the part that breaks output): > > <form method="post" action="kontakt.php"> > {if $form_subject_Error or $form_message_Error or $form_firstname_Error or $form_lastname_Error or $form_sender_Error}<p>Ihre Nachricht konnte wegen einer <em>fehlenden</em> oder <em>falschen</em> Information noch nicht versendet werden. Die <span class="error">rot markierte Anmerkung</span> kennzeichnet das zu korrigierende Feld.</p>{else}{/if} > {validate id="form_firstname" message="Bitte geben Sie einen Vornamen an." assign="form_firstname_Error"} > <p><label for="Vorname" title="Pflichtfeld: Vorname">Ihr Vorname *</label><br /> > {if $form_firstname_Error}<span class="error">{$form_firstname_Error}</span><br />{else}{/if} > <input type="text" name="Firstname" value="{$Firstname|escape}" id="Vorname" /></p> > {validate id="form_lastname" message="Bitte geben Sie einen Nachnamen an." assign="form_lastname_Error"} > <p><label for="Nachname" title="Pflichtfeld: Nachname">Ihr Nachname *</label><br /> > {if $form_lastname_Error}<span class="error">{$form_lastname_Error}</span><br />{else}{/if} > <input type="text" name="Lastname" value="{$Lastname|escape}" id="Nachname" /></p> > {validate id="form_sender_empty" message="Bitte geben Sie eine E-mail-Adresse an." assign="form_sender_empty_Error"} > {validate id="form_sender_valid" message="Die E-mail-Adresse, die sie angegeben haben, ist keine gültige E-mail-Adresse." assign="form_sender_valid_Error"} > <p><label for="Sender" title="Pflichtfeld: E-Mail-Adresse">Ihre E-Mail-Adresse *</label><br /> > {if $form_sender_empty_Error}<span class="error">{$form_sender_empty_Error}</span><br />{else}{/if} > {if $form_sender_valid_Error}<span class="error">{$form_sender_valid_Error}</span><br />{else}{/if} > <input type="text" name="Sender" size="30" value="{$Sender|escape}" id="Sender" /></p> > {validate id="form_subject" message="Bitte geben Sie einen Betreff ein." assign="form_subject_Error"} > <p><label for="Betreff" title="Pflichtfeld: Betreff">Betreff *</label><br /> > {if $form_subject_Error}<span class="error">{$form_subject_Error}</span><br />{else}{/if} > <input type="text" name="Subject" value="{$Subject|escape}" id="Betreff" /></p> > {validate id="form_message" message="Bitte geben Sie eine Nachricht ein." assign="form_message_Error"} > <p><label for="Nachricht" title="Pflichtfeld: Mitteilung">Ihre Mitteilung an uns *</label><br /> > {if $form_message_Error}<span class="error">{$form_message_Error}</span><br />{else}{/if} > <textarea name="Message" rows="10" cols="20" id="Nachricht">{$Message|escape}</textarea></p> > {validate id="form_contact" message="Bitte geben Sie Ihre Kontaktdaten an." assign="form_contact_Error"} > <p><label for="Kontaktdaten" title="Optionales Feld: Kontaktdaten">Ihre Kontaktdaten</label><br /> > {if $form_contact_Error}<span class="error">{$form_contact_Error}</span><br />{else}{/if} > <textarea name="Contact" rows="4" cols="20" id="Kontaktdaten">{$Contact|escape}</textarea></p> > <p style="text-align:right;"><button type="submit" accesskey="s">abschicken</button></p> > </form> > > > -- > state of mind > Agentur für Kommunikation und Design > > Patrick Koetter Tel: 089 45227227 > Echinger Strasse 3 Fax: 089 45227226 > 85386 Eching Web: http://www.state-of-mind.de > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- state of mind Agentur für Kommunikation und Design Patrick Koetter Tel: 089 45227227 Echinger Strasse 3 Fax: 089 45227226 85386 Eching Web: http://www.state-of-mind.de -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php