how can i post on a wall using onclick attribute? - php

i have tried a few different ways to get my data to post only when the user clicks it, but to no avail.
Hopefully someone can help:
<link href="facebook.css" rel="stylesheet" type="text/css">
<div class="fbbody">
<?php
require './facebook.php';
$facebook = new Facebook(array(
'appId' => ' *******',
'secret' => '******',
'cookie' => true,
));
$uid = $facebook->getUser();
$status = $_POST['status'];
if($status == "")
$msg = "Please enter a status.";
else {
$msg = "Thanks.";
}
?>
<script>
alert('<? echo $msg; ?>');
</script>
<div align="center">
<form method="GET" action="translate.php">
<textarea name="status2" cols="50" rows="5"/>
<?php echo str_ireplace(array ('old','awkward','all','again','behind','along','alright','hello','among','children','yes','child','kids','food','barnard castle','beer','book','blow','beautiful','bird','burst','brown','burn','boots'),
array ('auld', 'aakwad', 'aall','agyen','ahint','alang','alreet','alreet','amang','bairns','aye','bairn','bairns','bait','barney','beor','beuk','blaa','bonny','bord','borst','broon','bourn','byeuts'),$status); ?>
</textarea><br>
<?php
$args = array(
'message' => $_GET['status2'],
'link' => 'http://apps.facebook.com/geordie-status/',
'caption' => 'Translate from English to Geordie'
);
$post_id = $facebook->api("/$uid/feed", "post", $args);
?>
<input type="submit" value="post to wall"/>
</form>
</div>
</div>
the above code is my translate.php.
how could i use the 'onclick' attribute to run the below code when it is clicked, and only when the button is clicked, not before.
<?php
$args = array(
'message' => $_GET['status2'],
'link' => 'http://apps.facebook.com/geordie-status/',
'caption' => 'Translate from English to Geordie'
);
$post_id = $facebook->api("/$uid/feed", "post", $args);
?>

To post a status message you have to ask the user for permissions see: https://developers.facebook.com/docs/reference/login/extended-permissions/ you will need publish_actions here.
Cause you want to post on the on click event you will have ask the permission before show the form.
You can use jquery to handle your on click event (on submit in the code below). jquery is used to send the message to an second page (ajax request). The second page (facebookpost.php) will post the message on the wall.
facebook.php:
<?
error_reporting(E_ALL);
ini_set('display_errors','on');
require 'facebook-php-sdk-master/src/facebook.php';
$facebook = new Facebook(array(
'appId' => '***************',
'secret' => '*******************************',
));
$applicationurl = 'http://testdrive.nl/facebook.php';
// Get User ID
$user = $facebook->getUser();
if(empty($user))
{
$params = array(
'scope' => 'publish_actions',
'redirect_uri' => $applicationurl
);
$loginUrl = $facebook->getLoginUrl($params);
header('Location: ' . $loginUrl ."\r\n");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Facebook testpage</title>
</head>
<body>
<div class="container">
<div id="result"></div>
<form id="poster">
<textarea id="status2"></textarea>
<input type="submit" value="post to wall"/>
</form>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$('#poster').submit(function() {
$.get("facebookpost.php", { status2: $('#status2').val() }, function(data) {
$('#result').html(data);
});
return false;
});
</script>
</body>
</html>
facebookpost.php:
<?
error_reporting(E_ALL);
ini_set('display_errors','on');
require 'facebook-php-sdk-master/src/facebook.php';
$facebook = new Facebook(array(
'appId' => '***************',
'secret' => '*******************************',
));
//$applicationurl = 'http://testdrive.nl/facebook.php';
// Get User ID
$user = $facebook->getUser();
if(empty($user))
{
echo 'invalid user';
}
$args = array(
'message' => $_GET['status2'],
'link' => 'http://apps.facebook.com/geordie-status/',
'caption' => 'Translate from English to Geordie'
);
$facebook->api("/$user/feed", "post", $args);
echo 'posted to your wall';

Related

Wordpress login works partially

I try to login the user in wordpress, but it works only for users registered in UI, not for the ones added by program.
The Login is done as a response to Ajax login request:
//wp_clear_auth_cookie();
$usr = wp_set_current_user ( $user->ID, $user->user_login);
wp_set_auth_cookie ( $user->ID );
There is log output for each step, and for any type of user. It is successfully registered in database, loaded from database, and even login is ok. And even a session is created for both kind of users. It can be seen in the database. But after all login flow, when page is redirected or refreshed, only the UI registered users enters the site. The programmatic ones are just not loaded after all successful steps: silently not working, no errors messages, no warnings, no failures. Looks like it needs some additional steps to enable or to activate. All kind of users are shown in dashboard in UI.
I suspect the programmatically added user is not complete or is not activated. This is how the user is registered as response to Ajax registration request:
function register_user($username, $usertype, $externalid)
{
$user_email = 'theuseremail#mail.com';
$result = wp_insert_user(array('user_login' => $username,
'nice_name' => $username,
'user_email' => $user_email,
'user_pass' => '***********' ));
$fb_user_id = $result;
add_user_meta( $fb_user_id, 'specific_attribute', $specific_id, true );
$user = get_user_by('id', $fb_user_id);
return $user;
}
The same code is used for both kind of users, the ones registered by UI and the ones registered programatically. There is how the user is loaded from Database as response to Ajax login request:
function load_user($usertype, $specific_id)
{
$user = get_users(array(
'meta_key' => 'specific_attribute',
'meta_value' => $specific_id
));
return $user [0];
}
The login uses a metadata field specific_attribute in both cases. For users registered by UI this attribute is added manually in the database, because there is no such UI field. For the other ones it is added automatically in the function register_user. The same thing happens when I try to login any user by using standard login/password form.
Workflow update:
1. PHP:
$user = load_user(request['usertype'], request['specific_id'])
if not load then register_user(request['username'], request['usertype'], request['specific_id'])
//wp_clear_auth_cookie();
$usr = wp_set_current_user ( $user->ID, $user->user_login);
wp_set_auth_cookie ( $user->ID );
do_action( 'wp_login', $user->user_login );
return $user; //<-- this is returned to javascript Ajax request
}
Javascript:
function onClick()
{
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
window.location = redirectaddress; //redirect
//or window.location=window.location;//just refresh
}
}
xhttp.open("POST", "/wp-json/register_or_login", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(JSON.stringify(request));
}
In this snippet of code:
$user = load_user(request['usertype'], request['specific_id'])
if not load then register_user(request['username'], request['usertype'], request['specific_id'])
//wp_clear_auth_cookie();
$usr = wp_set_current_user ( $user->ID, $user->user_login);
wp_set_auth_cookie ( $user->ID );
do_action( 'wp_login', $user->user_login );
return $user; //<-- this is returned to javascript Ajax request
}
On the fourth line the $user won't be set to anything if it was just created.
Also on that same line you spelled $user as $usr
I've actually done this exact same thing before. Below is the relevant part of the code that I used when I was doing this.
$user_id = lookup_user_id();
// Create the user in the WordPress DB if it does not exist
if ($user_id === false){
$username = $_POST['username'];
$email = $_POST['email'];
// We're never going to know the password stored in the WordPress DB, but that is alright
// because we will only authenticate this user against our SSO server and not the WordPress DB
$password = wp_generate_password(33, true, true);
$user_id = wp_insert_user( array('user_login'=>$username, 'user_pass'=>$password, 'user_email'=>$email, 'display_name'=>$_POST['username']) );
}
// Login the user
wp_set_auth_cookie($user_id, false);
if (isset($_POST['redirect'])){
header('Location: '.$_POST['redirect']);
}
Here I have written script to login and register in WordPress programmatically
Have created an ajax request for login
add_action( 'wp_ajax_gs_user_login_action', 'gspre_user_login');
add_action( 'wp_ajax_nopriv_gs_user_login_action', 'gspre_user_login');
function gspre_user_login(){
$creds = array();
$username = $creds['user_login'] = $_POST['user_login'];
$creds['user_password'] = $_POST['user_pass'];
$userbyname = get_user_by( 'login', $username );
if ($userbyname) {
$user = $userbyname;
}
$userbyemail = get_user_by('email', $username);
if ($userbyemail) {
$user = $userbyemail;
}
if ($user) {
$user_roles = implode(', ', $user->roles);
$user = wp_signon( $creds, true );
if ( is_wp_error($user) ){
$myArr = array(
'response' => 'Invalide username and password',
'redirect_url' => '',
'message' => $user->get_error_message()
);
}else{
wp_set_current_user( $user->ID );
wp_set_auth_cookie( $user->ID );
if ($user_roles == "administrator") {
$redirect_url = home_url('wp-admin/');
}else{
$redirect_url = home_url();
}
$myArr = array(
'response' => 'Login successfully',
'redirect_url' => $redirect_url,
'message' => 'Login successfully'
);
}
}else{
$myArr = array(
'response' => 'Invalide username and password',
'redirect_url' => '',
'message' => $user->get_error_message()
);
}
$myJSON = json_encode($myArr);
echo $myJSON;
die();
}
Have created an ajax request for registration
add_action( 'wp_ajax_gs_user_reg_action', 'gspre_user_reg');
add_action( 'wp_ajax_nopriv_gs_user_reg_action', 'gspre_user_reg');
function gspre_user_reg(){
//Create user
//start: Fill you details here
$user_login = $_POST['user_login'];
$user_email = $_POST['email'];
$user_pass = $_POST['password'];
$display_name = $_POST['display_name'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$role = 'administrator';
//end: Fill you details here
$flag_1 = 0;
$flag_2 = 0;
$check_username_exists = username_exists( $user_login );
if ($check_username_exists) {
$flag_1 = 1;
}
$check_email_exists = email_exists($user_email);
if ($check_email_exists) {
$flag_2 = 1;
}
if ($flag_1 == 0 && $flag_2 == 0) {
$userdata = array(
'user_login' => $user_login,
'user_pass' => $user_pass,
'user_email' => $user_email,
'display_name'=> $display_name,
'first_name' => $first_name,
'last_name' => $last_name
);
$user_id = wp_insert_user($userdata);
wp_update_user( array ('ID' => $user_id, 'role' => $role) );
if(is_wp_error($user_id)){
//echo $user->get_error_message();
$myArr = array(
'response' => 'register xyz',
'message' => $user->get_error_message()
);
}else{
//echo "User created successfully";
$myArr = array(
'response' => 'register xyz',
'message' => 'User created successfully'
);
}
}else{
//echo "User already exist";
$myArr = array(
'response' => 'register xyz',
'message' => 'User already exist'
);
}
$myJSON = json_encode($myArr);
echo $myJSON;
die();
}
Also, Have created a shortcode for login form
Shortcode:: [gsuserlogin]
add_shortcode('gsuserlogin', 'gsuserlogin_shortcode_function');
function gsuserlogin_shortcode_function(){
if (is_user_logged_in()) {
return 'You have Logged in';
}
?>
<form name="loginform" id="loginform" action="" method="post">
<div class="msg_ajax"></div>
<div>
<label for="gs_user_login"><?php echo _e('Username or Email', 'gs-users'); ?></label>
<input type="text" name="gs_user_login" id="gs_user_login" class="input" value="" size="20">
</div>
<div>
<label for="gs_user_pass"><?php echo _e('Password', 'gs-users'); ?></label>
<input type="password" name="gs_user_pass" id="gs_user_pass" class="input" value="" size="20">
</div>
<div>
<label><input name="gs_user_rememberme" type="checkbox" id="gs_user_rememberme" value="true"> <?php echo _e('Remember Me', 'gs-users'); ?></label>
</div>
<input type="hidden" name="action" value="gs_user_login_action">
<input type="button" id="login_btn" value="Login">
</form>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(document).on('click', '#login_btn', function(){
var target = jQuery(this);
var user_login = jQuery('#gs_user_login').val();
var user_pass = jQuery('#gs_user_pass').val();
//Ajax
jQuery.ajax({
url: '<?php echo admin_url( 'admin-ajax.php');?>',
type: "POST",
data: {'action': 'gs_user_login_action', user_login: user_login, user_pass: user_pass},
cache: false,
dataType: 'json',
beforeSend: function(){
},
complete: function(){
},
success: function (response) { console.log(response);
jQuery('.msg_ajax').text(response['message']);
console.log(response['redirect_url']);
console.log(response['message']);
if (response['redirect_url']!="") {
window.location.href = response['redirect_url'];
}
}
});
//Ajax
});
});
</script>
<?php
}
Created a shortcode for registration form
Shortcode:: [gsuserreg]
add_shortcode('gsuserreg', 'gsuserreg_shortcode_function');
function gsuserreg_shortcode_function(){
if (is_user_logged_in()) {
return 'You have Logged in';
}
?>
<form name="regform" id="regform" action="" method="post">
<div class="msg_ajax"></div>
<div>
<label for="first_name"><?php echo _e('first_name', 'gs-users'); ?></label>
<input type="text" name="first_name" id="first_name">
</div>
<div>
<label for="last_name"><?php echo _e('last_name', 'gs-users'); ?></label>
<input type="text" name="last_name" id="last_name">
</div>
<div>
<label for="user_login"><?php echo _e('user_login', 'gs-users'); ?></label>
<input type="text" name="user_login" id="user_login">
</div>
<div>
<label for="email"><?php echo _e('email', 'gs-users'); ?></label>
<input type="text" name="email" id="email">
</div>
<div>
<label for="password"><?php echo _e('password', 'gs-users'); ?></label>
<input type="password" name="password" id="password">
</div>
<input type="hidden" name="action" value="gs_user_reg_action">
<input type="button" id="btn_reg" value="Send My Message">
</form>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(document).on('click', '#btn_reg', function(){
var target = jQuery(this);
var first_name = jQuery('#first_name').val();
var last_name = jQuery('#last_name').val();
var user_login = jQuery('#user_login').val();
var email = jQuery('#email').val();
var password = jQuery('#password').val();
//Ajax
jQuery.ajax({
url: '<?php echo admin_url( 'admin-ajax.php');?>',
type: "POST",
data: {'action': 'gs_user_reg_action', first_name: first_name, last_name: last_name, user_login: user_login, email: email, password: password},
cache: false,
dataType: 'json',
beforeSend: function(){
},
complete: function(){
},
success: function (response) { console.log(response);
jQuery('.msg_ajax').text(response['message']);
console.log(response['response']);
console.log(response['message']);
}
});
//Ajax
});
});
</script>
<?php
}
Paste above code to the theme functions.php
I hope it will work you thank you :)

Google Invisible reCAPTCHA with PHP, no Response

Can't seem to get the Google invisible reCAPTCHA to work. This should be easy, looking to find out what I'm doing wrong. Here's my client side code:
<head>
<script type="text/javascript">
var onSubmit = function(token) {
console.log('success!');
};
var onloadCallback = function() {
grecaptcha.render('submit', {
'sitekey' : '------my site key---------',
'callback' : onSubmit
});
};
</script>
</head>
Form:
<form action='/mail-script.php' target='_self' method='POST' id='econtact'>
<input class='w3-input' type='text' placeholder='Name' required name='Name'>
<input class='w3-input w3-section' type='text' placeholder='Email' required name='Email'>
<input class='w3-input w3-section' type='text' placeholder='Subject' required name='Subject'>
<input class='w3-input w3-section' type='text' placeholder='Comment' required name='Comment'>
<button class='w3-button w3-dark-blue w3-section' type='submit' name='submit'>
<i class='fa fa-paper-plane'></i> SEND MESSAGE</button></form>
<script src='https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit' async defer></script>
Serve side code:
<?php
function checkCaptcha(){
if(isset($_POST['g-recaptcha-response'])){
$captcha = $_POST['g-recaptcha-response'];
$postdata = http_build_query(
array(
'secret' => '----------secret code----------',
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']
)
);
$options = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($options);
$result = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context));
return $result->success;
}else{
return false;
}
}
$captcha_result = checkCaptcha();
echo("the captcha result is: " . $captcha_result);
?>
So $captcha_result is blank. I can't get it to detect anything. I get the sense
g-recaptcha-response isn't being passed through the form correctly, or something else is going on. Thanks for the help.
UPDATE: var_dump($result); = NULL

How do I setup recaptcha with a form which uses the php_self action

my site looks like this.
<?php
include 'dbd.php'; //DB Login details
?>
<!DOCTYPE html>
<html>
<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<?php
$showFormular = true;
if (isset($_POST['submit'])) {
$error = false;
if (!$error) {
$statement = $pdo->prepare("INSERT INTO table (email, name) VALUES (:email, :name,)");
$result = $statement->execute(array(
'email' => $email,
'name' => $name
));
if ($result) {
echo "Your Registration was Successful";
$showFormular = false;
} else {
echo 'Could not register your Account';
}
}
}
if ($showFormular) {
?>
<form action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post">
<input placeholder="Your Forum Name Here" name="name" required>
<input placeholder="Your Forum Email Here" name="email" required>
<div class="g-recaptcha" data-sitekey="public key"></div>
<input name="submit" type="submit">
</form>
<?php
}
?>
</body>
</html>
The Problem what I have is that I dont know how to implement the Serverside ReCaptcha Check. I tried it with the following method but there I get obviously the error that the function is empty because its getting executed directly.
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
CURLOPT_POST =>1,
CURLOPT_POSTFIELDS => [
'secret' => 'privat key',
'response' => $_POST['g-recaptcha-response'],
],
]);
I hope I explained it good enough that someone can help me.
Why are you trying to use curl command ? You can do this by directly with php code.
First of all download this php reCaptcha library and import your project : reCaptcha gitHub
Secondly, after you action call your php and implement this on your php code.
require_once('your-imported-autoload.php-path'); ex:Assets/reCaptcha/autoload.php
$privatekey = "-your private key-";
$recaptcha = new \ReCaptcha\ReCaptcha($privatekey);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'],
$_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
For last, for cURL you are trying to connect through SSL and have to handle it
curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);

Tweet image with Twitter API not posting

I'm trying to create a simple app that sends a tweet of an image with a caption upon form submission. The test appears to be working at http://5starvintage.com/tweet/, but the tweet is never posted.
Any idea as to why the submitted tweet isn't posting?
Here's the form...
<form method="post" action="<?php echo bloginfo('template_directory');?>/tweet/start.php" enctype="multipart/form-data" onsubmit="FSV.initTweetValidate()" >
<div id="tweetWrap" class="clearfix">
<div id="imageDrop">
<span class="desc">Upload Image</span>
<input type="file" name="img" id="img"/>
</div>
<div id="tweetText">
<textarea type="text" name="txt" id="txt" maxlength="140" onkeyup="FSV.initCountChar(this)" placeholder="#5StarVintage..."></textarea>
<div id="charNum">140</div>
</div>
</div>
<input type="submit" name="sub" class="tweet" id="sub" value="Submit"/>
</form>
Here is the form action code, start.php..
<?php
require './config.php';
require './tmhOAuth.php';
/////// upload the photo
$img = $_FILES["img"]["name"];
move_uploaded_file($_FILES["img"]["tmp_name"],$img);
////////// generate *temp* access token and save it in cookie for callback page
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => API_KEY,
'consumer_secret' => API_SEC,
'curl_ssl_verifypeer' => false
));
$tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''));
$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$txt = $_POST['txt'];
$temp_token = $response['oauth_token'];
$temp_secret = $response['oauth_token_secret'];
$time = $_SERVER['REQUEST_TIME'];
setcookie("Temp_Token", $temp_token, $time + 3600 * 30, '/tweet/');
setcookie("Temp_Secret", $temp_secret, $time + 3600 * 30, '/tweet/');
setcookie("Img_Url", $img, $time + 3600 * 30, '/tweet/');
setcookie("Tweet_Txt", $txt, $time + 3600 * 30, '/tweet/');
///////// redirect to twitter page for user authincation
$url = $tmhOAuth->url("oauth/authorize", "") . '?oauth_token=' . $temp_token;
header("Location:".$url);
// after user give the required authrization he will be redirect to callback.php on your serve
exit();
?>
Here's the callback.php..
<?php
require './config.php';
require './tmhOAuth.php';
require './tmhUtilities.php';
/// retrive temp access token from cookie
$token = $_COOKIE['Temp_Token'];
$secret = $_COOKIE['Temp_Secret'];
$img = $_COOKIE['Img_Url'];
$txt = $_COOKIE['Tweet_Txt'];
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => API_KEY,
'consumer_secret' => API_SEC,
'user_token' => $token,
'user_secret' => $secret,
'curl_ssl_verifypeer' => false
));
/// Ask Twitter for correct access token
$tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array(
// pass the oauth_verifier received from Twitter
'oauth_verifier' => $_GET["oauth_verifier"]
));
$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$tmhOAuth->config["user_token"] = $response['oauth_token'];
$tmhOAuth->config["user_secret"] = $response['oauth_token_secret'];
$img = './'.$img;
$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => "#{$img}",
'status' => "$txt" // Don't give up..
),
true, // use auth
true // multipart
);
if ($code == 200){
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
echo '<h1>Your image tweet has been sent successfully</h1>';
}else{
// display the error
tmhUtilities::pr($tmhOAuth->response['response']);
return tmhUtilities;
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tweet an Image</title>
</head>
<body>
</body>

Unable to grab text from form_input

I am trying to obtain items that are within my view input boxes.
I am using:
$email = $this->input->post('email', true);
In order to obtain the what is within the input box. But it is not obtaining anything.
The function is run with:
<?php $function = array('auth/start', $price);?>
<form action="<?php echo base_url($function);?>"method="post">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_xZrfWwuBmwBzUBynB96OgZhU"
data-amount=""
data-name="Turbine Engine"
data-description="Individual Membership"
data-image="/128x128.png">
</script>
</form>
I have the following:
Controller:
function start()
{
$username = 'a';
$price = '100';
$password = 'password';
$email = $this->input->post('email');
$end = date('Y-m-d', strtotime('+1 years'));
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'middle_initial' => $this->input->post('middle_initial'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
'biography' => $this->input->post('biography'),
'address' => $this->input->post('address'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'zip' => $this->input->post('zip'),
'position' => $this->input->post('position'),
'country' => $this->input->post('country'),
'website' => $this->input->post('website'),
'listing' => 'N',
'type' => 'I',
'registration_end' => $end,
);
//load payment library
$this->load->library( 'stripe' );
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
//attempt to charge user
$this->stripe->charge_card( intval($price), $token, "Individual Membership" );
}
catch(Stripe_CardError $e)
{
// The card has been declined
}
//If passed then add a new user
//add the user
$this->ion_auth->register($username, $password, $email, $additional_data);
$this->session->set_flashdata('message', 'Payment Successful');
//TEST
//load parameters
$type = 'new account';
$date = date('Y-m-d');
date_default_timezone_set('Australia/Melbourne');
$time = date('h:i:s a', time());
//load the controller for adding activity
$this->load->library('../controllers/activity');
$this->activity->insert($email, $type, $date, $time);
//send to login
//$this->showView('login');
redirect("auth", 'refresh');
}
View:
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-body">
<!--Put Labels in order-->
<style>
label
{
display: inline-block;
width: 120px;
}
</style>
<h4>Individual Payment Page</h4>
<b>Make sure your email is correct</b>
<hr>
<p>
<?php echo form_label("Email:");?> <br />
<?php echo form_input(array('id' => 'email', 'name'=>'email','value'=>$email,'size'=>'30',
'readonly'=>'true'));?>
</p>
<!-- Make Hidden Labels to Pass the username and password-->
<p>
<?php echo form_input('username',$username);?>
<?php echo form_input('password',$password);?>
<?php echo form_input('first_name', $first_name);?>
<?php echo form_input('middle_initial',$middle_initial);?>
<?php echo form_input('last_name', $last_name);?>
<?php echo form_input('company', $company);?>
<?php echo form_input('phone', $phone);?>
<?php echo form_input('biography',$biography);?>
<?php echo form_input('address', $address);?>
<?php echo form_input('city', $city);?>
<?php echo form_input('state', $state);?>
<?php echo form_input('zip', $zip);?>
<?php echo form_input('position', $position);?>
<?php echo form_input('country', $country);?>
<?php echo form_input('website', $website);?>
</p>
<br>
<p>
<b>Click Below for Payment</b> <br>
</p>
<p><h4>1.) Regular Individual </h4><br>
<?php echo form_label("Price:");?> <br />
<?php echo form_input(array('name'=>'price','value'=>$price,'size'=>'30',
'readonly'=>'true'));?>
</p>
<?php $function = array('auth/start', $price);?>
<form action="<?php echo base_url($function);?>"method="post">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_xZrfWwuBmwBzUBynB96OgZhU"
data-amount=""
data-name="Turbine Engine"
data-description="Individual Membership"
data-image="/128x128.png">
</script>
</form>
<p><h4>2.) Regular Individual with Listing Enabled</h4><br>
<?php echo form_label("Price:");?> <br />
<?php echo form_input(array('name'=>'price_listing','value'=>$total,'size'=>'30',
'readonly'=>'true'));?>
</p>
<?php $function2 = array('auth/start_listing', $username, $password, $email, $first_name, $middle_initial, $last_name, $company, $phone, urldecode($address), $city, $state, $zip, urldecode($biography), $position, urldecode($country), urldecode($website), $total);?>
<form action="<?php echo base_url($function2);?>"method="post">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_xZrfWwuBmwBzUBynB96OgZhU"
data-amount=""
data-name="Turbine Engine"
data-description="Individual Membership"
data-image="/128x128.png">
</script>
</form>
</div>
</div>
</div>
</div>
</div>
Thank you. I appreciate any help.
In your view you have this:
//...
<?php echo form_input(array('id' => 'email', name'=>'email','value'=>$email,'size'=>'30', 'readonly'=>'true'));?>
//...
<form action="<?php echo base_url($function);?>"method="post">
// ...
</form>
But you didn't open the form before this input, so your inputs are not submitting, so open the form first like this:
echo form_open('url here');
echo form_input(array('id' => 'email', 'name'=>'email','value'=>$email,'size'=>'30', 'readonly'=>'true'));
//other inputs...
form_close();
The form_open opens/creates the opening form tag and form_close creates the closing form tag. You can also use <form> and </form> so put all your inputs inside the form before:
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" ...></script>
Read more about Form Helper.
There is no any form_open() and form_close() in you input form. Please update your code this will solve your problem.
in order to post your text field you need to enclose it in a form tag
<input type="text" name="email" value="" />
<form action="someurl" method="post">
</form>
in this situation nothing will get posted to the server
if you need to post the text field you will need move it inside the form tags
<form action="someurl" method="post">
<input type="text" name="email" value="" />
</form>
or
form_open('someurl');
<?php echo form_label("Email:");?> <br />
<?php echo form_input(array('id' => 'email', name'=>'email','value'=>$email,'size'=>'30', 'readonly'=>'true'));?>
form_close();
make sure all the text filed are wraped inside a form

Categories