Jump to content

Form elements not recognized by $input->post->submit


helmut2509
 Share

Recommended Posts

Hello,

I have a form which worked fine with when submitted by a submit button.

Then I had to replace the submit button by javascript document.myform.submit().

But since then $input->post->submit returns false albeit the $_POST array contains correctly all form values.

Any suggestions?

Update: I replaced $input->post->submit by $input->post, but now $input->post *always* returns TRUE even when there are no form elements....

 

Edited by helmut2509
Update
Link to comment
Share on other sites

Not sure I understand. If you removed the form element named 'submit' then it follows that there will be no post variable named 'submit'.

I take it you were checking $input->post->submit to see if the form was submitted. Can't you just check for another post variable for which the corresponding input is still included in your form? It could be a hidden input that always contains a value.

Link to comment
Share on other sites

5 minutes ago, Robin S said:

Not sure I understand. If you removed the form element named 'submit' then it follows that there will be no post variable named 'submit'.

I take it you were checking $input->post->submit to see if the form was submitted. Can't you just check for another post variable for which the corresponding input is still included in your form? It could be a hidden input that always contains a value.

The problem is that there are two modes: in the first mode there is no submit, the form will just be displayed (coming from another page).

So it can be totally correct, that there are no input values. Only in the real submit mode there must be input values.

Link to comment
Share on other sites

9 hours ago, helmut2509 said:

The problem is that there are two modes: in the first mode there is no submit, the form will just be displayed (coming from another page).

So it can be totally correct, that there are no input values. Only in the real submit mode there must be input values.

If you are loading the page that contains the form but the form has not been submitted then none of the form inputs will be in the post data. So that has no impact on anything you are doing with $input->post.

If the form has been submitted then the form inputs will be in the post data - a form input might be empty but there will still be a post variable for it. So you can check for the presence of any post variable, empty or not, like this...

if($input->post->my_input !== null) {
    // ...
}

Doing it this way you don't have to add anything extra to your form, but if you have several different forms with different inputs you need to adjust the test so you are always checking for a post variable that matches the name of an input if that form.

Alternatively you could add a hidden input to all your forms - for instance, you could call it 'form_page_id' and put the ID of the page containing the form in it. Then you can use the same test on every form...

if($input->post->form_page_id) {
    // ...
}

 

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...