prospecting: proper contact error handling when you add a prospect
[freeside.git] / httemplate / elements / contact.html
1 % unless ( $opt{'js_only'} ) {
2
3   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
4
5   <TABLE>
6     <TR>
7 %     foreach my $field ( @fields ) {
8         <TD>
9           <INPUT TYPE = "text"
10                  NAME = "<%$name%>_<%$field%>"
11                  ID   = "<%$id%>_<%$field%>"
12                  VALUE = "<% scalar($cgi->param($name."_$field"))
13                              || $contact->get($field) |h %>"
14                  <% $onchange %>
15           ><BR>
16           <FONT SIZE="-2"><% $label{$field} %></FONT>
17         </TD>
18 %     }
19     </TR>
20   </TABLE>
21
22 % }
23 <%init>
24
25 my( %opt ) = @_;
26
27 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
28 my $id = $opt{'id'} || 'contactnum';
29
30 my $curr_value = $opt{'curr_value'} || $opt{'value'};
31
32 my $onchange = '';
33 if ( $opt{'onchange'} ) {
34   $onchange = $opt{'onchange'};
35   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
36   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
37                                         #callbacks should act the same
38   $onchange = 'onChange="'. $onchange. '"';
39 }
40
41 my $contact;
42 if ( $curr_value ) {
43   $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
44 } else {
45   $contact = new FS::contact {};
46 }
47
48 tie my %label, 'Tie::IxHash',
49   'first'  => 'First name',
50   'last'    => 'Last name',
51   'title'   => 'Title/Position',
52   'comment' => 'Comment',
53 ;
54 my @fields = keys %label;
55
56 </%init>