|
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 |
intrige Smarty n00b
Joined: 14 Mar 2008 Posts: 1
|
Posted: Fri Mar 14, 2008 4:48 pm Post subject: SmartyValidation Multiple posts |
|
|
Hi, I am having some problems using the validator.
I am creating a shopping cart procedure and have multiple forms posting to each other.
The first form works fine, then i submit it to the same page with a different form and then it doesn't validate.
Has anybody come across the same problem or has an idea how I can fix this. The code I use is inside a class and quite big, so i will put some code here which is relevant.
Code: |
private function step_1(){
if(empty($_POST)){
SmartyValidate::connect($this->smarty, true);
SmartyValidate::register_validator('v_initials','initials','notEmpty');
}
# fetch template
return $this->smarty->fetch('frontend-order-step1.tpl');
}
private function step_1_shipping(){
# post not empty
SmartyValidate::connect($this->smarty, true);
SmartyValidate::register_validator('v_alt_initials','alt_initials','notEmpty');
$this->smarty->assign('processStep', $this->processStep);
# fetch template
return $this->smarty->fetch('frontend-order-step1-shipping.tpl');
}
/* Processing of steps */
private function process_step_1(){
#smarty validate connect
SmartyValidate::connect($this->smarty);
if(SmartyValidate::is_valid($_POST)){
#smarty disconnect
SmartyValidate::disconnect();
}else{
$this->smarty->assign('formvalue', $_POST);
$this->nextStep = $this->processStep; // process itself again
}
}
}
private function process_step_1_shipping(){
#smarty validate connect
SmartyValidate::connect($this->smarty);
#smarty validate
if(SmartyValidate::is_valid($_POST)){
# smarty disconnect
#SmartyValidate::disconnect();
}else{
var_dump('not valid');
$this->smarty->assign('formvalue', $_POST);
$this->nextStep = $this->processStep; // process itself again
}
}
}
|
I have a piece of code that keeps on track which step must be showed.
So on the first submit if valid it fetch step 1_shipping else it shows step 1 again
piece of template code from the first form
Code: |
<form method='post' action='' class='contentual_shop_form' enctype="multipart/form-data" id='{$function}' name='step1'>
<!--required//-->
<input type='hidden' name='__plugin' value='{$class}' />
<input type='hidden' name='__invoke' value='{$function}' />
<input type='hidden' name='__processStep' value='{$processStep}' />
<p class="error">
{if count($params) > 0}
{t}One or more errors occured when validating your information.{/t}<br />
{t}Please check your input.{/t}
{/if}
</p>
<fieldset class="billing">
<legend>{t}Billing Information{/t}</legend>
<p>
<label for="initials" id="lbl_initials" title="{t}Your initials is a required field{/t}.">{t}Initials{/t}: *</label>
<input type="text" name="initials" value='{$formvalue.initials}' class="{literal}{required:true}{/literal}" title="{t}Your initials is a required field{/t}." />
<span class="error">{validate id="v_initials" message="Your initials is a required field."}</span>
</p>
|
and the second form
Code: | <form method='post' action='' class='contentual_shop_form' enctype="multipart/form-data" id='{$function}' name='step1.5'>
<!--required//-->
<input type='hidden' name='__plugin' value='{$class}' />
<input type='hidden' name='__invoke' value='{$function}' />
<input type='hidden' name='__processStep' value='{$processStep}' />
<p class="error">
{if count($params) > 0}
{t}One or more errors occured when validating your information.{/t}<br />
{t}Please check your input.{/t}
{/if}
</p>
<fieldset class="shipping">
<legend>{t}Alternative Shipping Information{/t}</legend>
<p>
<label for="alt_initials" id="lbl_initials" title="{t}Your initials is a required field{/t}.">{t}Initials{/t}: *</label>
<input type="text" name="alt_initials" value='{$formvalue.alt_initials}' class="{literal}{required:true}{/literal}" title="{t}Your initials is a required field{/t}." />
<span class="error">{validate id="v_alt_initials" message="Your initials is a required field."}</span>
</p>
|
What ever I try, I keep on getting a false second validation.
When I output the session values I will see that the validators has been registered.
Thanks! I realy hope somebody knows what this could be cause it's driving me crazy |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 14, 2008 7:05 pm Post subject: |
|
|
This might have something to do with it:
Code: | SmartyValidate::connect($this->smarty, true); |
That second parameter resets the session. Do not pass true during the validation, only on the very first invocation of the form.
Also, get rid of the disconnect() calls until you have it all working. Sometimes that can throw you for a loop. |
|
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
|