srins has asked for the wisdom of the Perl Monks concerning the following question:

hi,
I have an cgi page named add.cgi where i will get parameters component and command,in my add cgi page and i will also have hash %data.
my add.cgi will be like this, my $component=$query->param('component'); my $ccc_id=$query->param('ccc_id'); my %data = ( ccc_id => $ccc_id, component_name => $component, add => \@tc_add_templ ); my $template = Template->new({ }); $template->process($file,\%data) || die $template->error();
where i will be passing this to template file.tc_add_templ will have data for form field in template ie name and value pairs in my template form elements. in add.tmpl file i will have data like this
<form action="AddTemplateResult.cgi" method="get" bgcolor="#e6ede7"> [% FOREACH element = add %] [% IF element.req == "all" %] <input type="text" name="[%element.name %]" value="[%element.default +%]" size="58">
In AddTemplateResult.cgi i will be getting results and store it in hash
@names=$query->param(); foreach $key (@names) { $val=$query->param("$key"); $hoh{$key}=$val; }
where i will be pasing this hash to anther perl file for processing and add the recpective data in an repositry.
$ref=$tc_ref->add_tc_to_rep(%hoh);
print "$ref\n
If it is added to the repositry sucessfully, i will be getting the message sucessful and print the result.
Here i am using two different cgi file ie add.cgi and AddTemplateResult.cgi.

I need to change that to one cgi file.I need to use only add.cgi.need to use like
<form action="add.cgi" method="get" bgcolor="#e6ede7">
when i am using same cgi file for both passing the values and retriving the result.I am getting error in that.
when i add data to add template ,I need to print the result getting from $ref and need to show the form again to add the data.
For the first time when i hit the cgi page i should get that add template form only.when i add data and submit the data using submit button ,then i should print the result "added sucessfully " and need to show the form again to add the data for futher.
i tried to check
if(ref eq " "){ pass the data to template ; } else { result data code; }
but it is not working in the manner i expected.Any idea how to check these condtions in my code.how to change my code according to problem.
Thanks, srins.

Replies are listed 'Best First'.
Re: how to pass the value to template and retrive the result from same cgi file.
by eric256 (Parson) on Nov 18, 2005 at 14:02 UTC

    Hey, It is rather hard to follow your question and your code so my answer is in pseudo code. ;)

    In add.cgi: check if one of that params with data is present. It is often usefull to have a command param that your script looks for and acts on. Then in your form you set that command param <input type="hidden" name="cmd" value="add"> Now in your script you can check $query->param("cmd") eq "add" and if it does, add the data in, otherwise display the form.

    I hope that helps. In general provide the smallest amount of code that should actualy do what you want the script to do. Then we can work with you on that, and you can take what you learn from it and use it in your bigger script. The added side effect is that 80%+ of the time you will solve your own problem while trying to make a smaller script do the same thing. Good LuckM.


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;
Re: how to pass the value to template and retrive the result from same cgi file.
by jesuashok (Curate) on Nov 18, 2005 at 08:57 UTC
    Hi

    you have to use redirect method in the add.cgi file. That will solve your problem.

    Template is the very useful module in developing CGI application using perl.

    Please read the HTML::Template documentation carefully before raising your queries

    "Keep pouring your ideas"