473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Dynamic form in PERL

hi im a new user here. apparently im working on a project that is creating a dynamic form. Assume user can insert the data into text field and upload csv file, csv file may have two columns. user has to provide a special character like <> in text field to replace with data from second column of csv file.

here is the tmpl code:

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2. <td align="right">
  3. BroadCast box:</td><td align="left"> <textarea name="mseg" rows="5" cols="33"
  4. onKeyUp="val = this.value;
  5. if (val.length>160)
  6. {
  7. alert('Sorry, you are over the limit of 160 characters');
  8. this.value = val.substring(0,160);
  9. smsInput.focus()
  10. }
  11. this.form.count.value=160-parseInt(this.value.length);">
  12. </textarea></td></tr>
  13. <tr>
  14. <td align="right">Please specify file to upload:</td>
  15.     <td align="left"><input type="file" name="address" size="30" maxlength="80" /></td>
  16. </tr>
  17. <tr>
  18. <td colspan="2" align="center">
  19. <input type="button" name="submit" value="Upload" onClick="validateForm(document.upload);">
  20. <input type="reset" name=".reset" value="Reset" />
  21. </td>
this is my pm code:

Expand|Select|Wrap|Line Numbers
  1. sub Uploading {
  2.     my $self = shift;
  3.     my $element;
  4.     my $output;
  5.     my $co = $self->{CGI};
  6.     my $mseg = $self->{CGI}->param('mseg');
  7.  
  8.     if (!defined($mseg)){
  9.         $output = $self->MsgRedirect('error',"Sorry, No template selected.");
  10.         return $output;
  11.     }
  12.     my $error = $co->cgi_error;
  13.     if ($error) {
  14.         $output = $self->MsgRedirect('error',"CGI POST Error");
  15.         return $output;
  16.     }
  17.  
  18.     my @form_input = $co->param();
  19.     my $buffer = "";
  20.     my $count = 1;
  21.  
  22.     foreach my $in (@form_input) {
  23.         $buffer .= $in . '==' . $co->param($in) . "<br/>\n";
  24.         $count++;
  25.     }
  26.  
  27.     my $msg_count = 0;
  28.     my $symbol = "<>";
  29.     my @loop_data;
  30.     if ($fileformat eq "1") {
  31.         @data = <$add>;
  32.         my $i =0;
  33.         my $color = "";
  34.         foreach $element (@data) {
  35.             $element =~s/[\n\r]/ /g;
  36.             $element =~ s/^\s+//g;
  37.             $element =~ s/\s+$//g;
  38.             if ( length($element) == 0 ) {
  39.                 next;
  40.             }
  41.  
  42.             my %data_elem;
  43.             if ($i % 2 == 0) {
  44.                 $data_elem{CLASS} = "even";
  45.             } else {
  46.                 $data_elem{CLASS} = "odd";
  47.             }
  48.  
  49.             $data_elem{COUNT} = $i + 1;
  50.             $data_elem{LANG_CODE} = $charset;
  51.             $data_elem{MSEG} = $mseg;
  52.  
  53.             if($element =~ /^(\+?\d+),(.*)$/) {
  54.                 $data_elem{MNO} = $1;
  55.                 $data_elem{MSG} = $2;
  56.  
  57.                 if( length($data_elem{MSG}) > 160 ) {
  58.                     $data_elem{MSG} = substr $data_elem{MSG}, 0, 160;
  59.                     my $mymsg = $data_elem{MSG};
  60.                     $data_elem{MSEG} = $mseg;
  61.                     $mseg =~ s/$symbol/$mymsg;
  62.                 }
  63.  
  64.                 $msg_count++;
  65.  
  66.             } else {
  67.                 $data_elem{MNO} = "NA";
  68.                 $data_elem{MSG} = $element;
  69.                 $mymsg = $data_elem{MSG};
  70.                 $mseg =~ s/$symbol/$mymsg;
  71.             }
  72.  
  73.             push @loop_data, \%data_elem;
  74.             $i++;
  75.         }
  76.  
I do realize my code has some error and still I can't figure out. I'll appreciate if you provide me easier way to do so.
Feb 14 '07 #1
4 1724
KevinADC
4,059 Expert 2GB
don't know if this is the only problem, but you have two lines that are the same :

Expand|Select|Wrap|Line Numbers
  1. $mseg =~ s/$symbol/$mymsg;
they are both missing the ending / at the end of the regexp:

Expand|Select|Wrap|Line Numbers
  1. $mseg =~ s/$symbol/$mymsg/;
Feb 14 '07 #2
thanks you indeed for your reply .. it isn't working correctly yet :(
Feb 14 '07 #3
KevinADC
4,059 Expert 2GB
thanks you indeed for your reply .. it isn't working correctly yet :(

what isn't working? Any error messages? I see this in the code:

<$add>

where is $add being defined? and is $add scoped (visible) to that block of code?
Feb 14 '07 #4
i did figure out the error and its working now .. tnx for ur help :)
Feb 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: surfunbear | last post by:
I noticed a post that mentioned PHP does a better job of dynamic web content than java and wanted to see what people have to say about that. Also, I saw it mentioned that in PHP you don't have to...
10
by: Mark Winter | last post by:
Hello, I am wondering if someone could point me in the right direction to figure out how to create a dynamic form. I have been developing programs in perl and oracle and have recently switched...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
0
by: OverTheTop | last post by:
All the usual Newbie stuff applies... I have a Windows2000 Server with ActivePerl and a module (DBD-Interbase) that worked fine. Trying to duplicate the environment on Windows2003 Server for...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
9
by: atbusbook | last post by:
I'm doing a report on the speed of develipment and executionin varius programing langiuiges. write code for all these tasks in the languige of your choise if intrestied send code to...
3
Kelicula
by: Kelicula | last post by:
I am trying to set a variable to one of two things depending on if the client has cookies enabled. I have decided NOT to have a prompt saying "cookies must be enabled" if they don't have cookies...
8
numberwhun
by: numberwhun | last post by:
Hello everyone! I am dabbling in processing forms using Perl and having only just begun, I am already having problems. Go figure. :-) Top begin with, here it the form's html, its nothing at...
1
by: kanishka1213 | last post by:
#!/activeperl/perl/bin/perl use CGI qw(:standard); print "Content-type: text/html\n\n"; print <<EndOfHTML; <html> <head> <script language="javascript" type="text/javascript">
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.