dani33l_87 Posted July 2, 2014 Share Posted July 2, 2014 I have the form: <form> What name people call you: <input type="text" name="firstname" value="xxx"><br> Your favorite cars are: <input type="text" name="brand" value"yyy"> </form> Send to a php engine for processing. Insted of ($_GET["brand"]) to have only "yyy" value I want to have three values for the same input brand[0] = "yyy" brand[1] = "mini" brand[2] = "pontiac" TO work in three different links: http://($_GET["brand[0]"]).com html result: http//yyy.com http://($_GET["brand[1]"]).com Html result Http://mini.com http://($_GET["brand[2]"]).com Html resut http://pontiac.com I want to use this kind of system to implement multiple website filters in only one form and make available the link to each one aleardy withh the fillters settings, insted of going to each website and type the same filters again. This is the basic that I need make. How can I do this small script? Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/ Share on other sites More sharing options...
cyberRobot Posted July 2, 2014 Share Posted July 2, 2014 You could add 3 input fields and name them using array syntax. Here is a quick example: <?php if(isset($_GET['brand'])) { print '<pre>' . print_r($_GET, true) . '</pre>'; } ?> <form method="get"> <p>Your favorite cars are:</p> <div><label>Brand 1: <input type="text" name="brand[]"></label></div> <div><label>Brand 2: <input type="text" name="brand[]"></label></div> <div><label>Brand 3: <input type="text" name="brand[]"></label></div> <input type="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483534 Share on other sites More sharing options...
maxxd Posted July 2, 2014 Share Posted July 2, 2014 (edited) A couple options in addition to cyberRobot's suggestion come to mind. You could use a checkbox group and a per-determined list of options, which is probably the safest and most controllable method. Or you can explode the $_POST['brand'] value on a comma (or other character). This, however, leaves you at the mercy of your users and whether or not they're going to read and follow the instructions. Edited July 2, 2014 by maxxd Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483535 Share on other sites More sharing options...
Jacques1 Posted July 2, 2014 Share Posted July 2, 2014 The whole problem still doesn't make a lot of sense. You have a text field, which means the user can enter anything they want. How do you know they will enter exactly three brands? How do you know you can just append “.com” and get a valid URL? And why do you predefine the favorite brands? Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483556 Share on other sites More sharing options...
dani33l_87 Posted July 2, 2014 Author Share Posted July 2, 2014 Is not the answer what I am looking for. Jacques1, the text field is only for example, I will use radio buttons. To be more explicit, when you buy a car you have more filters: NEW & USED (for this we create radio buttons for the user to chose) There are many website (3 for example) that have a primary link: http//ebay.com http//cars.com http//auto.com For New cars the value information needed to each website it s different, for example http//ebay.com/newcars/ http//cars.com/new/ http//auto.com/newmake/ The user Select NEW (radio Buttons) and a php engine will add the above information for each link, having a predetermined information: NEW = new[0] = "newcars/" NEW = new[1] = "new/" NEW = new[2] = "newmake/" The result script for will be: href="http://ebay.com/$_GET(new[0]) ==== > http//ebay.com/newcars/ This I will want to do for every link, if is possible. I hope now everything is more clear. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483571 Share on other sites More sharing options...
Jacques1 Posted July 2, 2014 Share Posted July 2, 2014 There absolutely no reason for putting this data into the form. The purpose of the form is to let the user choose a filter. So in your case, the radio button values would be “new” and “used”. What you do with the user choice is a completely different story. In the processing script of the form, you can create as many links as you want. But you don't do this in the form. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483574 Share on other sites More sharing options...
dani33l_87 Posted July 2, 2014 Author Share Posted July 2, 2014 I don t want to do this in a form, for that I will use a script file, but how I suppose to split it? when I will get the filter Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483575 Share on other sites More sharing options...
Jacques1 Posted July 2, 2014 Share Posted July 2, 2014 There is nothing to split. As I've already tried to explain, you only need a single value for the radio buttons. In your example, the value is either “new” for new cars or “used” for used cars. After you've received the submitted data, you're free to create your links. But it's absolutely pointless to have the links as form values. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483581 Share on other sites More sharing options...
dani33l_87 Posted July 2, 2014 Author Share Posted July 2, 2014 Can you show me a short example, because I don t really understand how this should be done. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483585 Share on other sites More sharing options...
cyberRobot Posted July 2, 2014 Share Posted July 2, 2014 Where does these links come from? Do you have a database which indicates which links go with "new" and "old"? If so, you could just query the database depending on which option was checked. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483586 Share on other sites More sharing options...
dani33l_87 Posted July 2, 2014 Author Share Posted July 2, 2014 No database, because is not so much data, but yes is also a good option what you say. I try to make this simple as possible. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483594 Share on other sites More sharing options...
Jacques1 Posted July 2, 2014 Share Posted July 2, 2014 Where the data comes from is irrelevant for this problem. The point is that you do all your link logic after the user has made their choice. The user only tells you “I want used cars” or “I want new cars”. Based on that decision, you then fetch the links from an array, a database or whatever. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483595 Share on other sites More sharing options...
cyberRobot Posted July 2, 2014 Share Posted July 2, 2014 No database, because is not so much data, but yes is also a good option what you say. I try to make this simple as possible. This is a very crude example, but you could hard-code the values in an array. Then use a GET variable from a form, or wherever, to pull the corresponding links. <?php $linkArray = array( 'new' => array( 'http//ebay.com/newcars/', 'http//cars.com/new/', 'http//auto.com/newmake/' ), 'old' => array( 'http//ebay.com/oldcars/', 'http//cars.com/old/', 'http//auto.com/oldmake/' ) ); foreach($linkArray[$_GET['type']] as $currLink) { print "<div>$currLink</div>"; } ?> If the GET variable (type) is set to "new", the example code will display the new links. Otherwise, it will display the old links when set to "old". Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483599 Share on other sites More sharing options...
dani33l_87 Posted July 2, 2014 Author Share Posted July 2, 2014 I was thinking to an easier approach because they are more filters, something like: http//ebay.com/{$_GET[NEW]}/$_GET[YEAR]....etc If I use the array approach I will need to create a new php file for each filter Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483602 Share on other sites More sharing options...
Solution maxxd Posted July 2, 2014 Solution Share Posted July 2, 2014 You need to reconsider your approach. By trying to 'make things as simple as possible', you're twisting things way out of control. Consider using comboboxes for the your filters. <select name='type'> <option value='newcars'>New Cars</option> <option value='new'>New Whatever</option> <option value='newmake'>New Make</option> </select> <select name='year'> <option>2014</option> <option>2013</option> <option>2012</option> </select> <select name='color'> <option value='blue'>Blue</option> <option value='red'>Red</option> <option value='rusted'>Rusted Out</option> </select> Then you build it in php $link = "http://ebay.com/{$_GET['type']}/{$_GET['year']}/{$_GET['color']}/"; I've honestly never used ebay so I don't know if that link makes any sense at all to it, but I think it's close to what you're trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483609 Share on other sites More sharing options...
dani33l_87 Posted July 3, 2014 Author Share Posted July 3, 2014 Yes maxxd the last part is what I want: $link = "http://ebay.com/{$_GET['type']}/{$_GET['year']}/{$_GET['color']}/"; But the first part is the problem. Because in the form should be only 2 option, that will have more values in the php script. The solution will be this: <?php$linkArray = array( 'new' => array( newcars/', new/', newmake/' ), 'old' => array( 'oldcars/', /old/', 'oldmake/' )); ?> But how can I take each array and put it in the link, because in "new" they are 3 array, how can I take a specific one and add to the link $link = "http://ebay.com/{$_GET['new']}/{$_GET['year']}/{$_GET['color']}/" Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483647 Share on other sites More sharing options...
dani33l_87 Posted July 3, 2014 Author Share Posted July 3, 2014 I succeed to find the last piece of the puzzle. Thanks all for your help and patience. Quote Link to comment https://forums.phpfreaks.com/topic/289363-single-input-name-and-multiple-values/#findComment-1483664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.