473,789 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

$_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><ti tle>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
<select name=obs_mnd>
<option value=\"Jan\">J anuar</option>
<option value=\"Feb\">F ebruar</option>
<option value=\"Des\">D esember</option>
</select>
<input type=\"submit\" name=\"submit\" value=\"Send\">
</form>
";
echo "$form"
?>
</body></html>
Jul 17 '05 #1
9 3206

"Salve Håkedal" <ik************ **@fiolinmaker. no> ???????/???????? ?
???????? ?????????: news:bY******** **********@news 4.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><ti tle>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
<select name=obs_mnd>
<option value=\"Jan\">J anuar</option>
<option value=\"Feb\">F ebruar</option>
<option value=\"Des\">D esember</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=\"$_SERV ER[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******** **********@news 4.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><ti tle>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
<select name=obs_mnd>
<option value=\"Jan\">J anuar</option>
<option value=\"Feb\">F ebruar</option>
<option value=\"Des\">D esember</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_m nd) && $obs_mnd=="Jan" ) echo
"selected"; ?>>Januar</option>
....

HTH
Markus
Jul 17 '05 #3
I noticed that Message-ID: <40************ ***********@new s.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_m nd) && $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******** **********@news 4.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><ti tle>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
<select name=obs_mnd>
<option value=\"Jan\">J anuar</option>
<option value=\"Feb\">F ebruar</option>
<option value=\"Des\">D esember</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_m nd) && $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******** **********@news 4.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><ti tle>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
<select name=obs_mnd>
<option value=\"Jan\">J anuar</option>
<option value=\"Feb\">F ebruar</option>
<option value=\"Des\">D esember</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=\"$_SERV ER[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******** **********@news 4.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><ti tle>Part of a bigger page</title></head>
<?php
$form ="
<form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >
<select name=obs_mnd>
<option value=\"Jan\">J anuar</option>
<option value=\"Feb\">F ebruar</option>
<option value=\"Des\">D esember</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\"{$_SERV ER['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******* ***********@new s4.e.nsc.no...

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


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

$form = "<form action\"{$_SERV ER['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.andyhsoftwa re.co.uk/space
Jul 17 '05 #8
"Salve Håkedal" <ik************ **@fiolinmaker. no> wrote in message
news:JK******** **********@news 2.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="<?=$_SE RVER['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 = htmlspecialchar s($name); ?>
<form>
<table><tr><t d>
<input name="name" value="<?=$name ?>"><br>
...
</table>
</form>
<? } ?>
Jul 17 '05 #9

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

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
8202
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 difficulty getting the drop downs to repopulate with the values the user's selected. If any of you have implemented this before, how have you done this and what is the syntax? Thanks,
7
1961
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 style="display:none;"><input type="hidden" name="change_lang" value="1"> <label for="lang" accesskey="l">== <?= CHOOSE_LANG ?> ==</label></p> <p class="margin"><select id="lang" name="lang" class="langsection" onChange="if (this.options.value != 'null')
10
7244
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 within results.php, MySQL structure seems to work as expected, although i get some problems: As soon as i click on the "Page 2" Link, i get nothing, neither results nor page numbers.
5
2547
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 am never get passed the isset($_POST) after selecting an item in the dropdownlist. I have coded a simple script to duplicate what I am trying to do, just to make sure i understand it, and that works. This is the code and has to be something...
23
2807
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 place a link on there site so people can vote for their program, "ad a click". eg someone clicks the link on some page and it counts +1 click on my page. if some one clicks the link below it will count a click on my page.
5
2473
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 how do I get the rest?
1
1813
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 pathname into the Mysql. I desperately want to have the uploaded pictures resized in the meantime. Does anyone know how to do this ? Or perhaps adjust the script with the functions, necessary for resizing ? I would appreciate it VERY VERY much !...
14
75535
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" enctype="multipart/form-data" name="form1"> <select onchange="this.form.submit();" name="prod"> <option value="">Select product</option> <option value="12">abc</option>
2
2595
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 kindly help <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title>
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.