0

I'm programming in a language called pike, which is an interpreted, object-oriented, dynamic programming language with a syntax similar to C. The pike code is used to generate HTML and javascript.

Now to my problem. I have a form called formularet and a submit button for each language. What I want to do is pass the language lang as an argument when the form is submitted. I thought this could be achieved by using a hidden input, but whenever any submit button is pressed, lang is set to all the languages instead of just the one which button was pressed. This is basically the relevent code (languageOrder is an array with all the languages):

res+= "<form name=\"formularet\" action=right.html method="POST">"

foreach(languageOrder, string lang) {
    res+= "<input type=hidden name=lang value=\""+lang+"\">\n"
      "<input type=submit name=a2 value=\"Save\">&nbsp;"
}

Any ideas on how to just pass the language for the button that was pressed?

molundb
  • 484
  • 1
  • 4
  • 18
  • Have you tried wrapping form tags around all of the buttons (doing so in the foreach loop) - so you have lots of forms rather than them all in the one form? Otherwise when you submit the main form all data gets posted. – Simon Pollard Oct 04 '16 at 09:54

1 Answers1

0

There is no relationship between the button and the hidden input.

If you want to send specific data for a particular submit button, then encode that data into the submit button:

<button name="lang" value="en">Save</button>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • But the submit button already has a value. I've thought about adding the language to the value like: `" "` But I'd rather have it as 2 separate variables. Is that possible? – molundb Oct 04 '16 at 10:13