 |
|
 |
|
Next: Can MySql have multiple datadir's ?
|
| Author |
Message |
External

Since: Dec 21, 2003 Posts: 10
|
(Msg. 1) Posted: Tue Jul 27, 2004 10:54 am
Post subject: form button names as variables Archived from groups: alt>comp>lang>php, others (more info?)
|
|
|
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 >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |
External

Since: Jan 16, 2004 Posts: 2
|
(Msg. 2) Posted: Tue Jul 27, 2004 11:54 am
Post subject: Re: form button names as variables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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 >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |
External

Since: Jul 14, 2003 Posts: 8
|
(Msg. 3) Posted: Tue Jul 27, 2004 11:54 am
Post subject: Re: form button names as variables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"PhilM" <philm.TakeThisOut@nospam.com.am> wrote in message
news:41066686$0$18191$afc38c87@news.optusnet.com.au...
> 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 <a style='text-decoration: underline;' href="http://www.php.net/manual/en/ref.array.php" target="_blank">http://www.php.net/manual/en/ref.array.php</a>
Nel.<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |
External

Since: Dec 21, 2003 Posts: 10
|
(Msg. 4) Posted: Tue Jul 27, 2004 11:54 am
Post subject: Re: form button names as variables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Andrew Crowe" <andrewcrowe_uk DeleteThis @yahoo.co.uk> wrote in message
news:41066e8d$0$26230$afc38c87@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<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |
External

Since: Jul 27, 2004 Posts: 3
|
(Msg. 5) Posted: Tue Jul 27, 2004 4:55 pm
Post subject: Re: form button names as variables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
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:
<a style='text-decoration: underline;' href="http://pear.php.net/package/HTML_QuickForm" target="_blank">http://pear.php.net/package/HTML_QuickForm</a>
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
>
><!-- ~MESSAGE_AFTER~ --> >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |
External

Since: Dec 21, 2003 Posts: 10
|
(Msg. 6) Posted: Tue Jul 27, 2004 10:54 pm
Post subject: Re: form button names as variables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Luciano Tolomei" <tolomei.RemoveThis@newmediatrio.it> wrote in message
news:8hzNc.100871$G%.77635@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:
<font color=purple> > <a style='text-decoration: underline;' href="http://pear.php.net/package/HTML_QuickForm</font" target="_blank">http://pear.php.net/package/HTML_QuickForm</font</a>>
>
>
> 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
> >
> ><!-- ~MESSAGE_AFTER~ --> >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |

Joined: Jan 06, 2004 Posts: 655
|
(Msg. 7) Posted: Wed Jul 28, 2004 7:32 pm
Post subject: Re: form button names as variables [Login to view extended thread Info.]
|
|
|
| PhilM wrote: |
"Luciano Tolomei" <tolomei.RemoveThis@newmediatrio.it> wrote in message
news:8hzNc.100871$G%.77635@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. >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |
External

Since: Jun 20, 2004 Posts: 22
|
(Msg. 8) Posted: Wed Jul 28, 2004 7:54 pm
Post subject: Re: Re: form button names as variables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"PhilM" wrote:
> "Luciano Tolomei" <tolomei.RemoveThis@newmediatrio.it> wrote in message
> news:8hzNc.100871$G%.77635@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:
<font color=green> > > <a style='text-decoration: underline;' href="http://pear.php.net/package/HTML_QuickForm</font" target="_blank">http://pear.php.net/package/HTML_QuickForm</font</a>>
> >
> >
> > 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.
--
<a style='text-decoration: underline;' href="http://www.dbForumz.com/" target="_blank">http://www.dbForumz.com/</a> This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: <a style='text-decoration: underline;' href="http://www.dbForumz.com/PHP-form-button-variables-ftopict133546.html" target="_blank">http://www.dbForumz.com/PHP-form-button-variables-ftopict133546.html</a>
Visit Topic URL to contact author (reg. req'd). Report abuse: <a style='text-decoration: underline;' href="http://www.dbForumz.com/eform.php?p=448738" target="_blank">http://www.dbForumz.com/eform.php?p=448738</a><!-- ~MESSAGE_AFTER~ --> >> Stay informed about: form button names as variables |
|
| Back to top |
|
 |  |
| Related Topics: | Form Data -> Variables or an Array? - 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 complex, and I don't want to have to mess around with..
Submit Button - How can I use a graphic button instead of the usual grey SUBMIT button?
Constructor as a "Reset" Button - I'm having a BLAST writing this app as OOP as PHP allows. It's one thing to discuss the dance, but it's a thing of beauty to see the performance. I'm noticing that the constructor is a "reset" switch - just like the one on the front of my ...
passing radio button values to a submit button (gif) - Hello, How do i pass the value of the radio button to be put of the action that includes the value as part of the URL being submitted - "/ picked.php?pick_num=". Any help with be appreciated. Thanks <form method="post"..
More on session variables - I wanted to see if absolute or relative URLs had anything at all to do with the session variable information being lost. So, I wrote a simple test program. It is at www.sheldonlg.com/headertest/index.php. The results were not what I expected. BOTH.... |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|