473,386 Members | 1,708 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,386 software developers and data experts.

form button names as variables

perhaps I am just a little tired, but I am having trouble with my form
buttons.

Firstly I name them like this
name=\"round".$counter."heats\"
which results in variables
$round1heats
$round2heats
$round3heats
etc...
now, when I select button named ... "round1heats" ... I want to use the
variable $round1heats to remove the button "round1heats", and display heats
set for the round. To do that I assumed that I would have to:-
IF(isset($round1heats)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

My problem is, since all this is dynamic, since the number of heats is
variable, and is dependant on DB entries, how do I generate the $round1heats
used in the isset() so that it is recognised as a variable by the isset().
I have tried, to concat the bits as I have done in the naming of the button,
but, unsurprisingly, it spits out errors ;)
[note, $counter is still available, and is limited to the number of rounds
registered in DB.]
OR, have I been barking up the wrong tree altogether?

I hope that made a bit of sense .

PhilM
Jul 17 '05 #1
7 2214
There are a few things you could try to improve the routine.

One is to use $_GET or $_POST instead of using registered global variables,
as these are considered much more secure.

For example, if your form tag is method="post" then you would do

IF(array_key_exists("round{$count}heats",$_POST)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

One thing to note is that if the submit buttons are type="image" then the
form will post round1heats.x, round1heats.y or round1heats_x,
round1heats_y to correspond to the x and y pos that the user clicked on the
image, so that'd need to be taken into consideration as well.
Finally if these buttons need to stay the same if the database changes a
lot, then you should load all the database info you need into a session and
then draw the buttons from that rather then from the database each time.

--
Regards,
Andrew Crowe
Jul 17 '05 #2
Nel
"PhilM" <ph***@nospam.com.am> wrote in message
news:41***********************@news.optusnet.com.a u...
perhaps I am just a little tired, but I am having trouble with my form
buttons.

Firstly I name them like this
name=\"round".$counter."heats\"
which results in variables
$round1heats
$round2heats
$round3heats
etc...
now, when I select button named ... "round1heats" ... I want to use the
variable $round1heats to remove the button "round1heats", and display heats set for the round. To do that I assumed that I would have to:-
IF(isset($round1heats)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

My problem is, since all this is dynamic, since the number of heats is
variable, and is dependant on DB entries, how do I generate the $round1heats used in the isset() so that it is recognised as a variable by the isset().
I have tried, to concat the bits as I have done in the naming of the button, but, unsurprisingly, it spits out errors ;)
[note, $counter is still available, and is limited to the number of rounds
registered in DB.]
OR, have I been barking up the wrong tree altogether?

I hope that made a bit of sense .

PhilM

Try using arrays and then working through the arrays in order.

name=\"round[$counter]\"

so you get
name="round[1]"
name="round[2]"
etc.

Then you can set a loop to work through $round[$loopnumber] to see which is
set etc.

See http://www.php.net/manual/en/ref.array.php

Nel.


Jul 17 '05 #3

"Andrew Crowe" <an************@yahoo.co.uk> wrote in message
news:41***********************@news.easynet.co.uk. ..
There are a few things you could try to improve the routine.

One is to use $_GET or $_POST instead of using registered global variables, as these are considered much more secure.

For example, if your form tag is method="post" then you would do

IF(array_key_exists("round{$count}heats",$_POST)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

One thing to note is that if the submit buttons are type="image" then the
form will post round1heats.x, round1heats.y or round1heats_x,
round1heats_y to correspond to the x and y pos that the user clicked on the image, so that'd need to be taken into consideration as well.
Finally if these buttons need to stay the same if the database changes a
lot, then you should load all the database info you need into a session and then draw the buttons from that rather then from the database each time.

--
Regards,
Andrew Crowe

Many thanks. My head doesn't hurt as much now ;)
I am using method="post".
I am not using images, tho that is something to remember. (Am using styles
to make hrefs and form buttons look identical.)
these buttons are generated when certain other conditions are met, and are
only on display when a competition is edited. ie not a full time presence as
part of any template. When there is the need to edit the heats in a round,
the button is redundant when the heats are displayed, as I have another that
will pass info back.

Tried the code, and works a treat.
Once again, many thanks.

PhilM
Jul 17 '05 #4
you could do simply as you are doing putting in html : name=round1heats ...
and then makin in the php code something like:

for ($i=0;$i<$max_rows;$i++) {
if (isset($_POST["round".$i."heats"]) && $_POST["round".$i."heats"] !=
"") {
//do something
else //do something else
}

if you use register global ON this will work too:
....
$name = "round".$i."heats";
if (isset($$name) && $$name != "") {
....
or you can use array in the form...
or a lot of other things.
but i suggest to you to spend some more time in it and build a good
object to work with your forms or look at something like this:
http://pear.php.net/package/HTML_QuickForm
bye
Luciano
PhilM wrote:
perhaps I am just a little tired, but I am having trouble with my form
buttons.

Firstly I name them like this
name=\"round".$counter."heats\"
which results in variables
$round1heats
$round2heats
$round3heats
etc...
now, when I select button named ... "round1heats" ... I want to use the
variable $round1heats to remove the button "round1heats", and display heats
set for the round. To do that I assumed that I would have to:-
IF(isset($round1heats)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

My problem is, since all this is dynamic, since the number of heats is
variable, and is dependant on DB entries, how do I generate the $round1heats
used in the isset() so that it is recognised as a variable by the isset().
I have tried, to concat the bits as I have done in the naming of the button,
but, unsurprisingly, it spits out errors ;)
[note, $counter is still available, and is limited to the number of rounds
registered in DB.]
OR, have I been barking up the wrong tree altogether?

I hope that made a bit of sense .

PhilM

Jul 17 '05 #5

"Luciano Tolomei" <to*****@newmediatrio.it> wrote in message
news:8h*******************@tornado.fastwebnet.it.. .
you could do simply as you are doing putting in html : name=round1heats .... and then makin in the php code something like:

for ($i=0;$i<$max_rows;$i++) {
if (isset($_POST["round".$i."heats"]) && $_POST["round".$i."heats"] !=
"") {
//do something
else //do something else
}

if you use register global ON this will work too:
...
$name = "round".$i."heats";
if (isset($$name) && $$name != "") {
...
or you can use array in the form...
or a lot of other things.
but i suggest to you to spend some more time in it and build a good
object to work with your forms or look at something like this:
http://pear.php.net/package/HTML_QuickForm
bye
Luciano

thanks for this. I almost started to look at variable variables.
I suppose that is really where I was heading.
regards,
PhilM

PhilM wrote:
perhaps I am just a little tired, but I am having trouble with my form
buttons.

Firstly I name them like this
name=\"round".$counter."heats\"
which results in variables
$round1heats
$round2heats
$round3heats
etc...
now, when I select button named ... "round1heats" ... I want to use the
variable $round1heats to remove the button "round1heats", and display heats set for the round. To do that I assumed that I would have to:-
IF(isset($round1heats)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

My problem is, since all this is dynamic, since the number of heats is
variable, and is dependant on DB entries, how do I generate the $round1heats used in the isset() so that it is recognised as a variable by the isset(). I have tried, to concat the bits as I have done in the naming of the button, but, unsurprisingly, it spits out errors ;)
[note, $counter is still available, and is limited to the number of rounds registered in DB.]
OR, have I been barking up the wrong tree altogether?

I hope that made a bit of sense .

PhilM

Jul 17 '05 #6
"PhilM" wrote:
"Luciano Tolomei" <to*****@newmediatrio.it> wrote in message
news:8h*******************@tornado.fastwebnet.it.. .
you could do simply as you are doing putting in html :

name=round1heats
....
and then makin in the php code something like:

for ($i=0;$i<$max_rows;$i++) {
if (isset($_POST["round".$i."heats"]) &&

$_POST["round".$i."heats"] !=
"") {
//do something
else //do something else
}

if you use register global ON this will work too:
...
$name = "round".$i."heats";
if (isset($$name) && $$name != "") {
...
or you can use array in the form...
or a lot of other things.
but i suggest to you to spend some more time in it and build a

good
object to work with your forms or look at something like this:
http://pear.php.net/package/HTML_QuickForm
bye
Luciano

thanks for this. I almost started to look at variable variables.
I suppose that is really where I was heading.
regards,
PhilM

PhilM wrote:
perhaps I am just a little tired, but I am having trouble with my form buttons.

Firstly I name them like this
name=\"round".$counter."heats\"
which results in variables
$round1heats
$round2heats
$round3heats
etc...
now, when I select button named ... "round1heats" ... I want to use the variable $round1heats to remove the button "round1heats", and display
heats set for the round. To do that I assumed that I would have to:- IF(isset($round1heats)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

My problem is, since all this is dynamic, since the number of heats is variable, and is dependant on DB entries, how do I generate the
$round1heats used in the isset() so that it is recognised as a variable by the
isset(). I have tried, to concat the bits as I have done in the naming of the
button, but, unsurprisingly, it spits out errors
[note, $counter is still available, and is limited to the number of
rounds registered in DB.]
OR, have I been barking up the wrong tree altogether?

I hope that made a bit of sense .

PhilM

</font>


Phil, register_globals is going away, and is a security threat. I
would not turn it on. Use $_POST.

Nel’s solution IMHO is the most elegant. No need to have many
variable names or variable variables. Take a 2nd look at Nel’s.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-form-but...ict133546.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=448738
Jul 17 '05 #7
"PhilM" wrote:
"Luciano Tolomei" <to*****@newmediatrio.it> wrote in message
news:8h*******************@tornado.fastwebnet.it.. .
you could do simply as you are doing putting in html :

name=round1heats
....
and then makin in the php code something like:

for ($i=0;$i<$max_rows;$i++) {
if (isset($_POST["round".$i."heats"]) &&

$_POST["round".$i."heats"] !=
"") {
//do something
else //do something else
}

if you use register global ON this will work too:
...
$name = "round".$i."heats";
if (isset($$name) && $$name != "") {
...
or you can use array in the form...
or a lot of other things.
but i suggest to you to spend some more time in it and build a

good
object to work with your forms or look at something like this:
http://pear.php.net/package/HTML_QuickForm
bye
Luciano

thanks for this. I almost started to look at variable variables.
I suppose that is really where I was heading.
regards,
PhilM

PhilM wrote:
perhaps I am just a little tired, but I am having trouble with my form buttons.

Firstly I name them like this
name=\"round".$counter."heats\"
which results in variables
$round1heats
$round2heats
$round3heats
etc...
now, when I select button named ... "round1heats" ... I want to use the variable $round1heats to remove the button "round1heats", and display
heats set for the round. To do that I assumed that I would have to:- IF(isset($round1heats)){
show other stuff instead etc
}else{
generate and print html for button "round1heats"
}

My problem is, since all this is dynamic, since the number of heats is variable, and is dependant on DB entries, how do I generate the
$round1heats used in the isset() so that it is recognised as a variable by the
isset(). I have tried, to concat the bits as I have done in the naming of the
button, but, unsurprisingly, it spits out errors
[note, $counter is still available, and is limited to the number of
rounds registered in DB.]
OR, have I been barking up the wrong tree altogether?

I hope that made a bit of sense .

PhilM

</font>


Phil, register_globals is going away, and is a security threat. I
would not turn it on. Use $_POST.

Nel’s solution IMHO is the most elegant. No need to have many
variable names or variable variables. Take a 2nd look at Nel’s.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-form-but...ict133546.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=448738
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Ballard | last post by:
Hi all, I've seen some weird (to me) behaviour where PHP (I think PHP is the culprit) turns dots into underscores in the names in my form data. Below is a simple example (play.php): <?php...
5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
14
by: Oleg | last post by:
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two...
1
by: williamroy | last post by:
Hello, I've got a form that runs over 5 pages. I need the last page submit button to post all of the answers at one time from the previous 5 pages (to another server). I'd like to see the last...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
4
by: Cerebral Believer | last post by:
Hi I need help! Forgive me I am a PHP newbie. I have a small script that enables me to send a form from an HTML page. I want to use the HTML formatted form because the design of my website is...
10
by: menashay | last post by:
Hello, I am absolute beginner in C# so pardon me if the following question is too easy. I have a form with a one button. When I click the button I want to display a message that reads...
22
by: Kurda Yon | last post by:
Hi, In the first page I declare a session variable. Than, on the same page, I make a form which contains a variable which has the same name as the mentioned session variable. Pressing the...
13
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.