Mr. Jo
Mr. Jo

Reputation: 5271

Can I set a $_REQUEST variable in PHP?

I have a website programmed in PHP with WordPress. At my website I've installed a plugin named UltimateMember. In this plugin you can add a registration form which gives visitors the option to register to my page.

I have also installed a plugin named Newsletter. This plugin creates a page where user can register with double-opt-in verification to receive a newsletter.

My plan is now to remove this site and add a checkbox to the registration form. When a user wants to receive my newsletter, he can check the checkbox.

When he submit the registration, I've the ability to check if the checkbox is checked during the registration request. In this function I want to require the class from the Newsletter plugin to call a function there to send a newsletter.

In this function is a line of code where the function receives the email address (which is normally sent from the form on the newsletter page):

$email = $this->normalize_email(stripslashes($_REQUEST['ne']));

When I call the function now without the submitted form, I run into a problem because this variable will be null.

So my question, is it possible to set this $_REQUEST variable before I call the function to subscribe the user during the registration process?

Upvotes: 2

Views: 3783

Answers (3)

user10946716
user10946716

Reputation:

$email = isset($_REQUEST['ne']) ? $this->normalize_email(stripslashes($_REQUEST['ne'])) : "[email protected]";

Upvotes: 0

Emeka Augustine
Emeka Augustine

Reputation: 931

You have to check if the user actually clicked the submit button before submiting the form like so:

<php?

    if (isset($_POST['submit'])) {
      $email = $this->normalize_email(stripslashes($_REQUEST['ne']));
    }
<?

Upvotes: 0

AbraCadaver
AbraCadaver

Reputation: 78994

Either send another variable:

$other_var = '[email protected]';
$email = $this->normalize_email(stripslashes($other_var));

Or, yes, just define the $_REQUEST variable:

$_REQUEST['ne'] = '[email protected]';
$email = $this->normalize_email(stripslashes($_REQUEST['ne']));

Upvotes: 2

Related Questions