SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : The Server :

Previous DiscussionNext Discussion


';
?>





Started By scwilson on May 22, 2006 at 1:02:36 PM
This message has been edited.

 PHP and Select Dropdown Loses Setting (Fixed?)

(Let's try that again)

Our order form for name, address, etc. contains PHP-handled dropdown lists for selecting state and country. If, on "Submit", the user has selected "State", say, but missed a required field, e.g. "City", an error message is displayed alongside "City". The state selection is undisturbed. Standard stuff so far.

But now the user types in the city, presses "Submit" again, and the form is re-displayed, this time with "State" showing "0". That is, on this second "Submit" the state selection is lost. Can anyone see what we are doing wrong?

Many thanks for having a look. Here's the code for "State" (with list trimmed for brevity):



State 
if ((isset($_POST['submit2'])) && (($_POST['State']) == "0")) {
echo "Please include your State.\n";
}
?>
8 Response(s) | Reply

Earlier Replies | Replies 2 to 8 of 8 | Later Replies
Goto Page: 2 1
MHenke on May 23, 2006 at 1:20:26 AM (# 2)

Either use IE's RTE or manually replace HTML markup with character entities.


Frances on May 23, 2006 at 1:31:21 AM (# 3)

Sorry, can't help you on your original question, but ...

> How do we append code to these messages without it running?

<tr>
<td align="RIGHT">
<font face="helvetica, arial" size="2"><font class="astk">* </font><b>State</b> 
</font>
</td>
<select name="State">
<?php
$selection = array($State);
$posted = '';
if(isset($_POST['submit2'])) {
 $posted = $_POST['State'];
}
foreach ($selection as $key => $value){
if ($key == $posted) {
 echo '<option value="' . $key . '" select="selected">' . $value . '</option>';
 }
}
?>
<option>AK</option>
<option>AL</option>
<option>AR</option>
<option>NE</option>
<option>NH</option>
<option>NJ</option>
<option>WV</option>
<option>WY</option>
<?php
echo '</select>';
?>
</td>
<td width="216" valign="middle" align="left">
<?php
if ((isset($_POST['submit2'])) && (($_POST['State']) == "0")) {
 echo "Please include your State.\n";
}
?>
</td>
</tr>

BTW, looks like you've got a closing </td> tag in the middle there, without an opening <td> tag.

Also, the <font> tag is deprecated now - try <span class="astk"> instead.


philcha on May 23, 2006 at 7:57:18 AM (# 4)
This message has been edited.

If you redisplay the page for error correction, you should re-instate all the user's inputs.

In the case of select, that means adding the attribute "selected" to the option the user chose first time round. Suggest you search the web for a PHP function / class which will build a select and mark as "selected" the entry with the specified value, e.g.
$selectBlock = buildSelect($array, $name, $id, $cssClass, $selectedValue);


Bunce on May 24, 2006 at 2:06:38 AM (# 5)

Or... use ASP.Net where it does it automatically.

Wait - no - we can't recommend that because its an extra layer of abstraction... phhh.


MHenke on May 24, 2006 at 2:38:37 AM (# 6)

> Or... use ASP.Net where it does it automatically.
Of course, but not automagically, it's part of the framework, where some nice guys/gals from MS have implemented it.
I'm quite sure a similar functionality could be implemented in PHP, resp. I'm quite sure that this is already been done.

ATTENTION: This would be also nasty abstraction, that is, it'll will abstract you from filling the form fields by hand. I'm not sure if you want this... 8)


Bunce on May 24, 2006 at 5:23:41 AM (# 7)
This message has been edited.

>> Of course, but not automagically, it's part of the framework, where some nice guys/gals from MS have implemented it.

What is that supposed to mean? So what??

* It is a *feature* of the platform. Just like platform *X* has feature *Y*
* It just works.
* Magic / Automagic / Feature / Common Sense - call it what you want.
* It just works.
* You don't need to do anything.
* It just works.
* You don't need to install anything.
* It just works.
* You don't need to write code over and over to perform repetitious functionality that the coder shouldn't have to worry about.
* It just works.

>> it'll will abstract you from filling the form fields by hand.

Huh? They've already filled it in once?? Why should they, or the coder, have to fill it in again???

Face it, despite MS' negatives, they've come up with an excellent feature. Everyone else wishes they'd thought of, and, implemented it first. They didn't.


Long live abstraction!


MHenke on May 24, 2006 at 7:19:52 AM (# 8)

Ho hum, get up on the wrong side of bed, Bunce? Temporary SOHF?

However, for the peace of mind:
I neither meant to query the usefulness of that feature, nor to hurt your MS feelings.

What I want to say (and I think one could see that, if one isn't prejudiced with the assumption of an anti-MS statement) is, that this feature isn't anything that is intrinsic to any web technology, so that you can simply "use" it (via HTML, JavaScript or whatever).
It's a doubtless usefull feature, for any web application programming platform, but it has to be implementet by means of that platform. MS has done so in ASP.NET. That's wise (no irony), thank you, MS (teasing).
I just wanted to point out that there's no reason to change platform for that. It's no rocket since to re-initialise form fields for subsequent page calls. Each web application framework should provide support for it (and most of them do, MS has no patent here AFAIK).
I just wanted to express my assumption that there probably is support within PHP for that very feature. And if not build in, that somebody already has done it as [however_they_name_reusable_components_in_PHP].

I just wanted to say that re-filling form fields by hand is by no means desirable, nor to implement it on a per-page basis.
I just wanted to say that it's by all means desirable to disburden the user (and, to some extent, the developer) from that.
I just want to say that there's a thing called irony.

I feel very sorry for the inconvenience and hope that you may can convince scwilson to switch to ASP.NET.

 

 

To the dark side of the web...    MWUUUHAAAHAAAAA!!!!!!


Earlier Replies | Replies 2 to 8 of 8 | Later Replies
Goto Page: 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.