[email protected] Posted May 18, 2016 Share Posted May 18, 2016 (edited) Tengo un problema al pasar un nuevo campo del formulario create-account_form. Cuando lo obtengo en processSubmitCreate() siempre esta vacio. La función getValue('ciudad_create') no devuelve nada. He añadido el código en authentication.tpl para que se muestre el campo CIudad <label for="email_create">{l s='Email address'}</label> <input type="email" class="is_required validate account_input form-control" data-validate="isEmail" id="email_create" name="email_create" value="{if isset($smarty.post.email_create)}{$smarty.post.email_create|stripslashes}{/if}" /> <label for="ciudad_create">{l s='City'}</label> <input type="text" class="is_required validate account_input form-control" data-validate="isCity" id="ciudad_create" name="ciudad_create" value="{if isset($smarty.post.ciudad_create)}{$smarty.post.ciudad_create|stripslashes}{/if}" /> En la funcion de processSubmitCreate() de AuthController.php he añadido la comprobacion (He añadido el campo ciudad a la clase Customer $customer->ciudad) protected function processSubmitCreate() { if (!Validate::isCity($ciudad = trim(Tools::getValue('ciudad_create'))) || empty($ciudad)) { $this->errors[] = Tools::displayError('La ciudad introducice no es correcta: Barcelona, Madrid o Alicante'); } elseif (!Validate::isEmail($email = trim(Tools::getValue('email_create'))) || empty($email)) { $this->errors[] = Tools::displayError('Invalid email address.'); } elseif (Customer::customerExists($email)) { $this->errors[] = Tools::displayError('An account using this email address has already been registered. Please enter a valid password or request a new one. ', false); $_POST['email'] = trim(Tools::getValue('email_create')); unset($_POST['email_create']); } else { $this->create_account = true; $this->context->smarty->assign('email_create', Tools::safeOutput($email)); $_POST['email'] = $email; } } La funcion isCity la he añadido en la clase Validate.php /** * Check for validity * * @param string $ciudad ciudad to validate * @return bool Validity is ok or not */ public static function isCity($ciudad){ $ciudades = array('Barcelona','Madrid','Alicante'); if (in_array($ciudad, $ciudades)){ return false; }else return true; } Edited May 18, 2016 by [email protected] (see edit history) Link to comment Share on other sites More sharing options...
ventura Posted May 18, 2016 Share Posted May 18, 2016 Entiendo que has creado tambien el campo nuevo en la tabla customer de tu base de datos. Los cambios que realices en classes y controllers es mejor que los hagas mediante overrides. Link to comment Share on other sites More sharing options...
[email protected] Posted May 18, 2016 Author Share Posted May 18, 2016 Si! He creado también el campo en la base de datos. Lo haré con overrides pero de todas formas. No entiendo porque no consigo recoger el valor con getValue:: En el mismo punto recoge sin problemas el campo 'email_create' del mismo formulario. Link to comment Share on other sites More sharing options...
Code-Plus Posted May 19, 2016 Share Posted May 19, 2016 Buenas, imprime un getAllValues(), y a ver que tiene el array. Saludos Link to comment Share on other sites More sharing options...
[email protected] Posted May 19, 2016 Author Share Posted May 19, 2016 He metido esto en la función processSubmitCreate: foreach ($_POST as $key => $value) $this->errors[] = Tools::displayError("Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>"); y esto es lo que obtengo: Field controller is authentication<br> Field SubmitCreate is 1<br> Field ajax is true<br> Field email_create is [email protected]<br> Field back is my-account<br> Field token is 4f834c5cc5cf42cc2d28976faf373cc8<br> Link to comment Share on other sites More sharing options...
Code-Plus Posted May 20, 2016 Share Posted May 20, 2016 Buenas, en el código que pegaste no vi la inserción en smarty. Lo tienes incluido? Saludos Link to comment Share on other sites More sharing options...
[email protected] Posted May 20, 2016 Author Share Posted May 20, 2016 En primer lugar, muchas gracias por tus respuestas. La verdad es que creo que aqui puede estar el problema pero no lo tengo muy claro porque ya he probado tantas cosas... En la funcion processSubmitCreate() tengo esto (En el primer comentario no esta) de AuthController : else { $this->create_account = true; $this->context->smarty->assign('email_create', Tools::safeOutput($email)); $this->context->smarty->assign('ciudad_create', $ciudad); $_POST['email'] = $email; $_POST['ciudad'] = $ciudad; } pero claro en ese else entra despues de validar isCity y en ese momento necesito ya el getValue('ciudad') por lo que entiendo que igual no lo estoy poniendo donde corresponde. Link to comment Share on other sites More sharing options...
Code-Plus Posted May 20, 2016 Share Posted May 20, 2016 Buenas, la asignación de smarty la tienes que hacer cuando sacas el tpl, no puedes intentar hacer post de un campo no cargado. En primer lugar debes asignar a smarty las variables con su tpl + css correspondiente, después, en la llamada/hook que recoge el evento, recoges el submit. Saludos Link to comment Share on other sites More sharing options...
[email protected] Posted May 20, 2016 Author Share Posted May 20, 2016 Me podrias explicar un poco más o darme alguna referencia de donde puedo mirarlo? Link to comment Share on other sites More sharing options...
Code-Plus Posted May 20, 2016 Share Posted May 20, 2016 Mírate la clase principal de php de cualquier módulo del front. De ahí puedes hacerte a la idea. Saludos Link to comment Share on other sites More sharing options...
[email protected] Posted May 20, 2016 Author Share Posted May 20, 2016 (edited) Bueno, creo que por el momento lo dejaré porque debo estar cometiendo algun error que ya no soy capaz de ver. Lo que me comentabas imagino que era en authcontroller poner dentro de updateContext $this->context->cookie->ciudad = $customer->ciudad; Lo que no llego a entender es que en el siguiente formulario si que lo recogo bien y todo me funciona. Es al añadir el campo junto al e-mail en el primer proceso de creación. Estoy perdida la verdad. Edited May 20, 2016 by [email protected] (see edit history) Link to comment Share on other sites More sharing options...
Code-Plus Posted May 20, 2016 Share Posted May 20, 2016 Buenas, esto: $this->context->cookie->ciudad = $customer->ciudad; No se puede hacer, porque no existe esa propiedad en customer. Tendrías que rescribir la clase. Saludos Link to comment Share on other sites More sharing options...
[email protected] Posted May 20, 2016 Author Share Posted May 20, 2016 La clase customer esta modificada para tener $customer->ciudad y el campo esta añadido en la base de datos. /** @var string ciudad */ public $ciudad; 'ciudad' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 32), De hecho en el formulario siguiente me funciona bien. y me llega a guardar en la base de datos la ciudad que le introduzco. Link to comment Share on other sites More sharing options...
Code-Plus Posted May 20, 2016 Share Posted May 20, 2016 Buenas, revisa la asignación a smarty, ejemplo: $this->smarty->assign( array( 'products' => HomeFeatured::$cache_products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), ) ); Saludos Link to comment Share on other sites More sharing options...
[email protected] Posted May 23, 2016 Author Share Posted May 23, 2016 Nada! Creo que me rindo! Esta claro que no hago la asignacion correctamente pero ya no se donde probar. La debería hacer en el processSubmitCreate pero no me funciona. He probado muchas opciones, la ultima: $this->context->smarty->assign('ciudad_create', Tools::safeOutput($ciudad)); y $this->context->smarty->assign('ciudad_create', $ciudad); 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