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!

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.