Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting form elements

Posted on 2002-06-04
5
Medium Priority
?
281 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 dynamically set the form action using jQuery.
Suggested Courses

916 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