Jump to content

Combine a checkbox and Textfield in array


denniskarpes

Recommended Posts

Hello,

 

I want to create an order form where people can order shirts with sizes and quantities.

So in 1 form you have a column where people can check the size and after that the quantities. (see below the form)

As result i want after pressing submit and selecting for example 3 shirts Large and 1 small:

S=1, M=0, L=3, XL=0, XXL=0

 

echo "<form method=\"post\" action=".$PHP_SELF.">
  <label>aantal
  <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"S\">S<br />
  
  <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"m\">m<br />
  
  <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"l\">l<br />
  
  <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"XL\">XL<br />
  
  <input name=\"textfield[]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input class=\"option2\" id=\"option2\" name=\"maat[]\" type=\"checkbox\" value=\"XXL\">XXL<br />
  
  </label>
<input type=submit value=Select></form>"; 

 

i hope you can help me with it.

 

thanks in regard!

try

echo "<form method=\"post\" action=".$PHP_SELF.">
  <label>aantal
  <input name=\"textfield[s]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input name=\"textfield[M]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input name=\"textfield[L]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input name=\"textfield[XL]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <input name=\"textfield[XXL]\" type=\"text\" size=\"4\" maxlength=\"3\">
  <</label>
<input type=submit value=Select></form>"; 

and on submit page print_r($_POST['textfield']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.