Jump to content

Recommended Posts

I'm trying to make an OOP form handler but not having much success.  I've done some detective work on the bug and have broken the code down to it's simplest form and it still doesn't work:

 

<?php
// ayam_userInput.php
// This class directs and/or handles user input from any forms
// on the site

class userInput {
function userInput() {
               header ("Location: http://www.MYDOMAIN.com/testpage.php");
               }
        }
?>

 

So if I submit a form with the action being to this script in a different file, it should send me straight to the page in the header.  It doesn't, it actually points my browser to the page of the file (/ayam_userInput.php) and of course, it's blank.  The actual code has some form handling, but if I can't even get past the class constructor...grief.  Am I doing something wrong?  Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/208140-problem-with-form-handler/
Share on other sites

Just because you point your form to ayam_userinput.php, that doesn't mean your class will magically instantiate.  You still need to do that yourself.  You may want to rethink your design in any event.  You gain nothing by wrapping a header redirect in an object's  constructor.

Thanks, I added an instantiation at the end of the class and it works.  As for rethinking my design, as I said in my original post, I boiled the script down for simplicity, it actually has some form handling in the code, but erasing it did nothing to affect the error, so I snipped it out for posting on the forums.  Thanks for the help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.