Jump to content
  • 0

Formularz na stronie csm


Buaha

Question

Witma,

mam problem z działaniem formularza na stronie cms. Mianowicie zamieściłem html formularza na stronie CSM:

<div class="content">
<br /><center><form action="" method="post" name="form1"><input id="Type your email address" class="required" type="text" name="mail" /><br /><br /> <input id="First Name" class="required" type="text" name="user" /><br /><br /> <input class="sub" type="submit" name="Submit" value="Sign Up" /></form></center><br /><br />
</div>

po czym w pliku CSMcontroller dodałem:

if (isset($_POST['Submit'])){
$username = $_POST['user'];

$email = $_POST['mail'];



//the data

$data = "$username | $email\n";



//open the file and choose the mode

$fh = fopen("users.txt", "a");

fwrite($fh, $data);



//close the file

fclose($fh);



header('Location: http://xxx.pl');

}

I wszystko było by dobrze bo skrypt się wykonuje i na końcu następuje przekierowanie. Jednak wartości wpisane w formularz nie zapisują się do pliku users.txt

Czy może ktoś jest w stanie pomóc?

Dodam że jeśli taki formularz wykorzystuje na normalnej stronie czyli nie w prescie to wszystko działa bez problemu.
Pozdrawiam i dziękuję za pomoc :)

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

wsumie to sie wczesniej nie przyjrzalem cmscontroller - ale teraz tak nie bardzo wiem do ktorej funkcji zes wkleil ten kod.

 

przy okazji ja kiedys wymyslilem inne obejscie zapisu do newslettera (bo chyba o to chodzi)

zastosowalem iframe - dzieki temu moge korzystac z newslettera zewnetrznego

<p><iframe width="100%" height="800px" src="http://blahblahblah" frameborder="0" scrolling="no"></iframe></p>
Link to comment
Share on other sites

  • 0

Tak wygląda cały controller. Może rzeczywiście url do pliku users.txt powinien być w jakimś innym formacie? Tylko jaki powinien być poprawny format linku do tego pliku?

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

class CmsControllerCore extends FrontController
{
	public $php_self = 'cms';
	public $assignCase;
	public $cms;
	public $cms_category;

	public function canonicalRedirection($canonicalURL = '')
	{
		if (Validate::isLoadedObject($this->cms) && ($canonicalURL = $this->context->link->getCMSLink($this->cms)))
			parent::canonicalRedirection($canonicalURL);
		else if (Validate::isLoadedObject($this->cms_category) && ($canonicalURL = $this->context->link->getCMSCategoryLink($this->cms_category)))
			parent::canonicalRedirection($canonicalURL);
	}

	/**
	 * Initialize cms controller
	 * @see FrontController::init()
	 */
	public function init()
	{
		parent::init();

		if (isset($_POST['Submit'])){
$username = $_POST['user'];

$email = $_POST['mail'];



//the data

$data = "$username | $email\n";



//open the file and choose the mode

$fh = fopen("users.txt", "a");

fwrite($fh, $data);



//close the file

fclose($fh);



header('Location: xxx.html');

}
		
		if ($id_cms = (int)Tools::getValue('id_cms'))
			$this->cms = new CMS($id_cms, $this->context->language->id);
		else if ($id_cms_category = (int)Tools::getValue('id_cms_category'))
			$this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id);

		$this->canonicalRedirection();

		// assignCase (1 = CMS page, 2 = CMS category)
		if (Validate::isLoadedObject($this->cms))
		{
			$adtoken = Tools::getAdminToken('AdminCmsContent'.(int)Tab::getIdFromClassName('AdminCmsContent').(int)Tools::getValue('id_employee'));
			if (!$this->cms->isAssociatedToShop() || !$this->cms->active && Tools::getValue('adtoken') != $adtoken)
			{
				header('HTTP/1.1 404 Not Found');
				header('Status: 404 Not Found');
			}
			else
				$this->assignCase = 1;
		}
		else if (Validate::isLoadedObject($this->cms_category))
			$this->assignCase = 2;
		else
		{
			header('HTTP/1.1 404 Not Found');
			header('Status: 404 Not Found');
		}
	}

	public function setMedia()
	{
		parent::setMedia();

		if ($this->assignCase == 1)
			$this->addJS(_THEME_JS_DIR_.'cms.js');

		$this->addCSS(_THEME_CSS_DIR_.'cms.css');
	}

	/**
	 * Assign template vars related to page content
	 * @see FrontController::initContent()
	 */
	public function initContent()
	{
		parent::initContent();

		$parent_cat = new CMSCategory(1, $this->context->language->id);
		$this->context->smarty->assign('id_current_lang', $this->context->language->id);
		$this->context->smarty->assign('home_title', $parent_cat->name);
		$this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID'));
		if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category)
			$path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS');
		else if (isset($this->cms_category->meta_title))
			$path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS');
		if ($this->assignCase == 1)
		{
			$this->context->smarty->assign(array(
				'cms' => $this->cms,
				'content_only' => (int)(Tools::getValue('content_only')),
				'path' => $path
			));
		}
		else if ($this->assignCase == 2)
		{
			$this->context->smarty->assign(array(
				'category' => $this->cms_category, //for backward compatibility
				'cms_category' => $this->cms_category,
				'sub_category' => $this->cms_category->getSubCategories($this->context->language->id),
				'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ),
				'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '',
			));
		}

		$this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
	}
}

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...