1

I want to create 2 forms in a view. Only 1 form is visible. The another one is hidden.

Hence, I want to have only 1 submit button for both form.

Code:

<?php echo $this->Form->create('Payment', array('type' => 'post', 'url' => 'https://uat.pbbank.com/payment/dpayment.jsp')); 
echo $this->Form->hidden('merchant_id', array('value'=>'3242', 'name'=>'merchant_id', 'id'=>'merchant_id')); 
echo $this->Form->end(__('Submit')); ?>

<?php echo $this->Form->create('Payment'); 
echo $this->Form->hidden('merchant_id', array('value'=>'3242', 'name'=>'merchant_id', 'id'=>'merchant_id')); 
echo $this->Form->end(__('Submit')); ?>
6
  • 1
    can you share your code ? what have you tried? Commented Apr 15, 2014 at 8:43
  • I do not believe this is possible. I would suggest having a submit button per form and using javascript to submit both forms on click. Commented Apr 15, 2014 at 8:48
  • 1
    For most situations just having hidden input fields in a single form will suffice, post your code and give some insight into the purpose of the dual forms. Commented Apr 15, 2014 at 8:49
  • @Zeeshan I already update the question. I want 2 form, will insert almost same data, but go to different action. 1st action will save the data to my database. 2nd will bring the data to payment gateway. Commented Apr 15, 2014 at 9:15
  • @DavidYell yes yes. i can use that method also. you have any example for that? Commented Apr 15, 2014 at 9:17

2 Answers 2

4

The best way to achieve this would be with Ajax, or JS/Jquery.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#submit").click(function () {
            $.post($("#addToDB").attr("action"), $("#addToDB").serialize(),
              function () {
                  alert('Add to Database submitted');
              });

            $.post($("#paymentGateway").attr("action"), $("#addToDB").serialize(),
              function () {
                  alert('Payment Gateway submitted');
              });
        });
    });
</script>

The form:

<form id="addToDB" action="addtodatabase.php" method="post">
    <input type="button" id="submit" value="Submit" />
</form>

<!-- Hidden form for payment gateway -->
<form id="paymentGateway" action="paymentgateway.php" method="post">
    <!-- Payment gateway input fields -->
</form>

Clicking the button with id="submit" calls function to post both forms by form id.

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

Comments

0

you better wrap your form data and send your request with ajax to (https://uat.pbbank.com/payment/dpayment.jsp) and your action normal click event.

1 Comment

hi what did you mean by wrap the form? sorry i still new. hee

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.