2

How to post multiple form in one Html page to a PHP page and parse all the form elemnts in PHP Page on a single button click on the Html posting page any idea thanks in advance

    <form id="form1" name="form1"action="abc.php" method="post" name="hoursregistrationform" class="form-horizontal">
    <div class="smallBox">
    <div class="smallBox_day">
      <div class="control-group">
          <label class="control-label" for="monday">Monday:</label>
          <div class="controls">
              <input type="text" id="monday" name="monday" placeholder="hours">
              <select>
                  <option value="" selected>code</option>
                  <option>2</option>
                  <option>3</option>
                  <option>4</option>
                  <option>5</option>
              </select>
              <a id="cloneButton" href="#"><img src="images/button_plus_pink.png" alt="+"></a>
          </div>
      </div> 

    </div>
    <a id="cloneButton" href="#"><img src="images/button_plus_pink.png" alt="+"></a>

    </div>
    <input name="submit" type="button" value="submit">
    </form>
    <form id="form2" name="form2"action="abc.php" method="post" name="hoursregistrationform" class="form-horizontal">
    <div class="smallBox">
    <div class="smallBox_day">
      <div class="control-group">
      ...............................
              <a id="cloneButton" href="#"><img src="images/button_plus_pink.png" alt="+"></a>
          </div>
      </div> 

    </div>
    <a id="cloneButton" href="#"><img src="images/button_plus_pink.png" alt="+"></a>

    </div>
    <input name="submit" type="button" value="submit">
    </form>.................................................
.................
5
  • provide what you have done? Commented May 31, 2013 at 9:39
  • 2
    bundle the data together e.g. formdata[form1]=$('#form1').serialize(); formdata[form2]=$('#form2').serialize(); $.ajax({data:formdata, ....}); so when your process it, $_POST['form1'] contains form1's data Commented May 31, 2013 at 9:45
  • will you @waygood explain me more Commented May 31, 2013 at 9:49
  • $('#form1').serialize(); will bundle the data together from the form with id="form1". Since the process should know that this is from form1 we should put it in the formdata array with an index of 'form1'. We can then use ajax to submit the data, or we can construct a new form with jquery and submit it to the php script. The php script should then cycle through $_POST to process each form individually. Commented May 31, 2013 at 9:58
  • why you need second form though you are not submitting any value and you given name two time its should be one only Commented May 31, 2013 at 10:23

2 Answers 2

2

You can use one global form, instead of many small forms

Sign up to request clarification or add additional context in comments.

3 Comments

but the requirement is to have multiple forms
@SamuelJMathew Where does that requirement come from. It seems a bit weird.
you can do it with single form
0

You can use one global form with the aid of Jquery dynamic form to satisfy your need Jquery Dynamic Form:by clicking here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.