Solved

Sorting form elements

Posted on 2002-06-04
5
259 Views
Last Modified: 2011-09-20
If I pass form elements to a script and I want to sort specific ones based on the order of the hidden sort tag:

<input type="HIDDEN" name="sort" value="order:realName,address,address_,city,state,zip,...

How would I do this? The names in the sort are the names of selected hidden inputs I want to sort that were passed!
0
Comment
Question by:sargento
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7055200
Can you give some more details?

Do you mean that you want to output the values entered in the form according to the specified order?  Or are you trying to create a form with the inputs in that order?
0
 

Author Comment

by:sargento
ID: 7055213
I want to output the values according to the sort order.
0
 
LVL 5

Accepted Solution

by:
Hamlet081299 earned 100 total points
ID: 7055224
Here's a simple example that MAY be what you are after.

You will notice that the hidden fields are in a nonsense order, but when you click the Submit button they are listed in the order specified.

<form action='test.php'>

<input type="hidden" name="zip" value="2000">
<input type="hidden" name="realName" value="John Smith">
<input type="hidden" name="address_" value="Belrose">
<input type="hidden" name="city" value="Sydney">
<input type="hidden" name="state" value="NSW">
<input type="hidden" name="address" value="12 Main Street">

<input type="hidden" name="sort" value="realName,address,address_,city,state,zip">

<input type="submit">
</form>

<?php

$order = explode(',', $sort);
foreach ($order as $varname) {
    $value = $$varname;
    echo "$varname = $value<br>\n";
}

?>
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7055229
p.s. I dropped the "order:" from the start of the sort value.  I don't know if this is needed.  If it is then just strip it off before doing the explode().
0
 

Author Comment

by:sargento
ID: 7055238
That's exactly what Iwant! Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question