i am trying to get the current logged in user's friends, they should select one friend using the form below and then submit it to the same page.
The script is suppose to get the friend's userid (only one) and add it to the database.
The script is working fine but its not posting the right ID (Wrong ID $_POST['friend_selector_id']), it posts an id that looks like this: 2147483647 and i am not sure if this is the profile id or what but i need the id that you use with this code <fb:profile-pic uid=. i need the userid. Could somebody help me out ?
Thank You :D
<form action="<?php echo $appCanvasUrl.'challenge.php?gameid='.$_GET[gameid].'&userid='.$user.'&userid2='.$friend_selector_id; ?>" id="challenge" method="post">
<fb:friend-selector uid="<?PHP echo $user; ?>" name="userid2" idname="friend_selector_id"/>
<INPUT type="submit" value="Challenge"> </form>
<?php
if(isset($_GET['gameid']) && is_numeric($_GET['userid']) && isset($_GET['userid2'])) {
$gameid = am_injection($_GET[gameid]);
$userid2 = am_injection($_POST['friend_selector_id']);
$userid1 = am_injection($user);
am_queries($db, "INSERT INTO `AMCMS_challenges` (`primkey` ,`userkey1` ,`userkey2` ,`gameid` ,`winner`, `score1`, `score2`) VALUES (NULL, $userid1, $userid2, $gameid, 0, 0, 0);");
echo 'Challenge recorded.';
} else {
echo 'Please select a friend to challenge!';
exit;
}
My bad, it wasn't the script, it was my database. I had to set the fields to BIGINT otherwise the number recorded in the database was completely different :)
Related
I have a pdf generated (fpdf) from a post form. I would like the pdf to open in a new tab and/or window prompting the user to save the pdf. I'm guessing I need to save the output to a string
$data=$pdf->Output("OfficeForm.pdf", "S");
but what exactly can I do with this string to get it to open in a new window. I've attempted something like this but it's not working. Am I on the right track or is window.open not what I need?
echo "<script type=\"text/javascript\">
window.open('$data', '_blank')
</script>";
If you use a form you can do it by specifying target='_blank' in the -tag (next to where you should have submit='something')
Example:
This will open a new Tab (showing whatever "makepdf.php" produces) on submit.
Hope it answers the question correctly
I simply added target="_blank" to my form opening tag and used $_SESSION[]; to pass my form to the FPDF code:
<?php session_start(); ?>
<form id ="buildPDFform" name="buildPDFform" target="_blank" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
...some code for my form
<input type="submit" name="buildPDf" id="buildPDf" class="buildPDFbutton" value="Build the PDF">
</form>
Then when the form is submitted I gather my form items, put them in an array, create a session the array goes into and use a header("Location: testcode.php") to redirect to where my FPDF code is.
if (isset($_POST['buildPDf'])) {
$pdfArray = array();
foreach ($_POST as $key => $value) {
...gather your form items into your array
}
$_SESSION['pdfArray'] = $pdfArray;
header("Location: testcode.php");
}
And don't forget in your FPDF code file (testcode.php in my case) to grab your session that has the array.
<?php
session_start();
$pdfArray = $_SESSION['pdfArray'];
... your FPDF code
$pdf->Output('I');
?>
source: https://www.thesitewizard.com/html-tutorial/open-links-in-new-window-or-tab.shtml
use target="_blank" in your a tag to open it to new tab
Try $pdf->Output("OfficeForm.pdf", "I");
I am new to facebook graph api
i have written a small application for posting comments on the user profile.
the following is the code:
<?php
require_once 'config.php';
/* Get a valid session */
$user= $facebook->getUser();
$me = null;
if($user) {
//Check if session is valid
$me = $facebook->api('/me');
}
if($me) {
echo 'User is logged in and has a valid session';
print_r($me);
$id=getfirstpostid($facebook->api('/me/posts'));
echo "id is ".$id;
$message="This is done programatically";
$comment_id = $facebook->api('/'.$id.'/comments','POST',
array('message' => $message,));
//$like_id = $facebook->api('/'.$id.'/likes', 'POST');
}
else {
//$login_url = $facebook->getLoginUrl();
//header("Location: {$login_url}");
echo 'Session expired or user has not logged in yet.
Redirecting...';
$login_url=$facebook->getLoginUrl(array('req_perms'=>'publish_actions,user_likes,offline_access,manage_pages,user_friends',));
echo '<script>top.location.href="'. $login_url .'";</script>';
}
function getfirstpostid($feeds)
{
return $feeds['data'][0]['id'];
}
?>
<?php
$logoutUrl = $facebook->getLogoutUrl(array('next' => 'http://distanceeducationhelpline.org/',));
?>
<a href='<?php echo $appBaseUrl?>about.php' target='_top'>
About Us</a>
<a href='http://www.9itech.com' target='_top'>External Link</a>
<br/>
<br/>
<a href ="#" onclick="top.location.href='<?php echo $logoutUrl; ?>';
return false;">Logout</a>
a. While creating the app ,i have not provided secure Canvas Url and accordingly the Canvas page does not show up in facebook.
is it due to the secure canvas url not being proper that blank page comes in the canvas page url.
b. when i am accessing the user profile the profile does not ask for permission to post on his profile even though i have given permissions .
i am not able to get the likes and post comments to work.kindly update if there is any problem in code.
do we need to get access tokens in this case or the code is proper.
thanks
I am trying to build a simple CMS and have run into a problem I hope you can help me with.
I have a public display page that fetches data from a MySQL database. This works fine.
I also have an admin page where the data is loaded into a form field so that a maintainer can change it.
My problem is that after hitting the submit button, the data is successfully sent to the DB but I cannot find a way to get the form to show the latest data. It is always one submit step behind.
Sample code:
<?php
//retrieve data from MySQL
mysql_connect('localhost:3306','dundryor_show','show1');
mysql_select_db('dundryor_stofl_test');
$query = mysql_query("SELECT * FROM form_test where id = '0'");
$output = mysql_fetch_array($query);
$user_text = $output['user_text'];
mysql_close();
//display form and populate
echo '<form method="post">';
echo 'This text is stored in the database and can be changed by the user:<p>';
echo '<input type="Text" name="user_text" size="50" value="';
echo $user_text;
echo '"><br><input type="Submit" name="update" value="Update Database">';
echo '</form>';
//process submit event, write new data to DB
if ($_POST['update'])
{
$user_text = $_POST['user_text'];
mysql_connect('localhost:3306','dundryor_show','show1');
mysql_select_db('dundryor_stofl_test');
mysql_query("UPDATE form_test set user_text = '$user_text' where id = '0'");
mysql_close();
}
?>
As an added complication, the file name needs to be dynamic, i.e. not just "myform.php" but "myform.php?option=this_can_be_anything". So a reference to a static URL would not work.
Any suggestions much appreciated.
First off I'm new to cakephp.... I'm pulling survey questions from a database and building a form of type=file.
echo $this->Form->create('PersonalDetail', array('type' => 'file', 'id' => 'editProfileForm', 'class' => 'form-horizontal'));
echo $this->Form->hidden('id');
echo $this->Form->hidden('PersonalDetail.id');
echo $this->Form->input('PersonalDetail.field_name', array('label' => false, 'div' => false, 'readonly' => false));
echo $this->Form->submit('Update Profile', array('class' => 'btn btn-primary', 'id' => 'editProfileSubmitBtn'));
echo $this->Form->end();
According to cakephp docs "Since this is an edit form, a hidden input field is generated to override the default HTTP method." But I can't seem to figure out how to tell cake this is an edit form. It always inserts a hidden POST not PUT method:
<form action="/editForm" id="editProfileForm" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div style="display:none;">
<input type="hidden" name="_method" value="POST"/>
<input type="hidden" name="data[_Token][key]" value="ff8b198e82d800a35581" id="Token836"/></div>
<input type="hidden" name="data[id]" id="id"/>
<input type="hidden" name="data[PersonalDetail][id]" id="PersonalDetailsId"/>
<label class="control-label required">Username</label>
<input name="data[PersonalDetail][field_name]" maxlength="255" type="text" id="PersonalDetailsFieldName"/>
<input class="btn btn-primary" id="editProfileSubmitBtn" type="submit" value="Update Profile"/>
<div style="display:none;">
<input type="hidden" name="data[_Token][fields]" value="a2f722badf82c0d8991ab8%3APersonalDetail.id%7Cid" id="TokenField020"/> <input type="hidden" name="data[_Token][unlocked]" value="" id="TokenUnlocked1562820470"/> </div></form>
The problem is when I submit the form and watch with Firefox's Tamper Data the form posts the data fine, but then it posts again immediately again with all the data missing.
On a working form example, I see the same behaviour, except the hidden input field is "PUT" and when the form submits, it is first a PUT with data, then the immediate second submission is with the POST with data instead of begin blank.
I assume I'm missing something basic here, but I'm really confused.
Here's the controller where PersonalForm is a database of questions passed to an element that builds the forms. PersonalDetail is supposed contain the answers but for this first time this is run the user won't have any answers.
public function editForm() {
$userId = $this->UserAuth->getUserId();
if (!empty($userId)) {
$user_account_type = $this->UserDetail->read('account_type', $userId);
$user_account_type = $user_account_type['UserDetail']['account_type'];
$this->set('user_acct_type', $user_account_type);
$this->loadModel('Usermgmt.PersonalForm');
$forms = $this->PersonalForm->find('all');
$this->set('forms', $forms);
if ($this->request->isPut() || $this->request->isPost()) {
//put in ajax verification
//$this->PersonalDetail->saveAssociated($this->request->data);
$this->Session->setFlash(__('Your answers have been successfully updated'));
$this->redirect('/dashboard');
} else {
// read user's original responses and populate form
$this->loadModel('Usermgmt.PersonalDetail');
$answers = $this->PersonalDetail->read(null, $userId);
$this->request->data = null;
if (!empty($answers)) {
$this->request->data = $answers;
}
}
} else {
$this->redirect('/dashboard');
}
}
I'm using cakephp 2.3.7 and I'm running the debugKit plugin (maybe causing more than one submission? I don't know.) Edit: Also I'm using UserAuth and Security modules.
EDIT: I oversimplified the example when I removed the hidden id fields. Now I included the two hidden input elements. However the first time this form is loaded there is no edit data so it is a create instead of add case. So I don't understand why it is posting twice and losing the data on the second post. Perhaps that is the real problem and not that it should be PUT vs POST? I'm obviously missing something fundamental in how cake is processing the post data.
Perhaps I should mention this is form is part of a plugin. Could the routing have something to do with the loss of data and the second post?
You are missing the vital part of an edit form, the id:
echo $this->Form->input('id');
Without its presence cake assumes that this is not an update (edit), but a create (add).
Also mind your casing, its not $this->Form->Submit() but $this->Form->submit().
EDIT:
At second look: I also guess that you violated more than 5 other conventions, including the most important one: Models are singular, Controllers plural. Meaning:
$this->Form->create('PersonalDetail');
If your model is PersonalDetail (which from your controller code it looks like).
This would explain why the data doesnt end up where it is supposed to.
Again my recommendation: Bake your code to see how its done.
It appears this is related to a security module problem.
I was able to prevent the double empty data posts by adding the following to the beforeFilter:
if (isset($this->Security) && ($this->RequestHandler->isAjax() || $this->action == 'editForm')) {
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
}
Now I need to research the reasons for this security problem with my form to fix it.
I'm using cakephp 2.3.0. I searched in the manual for quite awhile, but I haven't found the answer. Also, I've searched the Internet, but still haven't found what I'm looking for. SO, I'm posting my question here. Note, I'm fairly new to cakephp.
Scenario:
I have a simple form with two fields: activity and zip code.
I'm using POST on the form.
When I type in some value in those fields and submit, I echo those 'post' values/parameters and display in the browser screen. What I typed in, I can see on the screen, but the number '1' is added to the end of what I typed in the form.
Here is an example. I type in these values in the form, 'walk' and '44555'. Then I click 'Submit'. The post goes to my controller's action, which then calls my view. My view is displayed on the browser screen and I echo out those 'post' values. The results on screen are 'walk1' and '445551'.
Example #2: If I follow the steps above and don't enter any values in my form (I'll add error checking later), what I see on the browser screen is '1' and '1'.
I am unable to figure out why I am getting the value of '1' added to my form's POST values?
I'll be glad to include any other additional php code to this posting, if requested by someone trying to help.
Here is my FORM code (from my view)...I know there are DIV helpers, but I'll get to that later:
echo $this->Form->create(null, array('url' => array('controller'=>'activities', 'action'=>'results'))); ?>
<div class="box1" style="position:relative; top:10px; left:10px; float: left;">
Search here.... <br>
<hr>
<?php echo $this->Form->input('activityName', array('size'=>'30',
'label'=>'Activity Name:', 'value'=>'i.e. walking, etc.'));?>
<br>
<?php echo $this->Form->input('zip', array('size'=>'7', 'label'=>'Postal Code:')); ?>
<br>
</div>
<div class="box1" align="right">
<?php echo $this->Form->end('Go Search');?>
</div>
Here is my controller code:
<?php
class ActivitiesController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
//other code....
}
public function results() {
$this->layout = 'second';
$name = $this->request->data['Activity']['activityName'];
$pCode = $this->request->data['Activity']['zip'];
$this->set('theName', $name);
$this->set('theZip', $pCode);
$this->set('results', $this->Activity->
find('all', array('conditions' => array('name' => $name, 'postal_code' => $pCode))));
$this->set('title_for_layout', 'Results');
$this->render();
}
}
?>
My final view code. I left off some of the code...just showing the part that matters:
<div style="position:relative; top:10px; left:5px; ">
<?php echo print_r($theName); ?>
<br>
<?php echo print_r($theZip); ?>
Thanks
The 1 comes from printing the return value of print_r() which is true (i.e. 1).
In other words: you shouldn't do echo print_r(), just do print_r(). The function handles the printing by itself, you don't have to print the results manually.
(Also, print_r() is almost never the best choice to print out values except when debugging and even then CakePHP's debug() is much more suitable.)