Adding friendRequest in codeigniter - codeigniter

As i am sending friend request to other user which is in the user list i simply using this code for comparing login user and other non login user. but this code does not work.
<?php $userid=$this->session->userdata('userID'); ?>
<?php
if($this->session->userdata('userID')==$userid)
{
}
else
{
echo '<a href="<?php echo base_url();?>index.php/myinfocontroller/friendrequest" > <input type="submit" name="Friendbutton" value"Friendrequest" /> </a>';
}
?>

Your link is wrong in the else clause use this:
<?php echo '<input type="submit" name="Friendbutton" value"Friendrequest" />'; ?>
Now the link will work!

Related

Magetno how add checkbox in contact form?

I must add checkbox in Contact form in Magetno (Magento wer. 1.8.1), I searching tutorials on Google but I found solution ... It is easy way to do this ?
Many Thanks
Wojtek
why you don't use the checkout agreements: Just fetch the agreements in file \app\design\frontend\PACKAGE\TEMPLATE\template\contacts\form.phtml by
if (Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
$agreements = Mage::getModel('checkout/agreement')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active', 1);
}
and print out some or all of them like
if ($agreements) {
foreach ($agreements as $_a):
// ID 5 = Datenschutz-Agreement deutsch, ID 6 = Alter-18-Agreement englisch, ID 7 = Datenschutz-Agreement deutsch, ID 8 = Alter-18-Agreement englisch
if ($_a->getId() >= 7 && $_a->getId() <= 8) {
?>
<li>
<div class="checkout-agreements">
<div class="agreement-content"<?php echo ($_a->getContentHeight() ? ' style="height:' . $_a->getContentHeight() . '"' : '')?>>
<?php if ($_a->getIsHtml()):?>
<?php echo $_a->getContent() ?>
<?php else:?>
<?php echo nl2br($this->escapeHtml($_a->getContent())) ?>
<?php endif; ?>
</div>
<p class="agree">
<input type="checkbox" id="agreement-<?php echo $_a->getId()?>" name="agreement[<?php echo $_a->getId()?>]" value="1" title="<?php echo $this->escapeHtml($_a->getCheckboxText()) ?>" class="required-entry checkbox" /><label for="agreement-<?php echo $_a->getId()?>"><?php echo $_a->getIsHtml() ? $_a->getCheckboxText() : $this->escapeHtml($_a->getCheckboxText()) ?></label>
</p>
</div>
</li>
<?php
}
endforeach;
}
That's all!
If there is someone German here: There you will get the full explanation in German!
Best regards
Bastian

How to create an unsubscribe page in magento

I would like to create a direct unsubscribe page in magento, I found this instruction to follow but the steps 1 and 2 are not clear As I'm not a professional.
Can someone please help me clarify these two steps. Where to create the "unsubscribe.phtml" page? How to add the just created block in it?
Thank you in advance.
1. Create a phtml page say “unsubscribe.phtml” containing the code to create the unsubscribe form.
<?php $newsletterObj = new Mage_Newsletter_Block_Subscribe(); ?>
<div class="newsletter-unsubscribe">
<div class="newsletter-unsubscribe-title"><?php echo $this->__('Submit your email id to unsubscribe newsletter') ?></div>
<form action="<?php echo $newsletterObj->getUnsubscribeFormActionUrl() ?>” method="post" id="newsletter-validate-detail">
<div class="block-content">
<div class="input-box">
<input type="text" name="email" id="newsletter" title="<?php echo $this->__('Sign up for our newsletter') ?>” class="input-text required-entry validate-email” value="<?php echo $this->__('Enter Your Email Here') ?>” onfocus="if(this.value==’<?php echo $this->__('Enter Your Email Here') ?>’)this.value=’’;” onblur="if(this.value==’’)this.value=’<?php echo $this->__('Enter Your Email Here') ?>’;”
/>
</div>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Submit') ?>” class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
</div>
</div>
</form>
<script type="text/javascript\">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm(’newsletter-validate-detail’);
//]]>
</script>
</div>
2) Create a CMS page. Add the just created block in it. So that your CMS page will contain that form.
3) Now in page \app\design\frontend\base\default\template\newsletter\subscribe.phtml add the code to add a link of the cms page.
<div class="unsubscribe">
<?php echo $this->__('Unsubscribe') ?>
</div>
4) In page \app\code\core\Mage\Newsletter\Block\Subscribe.php add a function to create the form action url which is called in the “unsubscribe.phtml”.
public function getUnsubscribeFormActionUrl()
{
return $this->getUrl(’newsletter/subscriber/unsubscribecus’, array(’_secure’ => true));
}
5) Now in \app\code\core\Mage\Newsletter\controllers\SubscriberController.php page add new action for unsubscribe process.
/**
* Unsubscribe newsletter from frontend
*/
public function unsubscribecusAction()
{
$email = $this->getRequest()->getParam(’email’);
$subsModel = Mage::getModel(’newsletter/subscriber’);
$subscriber = $subsModel->loadByEmail($email);
$id = (int) $subsModel->getId();
$code = (string) $subsModel->getCode();
if ($id && $code) {
$session = Mage::getSingleton(’core/session’);
try {
Mage::getModel(’newsletter/subscriber’)->load($id)
->setCheckCode($code)
->unsubscribe();
$session->addSuccess($this->__(’You have been unsubscribed.’));
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $e->getMessage());
}
catch (Exception $e) {
$session->addException($e, $this->__(’There was a problem with the un-subscription.’));
}
}
$this->_redirectReferer();
}
Since a can't leave a comment and this question isn't marked as solved yet, i'll assume you still need an answer.
I would suggest placing the unsubscribe.phtml file in /template/newsletter/
For step 2 you can use this code
{{block type="core/template" template="newsletter/unsubscribe.phtml"}}
so the page will contain your form.
If you already figured out how to do this, please post an answer to your own question further on.
Would it be an idea to add an unsubscribe button next to the subscribe button (or allow for a variable in the block call that sets it to yes/no display) - this way you capture both

(Codeigniter) Ion Auth CSRF Error:This form post did not pass our security checks (when loading views)

I'm using Ion Auth authentication library in Codeigniter. When I load my footer view, I get an CSRF Error(This form post did not pass our security checks). When I remove the footer view, it works fine though! Is there anything I'm doing wrong here? Thanks!
function edit_user($id) {
//I'm only posting the last part of the code of edit_user function in the auth controller
$this->load->view('layout/header');
$this->_render_page('auth/edit_user', $this->data);
$this->load->view('layout/footer'); // I'm getting an error when I load this footer view.
}
This is the code in my views.
<h1><?php echo lang('edit_user_heading');?></h1>
<p><?php echo lang('edit_user_subheading');?></p>
<div id="infoMessage"><?php echo $message;?></div>
<?php echo form_open(uri_string());?>
<p>
<?php echo lang('edit_user_fname_label', 'first_name');?> <br />
<?php echo form_input($first_name);?>
</p>
<p>
<?php echo lang('edit_user_lname_label', 'last_name');?> <br />
<?php echo form_input($last_name);?>
</p>
<p>
<?php echo lang('edit_user_company_label', 'company');?> <br />
<?php echo form_input($company);?>
</p>
<p>
<?php echo lang('edit_user_phone_label', 'phone');?> <br />
<?php echo form_input($phone);?>
</p>
<p>
<?php echo lang('edit_user_password_label', 'password');?> <br />
<?php echo form_input($password);?>
</p>
<p>
<?php echo lang('edit_user_password_confirm_label', 'password_confirm');?><br />
<?php echo form_input($password_confirm);?>
</p>
<h3><?php echo lang('edit_user_groups_heading');?></h3>
<?php foreach ($groups as $group):?>
<label class="checkbox">
<?php
$gID=$group['id'];
$checked = null;
$item = null;
foreach($currentGroups as $grp) {
if ($gID == $grp->id) {
$checked= ' checked="checked"';
break;
}
}
?>
<input type="checkbox" name="groups[]" value="<?php echo $group['id'];?>"<?php echo $checked;?>>
<?php echo $group['name'];?>
</label>
<?php endforeach?>
<?php echo form_hidden('id', $user->id);?>
<?php echo form_hidden($csrf); ?>
<p><?php echo form_submit('submit', lang('edit_user_submit_btn'));?></p>
<?php echo form_close();?>
Ion auth csrf protection is older. CI-2 already have
This is provide to security when posting form, ex: POST is from local or server?
ion auth controller file, you see like codes below:
// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE)
{
show_error($this->lang->line('error_csrf'));
}
If you remove these validation, you will not get csrf error
You can enable security with CI core lib
http://ellislab.com/codeigniter/user-guide/libraries/security.html
$config['csrf_protection'] = TRUE;
You have to use form_open() tag to triggger csrf protection.
Same problem happened to me when i was trying to add common/header and common/footer to the auth/reset_password page.
Issue was that I was using relative paths for the JS included in the footer part. After a lot of experiment using the base_url() fixed the issue.
I have the sale pb but a replace flashdata by userdata, it's just a little less secure but it's a good solution.

How to pass variable between views? Codeigniter

Codeigniter noob here:
I am wanting to let users click a button inside someone's profile in order to send them a message, I need to pass the variable from the view back to the controller and into another view, how can I accomplish this? The variable is $username in the first view:
View #1: (this works)
<a href="<?php echo base_url().'user/user_message';?>">
<button type="submit" class="btn btn-info btn-small" title="Send Message" >Send Message</button>
</a>
<h3><?php echo $username;?>- Public Profile</h3>
Controller:
public function user_message($username)
{
if($this->form_validation->run() == FALSE)
{
$this->load->view('header_loggedin');
$this->load->view('user/send_message', $username);
$this->load->view('footer');
}
else
I basically want to grab the $username variable from my first view and make it avaliable in the user/send_message view. Thanks for your help!
Change the following line
<a href="<?php echo base_url().'user/user_message';?>">
To
<?php echo base_url().'user/user_message/'.$username;?>
So, your public function user_message($username){ ... } will receive the $username as it's parameter. Once you get it in your controller method then you can send it to the second view when you load the view with other data, like for example,
...
$data['username'] = $username;
$this->load->view('viewname', $data);
Then you can use $username in your view.
Why not pass hidden field and post it to your controller. Try this.
VIEW
<a href="<?php echo base_url().'user/user_message';?>">
<button type="submit" class="btn btn-info btn-small" title="Send Message" >Send
Message</button>
</a>
<input type="hidden" name="username" value="<?php echo $username; ?>"/>
CONTROLLER
public function user_message()
{
$username = $this->input->post('username');
if($this->form_validation->run() == FALSE)
{
$this->load->view('header_loggedin');
$this->load->view('user/send_message', $username);
$this->load->view('footer');
}

Embed wordpress registration into homepage

I am trying to embed the wordpress registration into the homepage. I already created a custom register page, the problem is that it is calling to the header information and I get this error, when I include it with php include.
Warning: Cannot modify header information - headers already sent
Is there a way I can use my code but alter it somehow/work with it somehow, so that the registration form is fully embedded/works in the page using ajax, but that it works. I am not brilliant with Php so please excuse if this is a silly question:
Current register code(works in its own page but not when included in the homepage template)
<?php
require_once(ABSPATH . WPINC . '/registration.php');
global $wpdb, $user_ID;
//Check whether the user is already logged in
if (!$user_ID) {
if($_POST){
//We shall SQL escape all inputs
$username = $wpdb->escape($_POST['username']);
if(empty($username)) {
echo "User name should not be empty.";
exit();
}
$email = $wpdb->escape($_POST['email']);
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
echo "Please enter a valid email.";
exit();
}
$random_password = wp_generate_password( 12, false );
$status = wp_create_user( $username, $random_password, $email );
if ( is_wp_error($status) )
echo "Username already exists. Please try another one.";
else {
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
wp_mail( $email, $subject, $msg, $headers );
echo "Please check your email for login details.";
}
exit();
} else {
echo "";
?>
<!-- <script src="http://code.jquery.com/jquery-1.4.4.js"></script> --> <!-- Remove the comments if you are not using jQuery already in your theme -->
<?php
if(get_option('users_can_register')) { //Check whether user registration is enabled by the administrator
?>
<h1><?php the_title(); ?></h1>
<br /><br />
<div id="result"></div> <!-- To hold validation results -->
<form id="wp_signup_form" action="" method="post">
<label><p>Username:</p></label>
<input type="text" name="username" class="text" value="" />
<br /><br />
<label><p>Email address:</p></label>
<input type="text" name="email" class="text" value="" /> <br />
<br />
<input type="submit" id="submitbtn" class="Buttons" name="submit" value="Register" />
<br />
<br />
</form>
<script type="text/javascript">
$("#submitbtn").click(function() {
$('#result').html('<img src="<?php bloginfo('template_url'); ?>/images/loader.gif" class="loader" />').fadeIn();
var input_data = $('#wp_signup_form').serialize();
$.ajax({
type: "POST",
url: "<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>",
data: input_data,
success: function(msg){
$('.loader').remove();
$('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow');
}
});
return false;
});
</script>
<?php
}
else echo "Registration is currently disabled. Please try again later.";
?>
</div>
</div>
<?php
echo "";
} //end of if($_post)
}
else {
wp_redirect( home_url() ); exit;
}
?>
is not safe to use a custom method for registration and mailing.
so i suggest to look at this http://digwp.com/2010/12/login-register-password-code/
i hope that's what you want.
best regard.
As webfan suggests, it isn't a good idea to reproduce the registration functionality on the homepage. Much better would be to simply cut and paste the login form from the registration page and keep the form action pointed to the registration page:
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>">
<!-- registration form HTML goes here -->
</form>

Resources