Forum Moderators: coopster & phranque

Message Too Old, No Replies

how to pass the value to template and retrive the result from same cgi

         

srinshcl

8:04 am on Nov 18, 2005 (gmt 0)

10+ Year Member



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.

ckarg

12:46 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



You didn't say, but are you using CGI.pm? If so, then there are at least a couple of options:

1. request_method() - Returns the method used to access your script, usually one of 'POST', 'GET' or 'HEAD'. You can use this CGI.pm function to determine whether your code was invoked because of "GET" or "PUT", and then take the appropriate action.

2. If you give your button a name (e.g. <input type="submit" name="GoDoIt" value="Click Me">), then you can check whether that button was pressed:

if (defined param('GoDoIt') and param('GoDoIt') eq 'Click Me') {
...
}

Hope that helps....