keiichi Posted July 24, 2010 Share Posted July 24, 2010 Hi people,I'm trying to integrate a php library to build forms:http://validformbuilder.orgI need to build a form and use the library to validate and send the email with the data of the form.So far I have this: <?php include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/init.php'); include(dirname(__FILE__).'/header.php'); $smarty->assign(array('strOutput' => $strOutput)); $smarty->display(_PS_THEME_DIR_.'oferta.tpl'); include(dirname(__FILE__).'/footer.php'); //*** Include the library. include(dirname(__FILE__).'/libraries/ValidForm/class.validform.php'); ... ... .... .... And the code used by the library to build and validate the form... .... $strOutput = $objForm->toHtml(); I have created oferta.tpl in the themes folder, and put this code: {strOutput} but is not rendering anything, I'm getting a blank page.If I try to include a simple $hello variable and asign to $smarty->assign(array('hello' => $hello));blank page too.Any help or advice is well receivedThank you! Link to comment Share on other sites More sharing options...
rocky Posted July 25, 2010 Share Posted July 25, 2010 It should be {$strOutput} not {strOutput}. Link to comment Share on other sites More sharing options...
keiichi Posted July 25, 2010 Author Share Posted July 25, 2010 Grrr! I cant make it work... Maybe I need a coofeeOk this is all the code I have:File: oferta.php <?php include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/init.php'); include(dirname(__FILE__).'/header.php'); $smarty->assign('strOutput' , $strOutput); $smarty->display(_PS_THEME_DIR_.'oferta.tpl'); include(dirname(__FILE__).'/footer.php'); //*** Include the library. include(dirname(__FILE__).'/libraries/ValidForm/class.validform.php'); //*** Create an instance of the form. $objForm = new ValidForm("contactForm", "Required fields are printed in bold."); //*** Add the Name field. $objForm->addField("name", "Your name", VFORM_STRING, array( "maxLength" => 255, "required" => TRUE ), array( "maxLength" => "Your input is too long. A maximum of %s characters is OK.", "required" => "This field is required.", "type" => "Enter only letters and spaces." ) ); //*** Add the Email field. $objForm->addField("email", "Email address", VFORM_EMAIL, array( "maxLength" => 255, "required" => TRUE ), array( "maxLength" => "Your input is too long. A maximum of %s characters is OK.", "required" => "This field is required.", "type" => "Use the format [email protected]" ), array( "tip" => "[email protected]" ) ); //*** Add the Remarks field. $objForm->addField("remarks", "Remarks", VFORM_TEXT, array( "maxLength" => 2000 ), array( "maxLength" => "Your input is too long. A maximum of %s characters is OK.", "type" => "Enter only characters, punctuation, numbers and spaces" ) ); //*** Set the general alert. $objForm->setMainAlert("One or more errors occurred. Check the marked fields and try again."); //*** Set the label of the submit button. $objForm->setSubmitLabel("Send"); //*** Default output. $strOutput = ""; //*** Check the form. if ($objForm->isSubmitted() && $objForm->isValid()) { //*** HTML body of the email. $strMessage = "<html><head><title></title></head><body>"; $strMessage .= $objForm->valuesAsHtml(); $strMessage .= "</body></html>"; //*** Mail headers. $strHeaders = "MIME-Version: 1.0\r\n"; $strHeaders .= "Content-type: text/html; charset=utf-8\r\n"; $strHeaders .= "From: Awesome website <[email protected]>\r\n"; //*** Send the email. mail("[email protected]", "Contact form submitted", $strMessage, $strHeaders); //*** Set the output to a friendly thank you note. $strOutput = "Thank you for your interest. We will contact you as soon as possible."; } else { //*** The form has not been submitted or is not valid. $strOutput = $objForm->toHtml(); } ?> File: oferta.tpl {$strOutput} If I harcode the variable : $smarty->assign('strOutput' , 'strOutput'); I get : strOutput not the content of the variable.but if I change to: $smarty->assign('strOutput' , $strOutput); I get my regular PS page without content, if I look at the source code i can see: Link to comment Share on other sites More sharing options...
rocky Posted July 25, 2010 Share Posted July 25, 2010 That's because you are assigning the variable at the top before putting the content in the variable. Move the following lines: $smarty->assign('strOutput' , $strOutput); $smarty->display(_PS_THEME_DIR_.'oferta.tpl'); include(dirname(__FILE__).'/footer.php'); to the bottom just before the: ?> Link to comment Share on other sites More sharing options...
keiichi Posted July 25, 2010 Author Share Posted July 25, 2010 Rocky you are the man!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now