473,320 Members | 2,112 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,320 software developers and data experts.

$_SERVER[PHP_SELF] and <SELECT>

When I select Februar here and sends, selection returns to Januar.
I know why: no option is marked selected...
But can php get this right in an easy way?
<html><head><title>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<select name=obs_mnd>
<option value=\"Jan\">Januar</option>
<option value=\"Feb\">Februar</option>
<option value=\"Des\">Desember</option>
</select>
<input type=\"submit\" name=\"submit\" value=\"Send\">
</form>
";
echo "$form"
?>
</body></html>
Jul 17 '05 #1
9 3175

"Salve Håkedal" <ik**************@fiolinmaker.no> ???????/???????? ?
???????? ?????????: news:bY******************@news4.e.nsc.no...
When I select Februar here and sends, selection returns to Januar.
I know why: no option is marked selected...
But can php get this right in an easy way?
<html><head><title>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<select name=obs_mnd>
<option value=\"Jan\">Januar</option>
<option value=\"Feb\">Februar</option>
<option value=\"Des\">Desember</option>
</select>
<input type=\"submit\" name=\"submit\" value=\"Send\">
</form>
";
echo "$form"
?>
</body></html>


Why are you suprised? When you press SUBMIT the same script is execute
(there is no selected item in it) due to action=\"$_SERVER[PHP_SELF]\", so
where is pointing for previous selected item? No.
Jul 17 '05 #2
"Salve Håkedal" <ik**************@fiolinmaker.no> schrieb im Newsbeitrag
news:bY******************@news4.e.nsc.no...
When I select Februar here and sends, selection returns to Januar.
I know why: no option is marked selected...
But can php get this right in an easy way?
<html><head><title>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<select name=obs_mnd>
<option value=\"Jan\">Januar</option>
<option value=\"Feb\">Februar</option>
<option value=\"Des\">Desember</option>
</select>
<input type=\"submit\" name=\"submit\" value=\"Send\">
</form>
";
echo "$form"
?>
</body></html>


As you write the form into a variable and then output it, it makes it
complicated. I usually do:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
method="post">
<select name="obs_mnd">
<option value="Jan" <?php if(isset($obs_mnd) && $obs_mnd=="Jan") echo
"selected"; ?>>Januar</option>
....

HTH
Markus
Jul 17 '05 #3
I noticed that Message-ID: <40***********************@news.easynet.ch>
from Markus Ernst contained the following:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
method="post">
<select name="obs_mnd">
<option value="Jan" <?php if(isset($obs_mnd) && $obs_mnd=="Jan") echo
"selected"; ?>>Januar</option>

I do a similar thing, but use a function. No easy way AFAIK (for some
value of 'easy')
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4
Markus Ernst skreiv:
"Salve Håkedal" <ik**************@fiolinmaker.no> schrieb im Newsbeitrag
news:bY******************@news4.e.nsc.no...
When I select Februar here and sends, selection returns to Januar.
I know why: no option is marked selected...
But can php get this right in an easy way?
<html><head><title>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<select name=obs_mnd>
<option value=\"Jan\">Januar</option>
<option value=\"Feb\">Februar</option>
<option value=\"Des\">Desember</option>
</select>
<input type=\"submit\" name=\"submit\" value=\"Send\">
</form>
";
echo "$form"
?>
</body></html>


As you write the form into a variable and then output it, it makes it
complicated. I usually do:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
method="post">
<select name="obs_mnd">
<option value="Jan" <?php if(isset($obs_mnd) && $obs_mnd=="Jan") echo
"selected"; ?>>Januar</option>
...

HTH
Markus

Thank you. This is neat and I can understand it.
But my script should lead the user back to the form if it's not properly
filled out, while it's going to present the user with only "Thank you
....etc" if it _is_ properly filled out. Am I right to say that the form has
to be buildt as a variable to achieve that?

$alve
Jul 17 '05 #5
Dennis Biletsky skreiv:

"Salve Håkedal" <ik**************@fiolinmaker.no> ???????/???????? ?
???????? ?????????: news:bY******************@news4.e.nsc.no...
When I select Februar here and sends, selection returns to Januar.
I know why: no option is marked selected...
But can php get this right in an easy way?
<html><head><title>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<select name=obs_mnd>
<option value=\"Jan\">Januar</option>
<option value=\"Feb\">Februar</option>
<option value=\"Des\">Desember</option>
</select>
<input type=\"submit\" name=\"submit\" value=\"Send\">
</form>
";
echo "$form"
?>
</body></html>


Why are you suprised? When you press SUBMIT the same script is execute
(there is no selected item in it) due to action=\"$_SERVER[PHP_SELF]\", so
where is pointing for previous selected item? No.

I ain't surprised !
$alve
Jul 17 '05 #6
"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:bY******************@news4.e.nsc.no...
When I select Februar here and sends, selection returns to Januar.
I know why: no option is marked selected...
But can php get this right in an easy way?
<html><head><title>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<select name=obs_mnd>
<option value=\"Jan\">Januar</option>
<option value=\"Feb\">Februar</option>
<option value=\"Des\">Desember</option>
</select>
<input type=\"submit\" name=\"submit\" value=\"Send\">
</form>
";
echo "$form"
?>
</body></html>


To interpolate a array element into a string you need to use curly brackets.

$form = "<form action\"{$_SERVER['PHP_SELF']}\"> ... ";
Jul 17 '05 #7
On Tue, 6 Apr 2004 18:25:32 -0400, "Chung Leong" <ch***********@hotmail.com>
wrote:
"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:bY******************@news4.e.nsc.no...

<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">


To interpolate a array element into a string you need to use curly brackets.

$form = "<form action\"{$_SERVER['PHP_SELF']}\"> ... ";


Strictly speaking you don't NEED to, but you certainly SHOULD do.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #8
"Salve Håkedal" <ik**************@fiolinmaker.no> wrote in message
news:JK******************@news2.e.nsc.no...
Thank you. This is neat and I can understand it.
But my script should lead the user back to the form if it's not properly
filled out, while it's going to present the user with only "Thank you
...etc" if it _is_ properly filled out. Am I right to say that the form has to be buildt as a variable to achieve that?


No. For a conditional block of HTML you can do:

<? if($is_properly_filled_out) { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myform"
method="post">
<select name="obs_mnd">
....
<? }?>

or as I prefer it

<? if($is_properly_filled_out): ?>
<form action="<?=$_SERVER['PHP_SELF']?>" name="myform"
method="post">
<select name="obs_mnd">
....
<? endif; ?>

For HTML that appears often, you can define it as a function

<? function PrintLoginForm($name) { ?>
<? $name = htmlspecialchars($name); ?>
<form>
<table><tr><td>
<input name="name" value="<?=$name?>"><br>
...
</table>
</form>
<? } ?>
Jul 17 '05 #9

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:fp********************************@4ax.com...

Strictly speaking you don't NEED to, but you certainly SHOULD do.


Why, you are right! Though I would swear that's something that can't be
done. I guess you learn something new everyday.
Jul 17 '05 #10

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

Similar topics

7
by: TG | last post by:
Group, I have several drop down boxes that I'd like to repopulate with the value the user selected -- after the form posts by calling itself -- these fields are blanked out. I am having...
7
by: Cezary | last post by:
Hi. I want to change language on my site online. So, I wrote this: <form action="<?= preg_replace("/&/", "&amp;", $_SERVER) ?>" method="post" name="change_lang_form"> <p...
10
by: EOZyo | last post by:
Hi, i'm trying to set pagination for a search i run on my website, i'll try to explain the easiest i can: When i click the search button on search.php, data is received and stored in variables...
5
by: IchBin | last post by:
I am cross posting to comp.lang.php and alt.comp.lang.php. I am having a problem with getting a post from a dropdownlist off a html form. While debugging, by instruction steps, for some reason I...
23
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to...
5
by: Sonnich | last post by:
Can anyone give me a quick hint for this? Say, I have: <SELECT NAME="opt3" SIZE="15" multiple> Then I'd like to list the items selected... echo $_POST; but this gives only the first one ...
1
by: Valerie | last post by:
Hello everyone, I am new in PHP-programming but I am learning the basics of it. I've got a script that uploads a picture together with all data from the inputform, to the server and places the...
14
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post"...
2
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.