Solved

Sorting form elements

Posted on 2002-06-04
5
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

628 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