gebeer Posted October 6, 2014 Share Posted October 6, 2014 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 More sharing options...
kongondo Posted October 6, 2014 Share Posted October 6, 2014 Between them, don't your form fields have different names? $input->post->nameofield should then work irrespective of form, I would think... Link to comment Share on other sites More sharing options...
gebeer Posted October 6, 2014 Author Share Posted October 6, 2014 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 More sharing options...
kongondo Posted October 6, 2014 Share Posted October 6, 2014 Does each form have its own submit button or you are using one button for all three? Link to comment Share on other sites More sharing options...
gebeer Posted October 6, 2014 Author Share Posted October 6, 2014 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 More sharing options...
kongondo Posted October 6, 2014 Share Posted October 6, 2014 (edited) 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 October 6, 2014 by kongondo 1 Link to comment Share on other sites More sharing options...
gebeer Posted October 6, 2014 Author Share Posted October 6, 2014 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 3 Link to comment Share on other sites More sharing options...
kongondo Posted October 6, 2014 Share Posted October 6, 2014 Glad you solved it. So, your submit button didn't have a name....been there ... 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now