Jump to content

Multiple forms processing on same page


gebeer
 Share

Recommended Posts

Hi,

I process 3 different forms with 3 different ids/names in the same template.

Now my post values seem to get mixed up between the forms.

What I tried is

$profileForm->processInput($input->post);
 
    if ($profileForm->id == "profile-form") {
        //do something
    }

Analogue with the other 2 forms. But that didn't help.

In pure PHP I would use $_POST['profile-form']. But I want to stick wit the PW API.

There I found $input->post["name"].

var_dump($input->post["profile-form"]) is null.

How can I access and process only the data from my profile-form form using the API?

EDIT:

Also var_dump($input->post) does not reveal anything about the form id

Link to comment
Share on other sites

I tried that, too.

For example I have email fields in 2 forms. Before they both had name "email".

After renaming one of them to "profilemail", I still get unwanted effects on the email field and vice versa.

Link to comment
Share on other sites

Each form has its own.

I meanwhile checked that post data is only available for the form that was submitted.

So the problem seems to be in my form processing logic somewhere.

I will first try myself and find that problem and then report back here.

Thank you so far kongondo.

Link to comment
Share on other sites

I modified and quickly tested this example from SO: http://stackoverflow.com/questions/7849478/how-to-process-multiple-forms-using-one-php-script and it works fine...(but haven't tested with processInput). Make sure your PHP/PW form logic is at the top of the template file btw...

<?php 

  if (isset($input->post->submitForm2)) {

    echo '<pre>';
    print_r($input->post);
    echo '</pre>';
    echo 'Yes';
  }

?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm1" />
</form>

<form action="" name="form2" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm2" />
</form>

<form action="" name="form3" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm3" />
</form>

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

Thanks again. That helped.

I'm using the API to build my forms. They have different names and ids already.

When I create the submit button like

// submit button!
$submit = $modules->get("InputfieldSubmit");
$submit->label = " ";
$submit->attr("value","Save Changes");
$submit->attr("id+name","submitprofile"); //Notice submitprofile here - that did the trick
$submit->attr("class","btn btn-success");
$profileForm->append($submit);

and check if data should be processed with

if ($input->post->submitprofile) {
    //do processing here
}

It is working and other form submissions do not interfere anymore :)

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...