Solved

Sorting form elements

Posted on 2002-06-04
5
230 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
Comment Utility
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
Comment Utility
I want to output the values according to the sort order.
0
 
LVL 5

Accepted Solution

by:
Hamlet081299 earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
That's exactly what Iwant! Thanks!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now