I'm working on getting joomla registration form values that user enters
at the time of registration. After two days of searching I reached to the
file Joomla2.5.7\components\com_users\controllers\registration.php. In the register() method I
tried to echo $data and $requestData variables but didn't see any output, on registering a new entry. I also tried to echo javascript but was unsuccessful. I'm trying to connect joomla database with my own database, so that whenever new user registers , he is also registered to my website. How can I get the registration form variables, any kind of help is really appreciated.
Ty this
On registration controller you can find a function call to model like this
$return = $model->register($data);
after that just
echo "<pre/>";
print_r($data);
Also in the registration model
components\com_users\model\registration.php
register() method is defined you can check that for more info.
In addition if you want to add the users info to the other DB like your website DB.
The best place to write mysql query is :
// Store the data.
if (!$user->save()) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}else{
//Your custom mysql query to other DB or tables
}
find the above section in the registration model inside register()method.
Hope this may solve your problem..
I hope this tutorial helps you. You will find it explains the process of joomla registration form very well.
http://youtu.be/2AyCzb2vTaU
Related
I need to be able to store some custom session variables that exist for the custom, regardless of whether they're signed in or not, but for some reason my sessions keep deleting themselves.
I have used this example to help me add my session code in.
Here's my code
Block file
<?php
namespace MyVendor\MyModel\Block;
use Magento\Framework\View\Element\Template;
class ProductSearch extends Template {
protected $_customSession;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Customer\Model\Session $customSession,
array $data = []
){
parent::__construct($context, $data);
$this->_customSession = $customSession;
}
//Get the car model from the session
public function getSessionCarModel(){
return $this->_customSession->getCarModel();
}
//Unset the car model from the session
public function unsetSessionCarModel(){
return $this->_customSession->unsCarModel();
}
}
and heres the top of my template file that sorts the session when its loaded
productsearchbanner.phtml
<?php
//If the user has selected a new model, unset our session then start a new one
if(isset($_POST['modelSelect'])){
//Unset the other sessions
$block->unsetSessionCarModel();
//Set the model session
$block->setSessionCarModel($_POST['model']);
}
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
?>
The way the code is meant to work is, if the $_POST['modelSelect'] is set, the user has come from the model select page so we need to start the process again and reset their session, but if they haven't, the session should remain the same.
My issue is, when I come from the model select page, my session variable shows in the var dump no problem, as shown below.
But then as soon as I go to any another page on my site (for example, the homepage) and then back to the product search page, the session has cleared?
What am I doing wrong? Why does my session clear every time I load a page? I just need to be able to set the equivalent of $_SESSION['carModel'] and it be persistent for that user, regardless of if they're logged in or not, or where on the site they go.
Can someone please point me in the right direction?
Setting sessions in Blocks or Template files is a problem. This is because of full page cache. Magento's execution cycle changes with FPC turned on.
Controllers or Models are the best places to update session data.
But, if you need to update your session in a template / block, then you can call a custom action via AJAX and have it update the session info.
Generally, one would need to take these steps in Magento 2:
create a new controller / action pair in an existing or a new module, that would update session info. This controller should ideally accept AJAX requests only.
have a template rendered in container before_body_end and toss some jQuery code in there, that will query the controller / action pair to have the session info updated.
This way, whenever the page will load, it will trigger a session update ( or you can have it trigger on any other event, say when a user clicks something etc. ) by requesting your controller / action, say, /my-module/my-controller/my-session-updater-action.
I need to delete customer addresses programmatically, but I didn't find a function to do that.
$recordedAddresses = array();
foreach ($customer->getAddresses() as $address)
{
$recordedAddresses = $address->toArray();
}
I already took the addresses' collection as showed above, I just wanna delete them by id.
Curiously I didn't find examples but using API.
Could someone gimme a hand with that?
Somehow Magento keeps empty entities after using $address->delete() in my case. There were empty addresses on account preventing admin from saving the customer form when using this method.
Only way I've found to actually remove the address from user account is by changing the protected $_isDeleted flag to true:
$address = Mage::getModel('customer/address')->load($addressId);
$address->isDeleted(true);
Hope it saves some time for anyone who will stumble uppon same Magento behaviour.
Have a look at the Mage_Customer_AddressController controller class and deleteAction() method. Essentially all you need to is load the address by it's id:
$address = Mage::getModel('customer/address')->load($addressId);
and then delete it:
$address->delete();
delete() is a standard method you can run against all models (see Mage_Core_Model_Abstract), you can also set the _isDeleted flag and call save() which will have the same result.
I have a payment gateway integrated on my website. When user is done with payment he/she is redirected to a particular page say www.example.com/redirect. I want to prevent users from directly entering this url (www.example.com/redirect) in address bar and access the page. I want it asap.
Actually the page is protected from guest users but if logged in user types that url then it will redirect him to that page and hence the payment option will be skipped. I want the user must pay the amount first and then redirected to this page.
Hard to answer precisely since you only give a non-joomla url as an example, but at the top of every Joomla script is the following line:
defined('_JEXEC') or die( 'Restricted access' );
You obviously can't prevent a user from typing in the url, so this will at least detect if a session is already in place. If the user isn't in an active Joomla session, this will fire and prevent access. You could easily adapt it to do whatever you want to happen for your requirement, depending on whatever you have to check with, i.e. if the referrer is your payment gateway, etc.
I had a similar desire. I wanted the page to only display if the users was logged in and if they had filled out the order entry page.
What I decided to do was check to see if there was data in the POST.
controller/place_order.php (snipet)
public function submitOrder()
{
$post = JRequest::get('post');
$model = $this->getModel();
if($post != null && $post != ''){
if($model->placeOrder()){
}
}
JRequest::setVar('layout', 'submitOrder');
parent::display();
}
This prevents the task from executing my placeOder function anything in the model. Then I just add something similar to the submit order page. In your case "redirect".
view/place_order/tmpl/submitOrder.php (snipet)
defined('_JEXEC') or die('Restricted access');
$user =& JFactory::getUser();
if ($user->guest) {
echo "<p>You must login to access this page.</p>";
}
else if($_POST == "" || $_POST == null){
echo "<p>You can not directly access this page.</p>";
}else {
//Your order was submitted successfully HTML (don't forget to close it at the bottom ;)
There are a lot of ways you could do it... you probably don't even need to check in the controller if you don't want to but I do to save on time. With out seeing your code it's hard to tailor the answer but if you grasp the concept here it should help (I hope...).
You might also want to check out this page from Joomla on authorization and privileges.
this should be done in your component's base controller (controller.php). if you look at this code snippet:
// Check for edit form.
if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403,
JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}
this block of code is present in most of core components intended to do exactly what you want. how ever how this actually dos what it does is explained through the $this->checkEditId() function. I hope you are familiar with the JControllerForm class and if you are not check out the API. because creating an edit id for a page and "authorizing user for access to a specific page based on his last page" is done by JControllerForm.
I want to extend Ion Auth to only allow certain email addresses to register.
I'm fairly sure I could hack this together and get something working, but as a newbie to codeigniter and ion auth I wish to find out if there is a "proper way" to be doing what I need?
For instance can I "extend" ion auth (so I can update ion auth core files without writing over my changes?).
I noticed there are also hooks including this one (in the register function):
$this->ci->ion_auth_model->trigger_events('pre_account_creation');
Where do these resolve and can I use this one in order to intercept registrations from email addresses which don't match a list of those I wish to register?
If so, how would I do it? I would need access to the $email variable from the register() function.
Or is it just a case of altering the base code from ion auth and not updating it in the future?
Thanks for any help you can give me. Don't worry about the email bit, I'm capable of working out whether an email address matches the required email domains, I'm more interested in what is the best way to go about extending the library.
Tom
EDIT: Hi Ben, thanks for your answer, and thanks for taking the time to have a look at my issue. Unfortunately this hasn't helped.
I guess what you're trying to do there is add a little bit to the sql query a "where in" clause? I guess that the where in bit is incorrect as there isn't a column name.
Also, at this point I can't modify the sql query satisfactorily to produce the required output. e.g. I can add a hook to a function which is literally $this->db->where('1=1') and this outputs this sql in the next query:
SELECT COUNT(*) AS `numrows` FROM (`users`) WHERE `1=1` AND `email` = 'rawr#rawr.com'
The AND email = 'rawr#rawr.com' bit will always still return no rows. It should be OR email = 'rawr#rawr.com', but without editing the Ion Auth core code then I won't be able to change this.
I am starting to suspect (from the last couple of hours of tinkering) that I may have to edit the ion auth core in order to achieve this.
Check out this example: https://gist.github.com/2881995
In the end I just wrote a little form_verification callback function which I put in the auth controller of ion_auth which checked through a list of allowed domains. :)
When you validate your form in the auth controller you add a callback:
$this->form_validation->set_rules('email', 'Email Address', required|callback_validate_email');
You create a method in the controller called validate_email:
function validate_email() {
if (strpos($this->input->post('email'), '#mycompany.com') === false) {
$this->form_validation->set_message('validate_email', 'Not official company email address.');
return false;
} else return true;
}
This will cause the creation of the user to fail, since all rules must pass. You also provide an error message. Just make sure to have this line on the form view side:
echo validation_errors();
I am trying to populate address fields during registration, using data from another system. In my observer, I am able to use
$customer = $observer->getCustomer();
$customer->setFirstname($value);
$customer->setLastname($value);
and the information is saved in the database, but
$customer->setStreet($value);
$customer->setPostcode($value);
$customer->setTelephone($value);
do not. How would I set address fields?
Thanks!
Addresses are not stored in the Mage_Customer_Model_Customer object. You should instead do something like:
$address = Mage::getModel('customer/address');
$address->setStreet(...);
...
$customer->addAddress($address);
I found some good posts:
this was easier for me:-)
http://www.pauldonnellydesigns.com/blog/magento-display-address-fields-in-create-an-account/
and longer post:
http://www.magentocommerce.com/boards/viewthread/11110/
It's working, I checked.
I need show fields form address in orders, controller: /checkout/onepage on the page with form login and register (I want add fields personal and address in step register)
Do someone saw code to create for this functionality?