Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button submit form

Status
Not open for further replies.

imad77

Instructor
Oct 18, 2008
97
0
0
CA
Hi,

what's wrong in my following script? this part runs after clicking on a submit button to load a file. This part displays 2 buttons "Yes" and "NO" but it continues to run the next lines after this part. This part does not ask me to choose Yes or No to be able to delete the loaded file.


thansk a lot

=============

if (! $query->param('button')) {

print $query->p(Do you want delete this file?');
print $query->start_form();
print $query->submit(-name => 'button', value='yes',-label => 'Yes');
print ' ';
print $query->submit(-name => 'button', value='no',-label => 'No');
print $query->endform;

} elsif ($query->param('button') eq 'no') {

return;
}
 
Hi

Maybe this ?
Code:
print $query->submit(-name => 'button', [COLOR=red pink]-[/color]value='yes',-label => 'Yes');

print $query->submit(-name => 'button', [COLOR=red pink]-[/color]value='no',-label => 'No');

Feherke.
 
Code:
if (! $query->param('button')) {

    print $query->p(Do you want delete this file?');
    print $query->start_form();
    print $query->submit(-name => 'button', value='yes',-label => 'Yes');
    print ' ';
    print $query->submit(-name => 'button', value='no',-label => 'No');
    print $query->endform;
    exit();[red]#<-- stop script[/red]
}
if ($query->param('button') eq 'no') {

return;
}

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kevin,

I tried your suggestion, the script stops and provide the choice yes/no but when I choose "yes", the script does not run the next step to delete the file.

Is tehre something that I foget it?

Thanks a lot,

==========

if (! $query->param('button')) {

print $query->p(Do you want delete this file?');
print $query->start_form();
print $query->submit(-name => 'button', value='yes',-label => 'Yes');
print ' ';
print $query->submit(-name => 'button', value='no',-label => 'No');
print $query->endform;
exit();#<-- stop script
}
if ($query->param('button') eq 'no') {
return;
} elsif ($query->param('button') eq 'yes'){
&sub_delete();
}
 
imad77, keep in mind that the HTTP protocol is state-less. This means that by the time you see the output in your web browser, your CGI script has stopped running and exited. To continue interacting with your CGI script (i.e. clicking a button and having the CGI react), you need to have a separate HTTP request, which will load and execute your script again from top to exit(), but perhaps with different arguments passed (i.e. the value of the button you clicked, or the values filled out in a web form, etc.)

So when your CGI gives you some buttons, it has to exit and the script stops running. It can't give you buttons and then react to what button you clicked in the same HTTP request. It can only give you buttons, exit, you click one, creating a new HTTP request, which restarts your script, this time telling your script that you clicked a button, and then it can react accordingly.

What happens when you click a button?

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
CGI is not like command line scripts. A command line script can stop and wait for input, a CGI script can't. Each time you run a CGI script it starts from the beginning again so you have to program it with that behavior in mind.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
thanks guys for your advises and help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top