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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Labelling and valueing a button differently

Status
Not open for further replies.

chrismassey

Programmer
Aug 24, 2007
264
GB
Here is a standard HTML submit button...

Code:
<input type="submit" name="button" value="Button">

The issue I have with this button is that its value is not only the value carried by the form (i.e. $button = param('button'); ) but also the value thats printed on the button itself.

However, the value I use in the script thats carried by the button is entirely different to the value that should be printed on the button. Therefore I tried using this...

Code:
<button type="submit" name="button" value="$_">Button</button>

(Note that $_ is the value that should be carried forward from a loop)...

However the source code of the HTML page that the form prints shows that everything looks correct...

However the value that is carried forward is not $_ but its Button

I am totally confused.

Cheers,

Chris
 
Do you have different submit button's doing different things?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Hey yes I do. For every file within a directory, a submit button is produced instead of listing the files. This is so that when a user clicks on the button, its value will make sure that the user enters that file.

I'm going to check out that website link now.

Cheers
 
Yeah I followed similar guidelines and everything seems fine. Is it probably a problem due to using different submit buttons? If I do this...

Code:
<button type="submit" name="button" value="$_">$_</button>

It works fine! But the value contains text i.e. .htm which I want removed from the label.



 
so you want to have one value submitted but another displayed.

So the value=test but once submitted you get test.html?

I don't know if you can do that with a submit button.. If you know they are all .html just submit test and add .html to it after you submit it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thats correct. However you may be able to help me with this...

Basically, a client needs to be able to sort his directory into any order he wants. Therefore I have used the = as a separator between a unique number and the file name.

So for example. This directory contains 3 files

01=Home
02=About
03=Contact

Now if I didn't use the numbers then the order would look like this once sorted into alphabetical order

About
Contact
Home

Which isn't correct... Therefore I split the file using the = symbol as the split character... And then print the button

Code:
foreach (@directory_array) {
## Remove Position Indicator
if ($_ =~ m/=/) {
@directory_array_2 = split (/=/, $_);
shift(@directory_array_2);
$button_print = @directory_array_2[0];
}
else { $button_print = $_; }
## Open Directory
print <<"HTML code";
        <table border="0" cellpadding="0" cellspacing="0" width="280" bgcolor="#FFFFFF">
          <tr>
            <td width="45" align="right" valign="middle">
            
            <img border="0" src="Directory.bmp" width="24" height="12">
            
            </td>
            <td width="230" align="center" valign="middle">
            
            <p align="center">
            
            <button type="submit" name="button" value="$_" style="background-color: #FFFFFF; font-family: Arial; font-size: 10pt; font-weight: bold; text-decoration: underline; color: #0000FF; border-style: solid; border-color: #FFFFFF">$button_print</button>
            
            </p>
            
            </td>
          </tr>
        </table>
HTML code
}

But obviously it isn't neat to have i.e. 01=Home

When I just want Home

The value must be 01=Home because this is the name the file is created under i.e.
I could not think of a better way to allow the user to have full manipulation over the position of files in a directory, and there is possibly a much better way... Or a different method to remove the 01= from the button label.

Thanks again,

Chris
 
Not to mess with your original design, but I would separate your file names from your file structure. Make a mapping file and put your order in it and exclude that file from any globbing you are doing.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thats what I had in mind to begin with, to create a text file which maps the directory structure...

i.e. map.txt
Code:
Home
  Home1
  Home2
    index.htm
  Home3
About
Contact
  Contact1
  Contact2
    index.htm

Is this what you meant?

It looks like i'm going to have to redevelop much of my scripts :/. Its a pain when this button system should be working, I don't understand :S.

One more question, if I had a file i.e. file.txt
Code:
Line 1
Line 2
Line 3
Line 4
Line 5

I would assume if I wanted to change Line 3 I would use something like this...

Code:
open (LOG, ">>$initial_path$create_pageb_path$forward_slash$page_name.htm") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG[2] "Changes Line 3"
close (LOG);

Where [2] is Line 3 in the file.txt file.

However this isn't the correct syntax, what have I done wrong?

 
Forget the general syntax errors :s... I meant...

Code:
open (LOG, ">>file.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG[2] "Changes Line 3";
close (LOG);
 
I don't know if you can treat a file handle as an array.

Is there a reason why you are trying to specifically write to line 3 in the file? Is it for your directory structure? My idea was to keep your original naming schema but put it in a file. So the file would contain 01=home.html 02=about.html and you would use that file for sorting your display but wouldn't ever change the original file names.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Surely the same problem would occur? Again the value of each button would have to be 01=home.html and the label home.html?

If I were to store each item in the file in order from 1st to last then I wouldn't need to use an indicator anymore (01=).

Maybe I haven't thought about it enough and you are right. I'm going to think about it and get back to you.

The reason for writing to a specific line is because I want to use a txt file almost like a database for a different script. i.e.

Code:
Chris, 18, England,
John, 23, Australia,
Peter, 19, Russia,

Now say John changed his age from 23 to 40 (lol), I would need to access the 2nd line and then the 2nd element on the 2nd line.

Accessing the 2nd element is easy enough, but I don't know how I would access just line 2. Unless I were to take all the data and put it into an array of 9 elements (in this example)... And then split the first 3 elements, second 3 elements and then thrid 3 elements. However this isn't very efficient, though I would use references.

Chris
 
use the Tie::Fie module and you can treat a file like an array. But not FH[2], the filehandle itself is not the array. Read the Tie::File documentation its pretty easy to use.

The issue I have with this button is that its value is not only the value carried by the form (i.e. $button = param('button'); ) but also the value thats printed on the button itself.

Huh? The form submits key/value pairs. Even for submit buttons. If you have this:

<input type="submit" name="button" value="Button">

in the script you will get:

button=Button

if get something else there is a problem with your form or you are parsing the form incorrectly. If you want to sort files into alpha order you have to sort them case-insensitively if you don't want names with upper-case characters sorted before names without upper-case characters. If you use the generic sort() function it sorts in ASCII order, not alpha order. Upper-case characters have a lower ASCII value than lower-case characters.

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

I understand that I will get button=button (name=Value), but I want the label on the button to be different to the value that is used by the script. Using the <button type> input allows me to have a value and a label, rather than input type which just allows me to have a value (which is also used as the label). However it is strangely not working.

Thanks for the advice on Tie::File, I will have a go.

Cheers,
Chris
 
OK, I think I misunderstood your question. The <button> tag is parsed differently by different browsers and by different versions of the same browser. Newer browsers might have a more consistent behavior with the <button> tag but I never use that particular form widget so I am not sure how it is treated by the various browsers these days. I know in the past, some browsers sent the inner text: (value="inner text") and some sent the outter text: <button>outter text</button>. Like many things html, it was a mess.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Okay I have solved my problem...

Although I was trying to avoid using a link to submit data I have been forced to...

Code:
<A HREF="$script_name?button=$_&path_carry=$path_carry_2&i_frame_url=$i_frame_url">$button_print</A>

However I have thought about travs idea of using a map and I think it seems the sensible solution.

Chris
 
Kevin,

Just noted your response. Thanks for the info on the <button> tag. Its a really strange problem :s, hopefully it will be fixed in later versions.

Chris
 
I doubt it. The problems have been around for years. The button tag is not really used much anyway. Probably because of the buggy behavior.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
One way around your issue is for each button to be in it's own form.

<form action="yoururl.pl"><input type=hidden name="dothing" value="01=Home">blah blah blah<input type="submit" value="Home"></form>
..
<form action="yoururl.pl"><input type=hidden name="dothing" value="02=About">blah blah blah<input type="submit" value="About"></form>

..and at your backend, you would be checking the value of the hidden "dothing"


Another way is to change the NAME of your submit buttons..

<input type=submit name="Z01_Home" value="Home">
<input type=submit name="Z02_About" value="About">

In this version, you would need your backend to check all the form variables passed that start with "Z". If "Z01_Home" exists, then they pressed the "Home" button.




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top