|
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 |
ricklach Smarty Regular
Joined: 27 Aug 2004 Posts: 39
|
Posted: Tue Nov 16, 2004 4:38 pm Post subject: SmartyValidate - append |
|
|
I am having trouble getting the append function to work. Here is my template:
{if $select_donation_type}
<FORM ACTION="addDonation.php" METHOD="post">
<TABLE WIDTH="80%" ALIGN="center" cellpadding="2">
<TR><TD COLSPAN="3" NOWRAP><H2>Make a Donation</H2></TD></TR>
<TR><TD COLSPAN="3" ALIGN="left"><p>You can make a donation direct to a candidate or to a constituency association.
Donations are often associated with political fundraising events. In the next screen you will be able to select an event
from a list of events. If this donation is associated with an event then select the electoral district
where the event took place. This will help you select the appropriate event from the event list on the next page.</p>
</TD></TR>
{if $message}
<TR><TD COLSPAN="3">&</TD></TR>
<TR><TD COLSPAN="3"><FONT COLOR=#ff0000>{$message}</FONT></TD></TR>
{/if}
{validate form="addDonation" field="txtDonorName" criteria="notEmpty" message="You must select a person - please click on <b>Person Search</b>." append="errors"}
{validate form="addDonation" field="txtElectDistrict" criteria="notEmpty" message="You must select an electoral district from the list." append = "errors"}
{if !empty($errors)}
<TR><TD COLSPAN="3"><FONT COLOR=#ff0000>
{section name=error loop=$errors}
error: {$errors[error]}<br>
{/section}
</FONT></TD></TR>
{/if}
<TR><TH ALIGN="right">Select the name of the Donor</TH>
<TD VALIGN="top"><INPUT TYPE="text" NAME="txtDonorName" SIZE="30" VALUE="{$txtDonorName}" ID='organizer1'>
<INPUT TYPE="button" NAME="personSearch" VALUE="Person Search" onclick="showNewWindow('{$personSearchURL}','organizer1','organizer1Id')">
<INPUT TYPE="hidden" NAME="nDonorNum" VALUE="{$nDonorNum|escape}" ID='organizer1Id'><BR />
<FONT COLOR=#ff0000>
</TD></TR>
<TR><TH ALIGN="right">Select an Electoral District</TH>
<TD VALIGN="top"><SELECT NAME="txtElectDistrict" selected={$txtElectDistrict|escape}>
{html_options options=$rlResultArray selected=$txtElectDistrict|escape}
</SELECT>
</TD></TR>
<TR><TH ALIGN="right">
Direct Donation to a Candidate?</TH>
<TD ALIGN="left" VALIGN="top"><INPUT TYPE="radio" NAME="donation_type" VALUE="1">
<FONT COLOR=#ff0000>
{*validate form="addDonation" field="donation_type" criteria="notEmpty" message="You must select one of the donation types."*}</FONT>
</TD></TR>
<TR><TH ALIGN="right">
Donation to a Constituency Association?</TH>
<TD ALIGN="left" VALIGN="top"><INPUT TYPE="radio" NAME="donation_type" VALUE="2" >
</TD></TR>
<TR><TD COLSPAN="3">&</TD></TR>
<TD COLSPAN="3" ALIGN="center"><INPUT TYPE="submit" NAME="action" VALUE="Continue">&&&&
<INPUT TYPE="submit" NAME="action" VALUE="Cancel">&&&&<INPUT TYPE="submit" NAME="action" VALUE="Reset Form">
</TD></TR>
</TABLE>
</FORM>
{/if}
and here is the php:
function donation_type($message) {
$smarty = & new Smarty_gpbc;
$smarty->register_modifier("sslash","stripslashes");
SmartyValidate::connect(&$smarty);
SmartyValidate::register_form('addDonation');
$smarty->clear_cache( "addDonation.tpl" );
foreach ($_REQUEST as $key=>$value) {
$$key = $value;
//echo $key . " = " . $value . "<BR>";
}
$rlResultArray = makeSelectLists("ridinglist");
$smarty->assign( 'select_donation_type', true );
$smarty->assign('message', $message);
$smarty->assign('txtElectDistrict', $txtElectDistrict);
$smarty->assign('txtDonorName', $txtDonorName);
$smarty->assign('nDonorNum', $nDonorNum);
$smarty->assign('rlResultArray', $rlResultArray);
$smarty->assign( 'personSearchURL', $GLOBALS['personSearchURL'] );
$smarty->display( "addDonation.tpl" );
}
I know it should spit out the errors but nothing happens. Also How can I check if one or the other radio buttons has been selected?
Rick |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Nov 16, 2004 5:40 pm Post subject: Re: SmartyValidate - append |
|
|
Quote: | SmartyValidate::connect(&$smarty); |
get rid of the '&', you don't need to pass by reference.
Quote: | $smarty->clear_cache( "addDonation.tpl" ); |
clearing the cache each time, why not just disable caching?
Quote: | foreach ($_REQUEST as $key=>$value) {
$$key = $value;
//echo $key . " = " . $value . "<BR>";
} |
the same thing can be accomplished with explode($_REQUEST), although as a general programming practice I'd recommend accessing the vars directly $_REQUEST['foobar'] instead of blindly exporting them all to the local symbol table. Save yourself some debugging headache
Quote: | I know it should spit out the errors but nothing happens. |
I don't see any code that actually tests the form submission? See the examples that come shipped with SmartyValidate. You have to call SmartyValidate::is_valid() at the very least.
Quote: | Also How can I check if one or the other radio buttons has been selected? |
If validation of one form element depends on another being selected or not, that may require a custom validation criteria. |
|
Back to top |
|
ricklach Smarty Regular
Joined: 27 Aug 2004 Posts: 39
|
Posted: Tue Nov 16, 2004 7:21 pm Post subject: |
|
|
Monte,
Thanks for that input, I will make the changes. Regarding your last point about calling SmartyValidate::is_valid() - I do that in the next part of the form. The form is set up like this:
switch( $_REQUEST['action'] ) {
case "Continue":
show_add($message);
break;
case "Commit Record":
do_add($message);
break;
case "Reset Form":
SmartyValidate::disconnect();
donation_type($message);
break;
case "Cancel":
default:
donation_type($message);
break;
}
In the sample I provided it would be in the "continue" part of the code. Now I will admit that in general the methodology I have used works but I am not satisfied that I have approached the problem correctly. By this I mean, I have seen some code from Eric Wrenholt at this address: http://www.timestretch.com/php_intro/?page=resources and it works slicker than snot on a door knob. Now that is what I would like to achieve but I am not entirely certain what is happening in the code and even more to the point, not sure how to move my code to that methodology. So for now I am trying to get past the errors hurdle. Perhaps if I could send you my entire code you would get a better appreciation of how I have approached the problem.
Rick |
|
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
|