We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Working with native EE forms like member login and member registration forms from extensions

Developer Preview

BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

This is a three part question really…

I am working on an extension and have hit a roadblock on native EE forms and available hooks.

I’ve been trying to get the member:login_form, registration_form, and channel_entry_form forms working with it. I have been able to get everything working with the freeform addon and comment module, but these others are stumping me. Combing through the code, it doesn’t look likely for the login and registration since they are calling pre-built form templates. I was hoping there would be a hook available for login though since there was a tag pair, but I’m not seeing it.

GOAL: I want to inject a field in the form during render and check it on submission.

So ideally I would get the $tagdata from the tag pair and then parse the POST data before validation.

LOGIN FORM:

{exp:member:login_form return="site/index"}
        form here...
{/exp:member:login_form}

I just don’t see a hook for that. I was hoping. being a tag pair, that I would be able to use a hook to do what I need to like I do in the other forms.

REGISTRATION FORM:

I don’t see anything for the registration except for a link to the native registration form.

CHANNEL ENTRIES FORM:

With channel entry forms, I am able to inject the field I want using the channel_form_entry_form_tagdata_start hook like this:

function add_channel_form($tagdata, $channel_form_obj)
 {
  /**
   * Modidfy our tagdata
   */
  $tagdata = $this->add_myfield() . $tagdata;

  return $tagdata;
 }

However, when I use either the channel_form_submit_entry_start or channel_form_submit_entry_end hooks and dump the data to see what’s in there, my field is not being POST.

I feel like I am chasing my tail with this one. Has anyone else ever captured these events or know of something I am missing with any or all of these three forms?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

Are you wanting to insert a hidden field? If so, there’s the form_declaration_modify_data hook. Just append to the hidden_fields key in the $data array and return it.

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

Kevin,

Thanks, but I am wanting to create a field named and styled per the extensions settings. Default is not hidden and simply absolutely positioned off screen in an attempt to deter bot logic.

The field is not seen and does not affect the user at all. When validating against it, I am just checking against either an empty value or one of the settings in the extension settings.

Is there not a way to hook into the member login like there is for channel_form or comment_form?

Also, I am looking at the Channel_form_lib.php file now, specifically @:1344. The only thing I have been able to obtain from hooking here is a huge object that doesn’t contain any $_POST data from the channel_form. Is this due to the conversion happening @:1514?

Or am I not calling it correctly?

public $hooks           = array(
  'channel_form_entry_form_tagdata_start'   => 'add_channel_form',
  'channel_form_submit_entry_start'        => 'check_channel_form'
 );

Then in my check_channel_form: (Just testing output now)

function check_channel_form($channel_form_obj)
 {
  echo "<pre>";
  print_r($channel_form_obj);
  echo "</pre>”;
  exit;
        }

When I go look at the rendered form prior to submission, I know the first half is working properly on channel_forms because the input is there…

<input type="text" class="my_field" name="my_field" id="my_field" tabindex="-1" >

In my check_channel_form I was able to get all of the data with the global $_POST var. I was making it harder on myself than I needed for channel_forms.

function check_channel_form($channel_form_obj)
        {
              echo "<pre>";
              print_r($_POST);
              echo "</pre>”;
              exit;
        }

This still doesn’t help with the others though. 😉

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

Is there not a way to hook into the member login like there is for channel_form or comment_form?

No, not in this way.

The only thing I have been able to obtain from hooking here is a huge object that doesn’t contain any $_POST data from the channel_form. Is this due to the conversion happening @:1514?

Shouldn’t be due to that, it looks like that’s a convenience to developers who are accessing things via POST to provide some consistency for fieldtype naming conventions. The Channel Form library object we send you in the hooks isn’t intended to contain POST data as it is available in the global $_POST variable. Is there a reason you cannot access your data through that?

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

Sorry, I edited the above instead of adding another comment. Yes, I already realized the second part. Thanks.

So essentially, I am left with either:

a) using the form_declaration_modify_data hook and appending the field I am using as a hidden field

or

b) recreating the wheel (which I am not going to do) 😉

One of those two is my option availability for member_login.

Am I left with abandoning the option for registration forms?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

So essentially, I am left with either:

Yes, presently.

Am I left with abandoning the option for registration forms?

I would think the registration form would have the same options assuming the {exp:member:registration_form} tag is used.

What exactly are you trying to accomplish with an off-screen text field? We may be able to add some extra hooks but would like to understand the problem you’re trying to solve first.

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

No need for that. Thanks Kevin. I just want to make sure I cover as many bases as possible.

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

Kevin,

One thing though. I have noticed this morning that I am unable to catch the $_POST data from the

{exp:member:login_form}

using the ‘member_member_login_start’ hook. Is there a way to capture the $_POST data from this that I am missing?

😉

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

So if you var_dump($_POST);exit; or something similar, the variable is empty?

😉

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

Correct…

This:

public $hooks           = array(
  'member_manager'      => 'add_member_login',
  'member_member_login_start'    => 'check_member_login',
        ....


        /**
  * Member Login Validation
  *
  * Validate the Hon:EE Bee field on a member login form
  *
  * @return void
  */
 function check_member_login()
 {
  var_dump($_POST);
  exit;
        }

Just submits the form…

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

Sounds like the hook isn’t being fired at all if exit isn’t stopping the execution. I’d make sure you have the hook correctly registered in the extensions table. If that all looks correct, show me the template code you’re using to generate the login form.

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

See image…

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

I used the demo code from the docs…

                                    [code]<h1>MEMBER LOGIN FORM</h1>
                                    {exp:member:login_form return="site/index"}
                                        <p>
                                            <label>Username</label><br>
                                            <input type="text" name="username" value="" maxlength="32" size="25">
                                        </p>
                                        <p>
                                            <label>Password</label><br>
                                            <input type="password" name="password" value="" maxlength="32" size="25">
                                        </p>
                                        {if auto_login}
                                            <p><input type="checkbox" name="auto_login" value="1"> Auto-login on future visits</p>
                                        {/if}

                                        <p><input type="checkbox" name="anon" value="1" checked="checked"> Show my name in the online users list</p>
                                        <p><input type="submit" name="submit" value="Submit"></p>
                                        <p><a href="{path='member/forgot_password'}">Forgot your password?</a></p>
                                    {/exp:member:login_form}[/code]
       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

I’ve just used the exact same template code and make an extension to call the exact same method and it’s properly dumping POST and halting execution, so I cannot reproduce this issue. Are there any other hooks in your install using member_member_login_start?

       
BBDOKC's avatar
BBDOKC
14 posts
9 years ago
BBDOKC's avatar BBDOKC

This is it right here.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.