Jump to content

Custom Registration Page


Raj
 Share

Recommended Posts

Hello,

Hope I am in the right place.

For quite sometime now I have been trying to setup a personal website and as part of this process I am trying to setup 'User Registration Page'.

I am very new to ProcessWire and still on the learning curve; after going through multiple tutorials I somewhat was able to setup the page.

However, facing issue while registering the user...basically I have a custom code that get's called via java script code, if the validations passes.

While on the other page I try to reference the wire () function, I am encountering 'Using $this when not in object context' error.

Here is the complete code... Any help in resolving this is much appreciated.

<?php namespace ProcessWire;

// Register Page
// +-------------------------------------------+
// | Copyright (C) 2016, http://bluemine.co.in |
// +-------------------------------------------+
// +-------------------------------------------+
// | Author: Rajib Dey                         |
// +-------------------------------------------+

session_start();

error_reporting(E_ALL);

include('func.php');
require('/usr/share/php/libphp-phpmailer/class.phpmailer.php');

$wire = $this->wire();

$input = wire('input');
// $sanitizer = wire('sanitizer');
// $roles = wire('roles');
$security = $_SESSION['vercode'];

print_r($_SESSION);

$errors = "";

// check if the form content has been submitted
if($input->post->submit) {

    echo $security;

    //instantiate variables taking in the form data
    $full_name = $sanitizer->text($input->post->name);
    $email = $sanitizer->email($input->post->email);
    $uname = $sanitizer->username($input->post->username);
    $pswd = $input->post->password;
    $cpswd = $input->post->passwordConfirm;
    $sec = $sanitizer->text($input->post->sec);

    if($pswd!=$cpswd)
    $errorMessage = "<br><p class='alert alert-danger alert-error'><strong>Error!</strong> Passwords doesn't match!.</p>";

    // create activation code
    $activation = md5($uname);
    $activation_code = $config->httpHost."/activation/?user=".$uname."&hash=".$activation;
    // echo $activation_code;

    // username vaidation
    if(strlen($uname) != 0){
        if(username_validation($uname) == 0) {
                $username->error = " ";
                // $out .= "Sorry that username is already taken!";
?>
        <div class="alert alert-warning alert-dismissable fade in">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
            <strong>Warning!</strong><?php echo " Sorry that username is already taken. Please retry with a different ID.";?>
        </div>

<?php
                }
            else {
        
            $out = "Thank you for registering!<br><br>";
            $out .= "An email has just been sent to " . $email . " with the url to activate your account";

            /*
            * In this example I am using phpmailer to send the email
            * I prefer this, but you can also use the mail() function
            */
        
            $mail = new PHPMailer();

            $mail->IsHTML(true);

            $mail->From     = "admin@bluemine.co.in";
            $mail->FromName = "Register @ BlueMine";
            $mail->AddAddress($email);
            $mail->AddReplyTo("admin@bluemine.co.in","Register @ BlueMine");

            $mail->Subject  = "Registration";
            $mail->Body     = "
            Hello " . $full_name. ", <br>" .
            "Thanks for registering at BlueMine - Your Digital Library.  To activate your account click the link below! <br><br>"
            . "Activation Link: <a href='http://".$activation_code."'>".$activation_code."</a>";

            $mail->send();
            print 'success';
        }
    }
}

 

Edited by LostKobrakai
added code block
Link to comment
Share on other sites

2 hours ago, fbg13 said:

$wire = $this->wire();

$this is only used inside a class.

http://stackoverflow.com/questions/1523479/what-does-the-variable-this-mean-in-php

Thank you fbg13 for pointing me to the appropriate instruction.

In that case could you suggest how should I make this work please?

$input = wire('input');
$sanitizer = wire('sanitizer');
$roles = wire('roles');
Link to comment
Share on other sites

A couple of examples

Outside function and class

$page;
$pages;
$sanitizer;
$input;
$modules;
$templates;
$fields;
$user;
$users;
$log;
$session;
$config;

Inside function

wire('page');
wire('pages');
wire('sanitizer');
wire('input');
wire('modules');
wire('templates');
wire('fields');
wire('user');
wire('users');
wire('log');
wire('session');
wire('config');

Inside class

$this->wire('page');// also $this->page;
$this->wire('pages');// -ditto-
$this->wire('sanitizer');// -ditto-
$this->wire('input');// -ditto-
$this->wire('modules');// -ditto-
$this->wire('templates');// -ditto-
$this->wire('fields');// -ditto-
$this->wire('user');// -ditto-
$this->wire('users');// -ditto-
$this->wire('log');// -ditto-
$this->wire('session');// -ditto-
$this->wire('config');// -ditto-

Welcome to PW and the forums :)

You may also want to use PW core email class + read up on the recent vulnerability regarding PHPMailer Class (if you haven't already)

  • Like 1
Link to comment
Share on other sites

9 minutes ago, kongondo said:

A couple of examples

Outside function and class


$page;
$pages;
$sanitizer;
$input;
$modules;
$templates;
$fields;
$user;
$users;
$log;
$session;
$config;

Inside function


wire('page');
wire('pages');
wire('sanitizer');
wire('input');
wire('modules');
wire('templates');
wire('fields');
wire('user');
wire('users');
wire('log');
wire('session');
wire('config');

Inside class


$this->wire('page');// also $this->page;
$this->wire('pages');// -ditto-
$this->wire('sanitizer');// -ditto-
$this->wire('input');// -ditto-
$this->wire('modules');// -ditto-
$this->wire('templates');// -ditto-
$this->wire('fields');// -ditto-
$this->wire('user');// -ditto-
$this->wire('users');// -ditto-
$this->wire('log');// -ditto-
$this->wire('session');// -ditto-
$this->wire('config');// -ditto-

Welcome to PW and the forums :)

You may also want to use PW core email class + read up on the recent vulnerability regarding PHPMailer Class (if you haven't already)

Thank you Kongondo. :)

Let me find out how to use these - best way to learn ;) ....meanwhile can you point me to the PW core email thing that you mentioned...

On thing to mention - At the very first instance I am awed by the response time and helpful attitude of the members... Thumbs Up Guys... :)

Link to comment
Share on other sites

Thank you Kongondo. :)

I am still stuck with this...not able to get my head around, not sure where I am failing. :(

Would you mind helping my out here with the code mentioned initially. How do I make those variables an instance of wire?

Link to comment
Share on other sites

Those variables are always  available to you. You don't need to do anything special. The one care you should take is not to overwrite them.

# outside a function
// will echo the integer value of an input called 'id' that was sent via $_GET
echo (int) $input->get->id;
// will echo the sanitized value of an input 'title' that was sent by $_POST
echo $sanitizer->text($input->post->title);

If in a function then:

# inside a function
// will echo the integer value of an input called 'id' that was sent via $_GET
echo (int) wire('input')->get->id;
// will echo the sanitized value of an input 'title' that was sent by $_POST
echo wire('sanitizer')->text((wire('input')->post->title));

Of course, if inside a function or class, and you will be using lot's of wire('input'), then you can assign that to a variable at the start of the function/class method, i.e.

$input = $this->wire('input')->post;// #1. if expecting only post variables
// or
$post = $this->wire('input')->post;
$input = $this->wire('input');// if expecting either get or post or cookie
// or
$input = wire('input');// you get the idea
// then, in relation to #1 above, you can do
$id = (int) $post->id;

If you have a specific issue, please address it. What is working? What is not? etc...:)

http://processwire.com/api/variables/

  • Like 2
Link to comment
Share on other sites

Unless you are in a PHP Class, you should not be using $this at all, as pointed out earlier. You don't need this line at all:

//$wire = $this->wire();// this is not needed in your context

It is a good idea, to get a few basic PHP tutorials under your belt before starting to use ProcessWire :). Given that you are setting up something as important as a user registration feature, I highly recommend you have a look at such tutorials. 

  • Like 1
Link to comment
Share on other sites

When I do this , "$input = wire('input');" I get the error - Call to undefined function ProcessWire\wire()...

What am I missing? :(

I completely agree with you Kongondo and I am doing that simultaneously...actually I am a no coder, long ago I did my software engg. but could not get any job in this line....so forgot all those concepts, trying to recall mystic memories....The site that I am trying to setup now is just out of my passion for networking and coding...hope I can make something good for my family and friends... :)

Link to comment
Share on other sites

The code in your first post, is that in a template file or elsewhere? Not necessarily the cause of the error, but am wondering whether you are in a function context or not. 

Edit: These may be of relevance to you...

https://processwire.com/talk/topic/12272-308-call-to-undefined-function-because-of-compiled-files/
https://processwire.com/talk/topic/12214-templates-namespace-and-modules-problem/
https://processwire.com/talk/topic/11815-undefined-variable-pw-3-wirerenderfile-use-compiled-file/
https://processwire.com/talk/topic/13500-variables-scope-in-included-files/
https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#compiled-template-files
 

Edited by kongondo
added a couple of potentially relevant links
Link to comment
Share on other sites

Thank you guys....sorry for the late response, was held up with some stuffs.

require_once('...') did the trick finally...had to key in the complete URL - probably miss-configuration of php.ini file....

Now while I have changed to WireMail I am getting the error "Error:     Uncaught exception 'ProcessWire\WireException' with message 'Method WireMailSmtp::IsHTML does not exist or is not callable in this context"

What does this mean?

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...