How to access data from API response - php

I have received the following response from an API.
[{
"BookId":"32c03594-1ecb-4f97-8453-5b28a03d26d9",
"BookName":"Book1",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"51d16696-b98a-4b3b-ac67-f36559cff70b",
"BookName":"Book2",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"7b557a75-bf5e-4c29-9f31-43a7fee77520",
"BookName":"Book3",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"c945ade5-d540-4378-9979-3842a1da396b",
"BookName":"Book4",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"814869e2-e5af-48bc-a6da-28f272366955",
"BookName":"Book5",
"Bookstatus":3,
"Country":"AU"
}]
I have a webform with drop down box to choose the book you want.
What I want to happen, is when you click submit you are sent to another page, and on that page I want to be able to access the BookId, BookName and access token from the first page via $_POST. I have no trouble with the BookName but can't work out how to get the BookId and access token to go with it.
This is what I have so far:
Please note: the access token was obtained with $_GET in the head of the page and assigned to $access_token variable.
<body>
<?php
$array=json_decode($response, true);
$arr_len = count($array);//length of the array = 5
$for_len = $arr_len - 1;//length - 1
?>
<h1>CashBooks</h1>
<form action="getcoa.php" method="post">
<select name="books">
<?php
for($i=0; $i<=$for_len; $i++){
$bookname = $array[$i]["BookName"];
echo '<option value="' . $bookname . '" name="' . $bookname . '">' .
$bookname . '</option>';
};
?>
</select>
<input type="hidden" name="<?php $bookname; ?>">
<input type="hidden" name="<?php $access_token; ?>">
<input type="submit" value="Get Chart of Accounts">
</form>
</body>
With the BookId, I haven't figured out how to deal with that yet, so any suggestions would be great. And what I'm trying with the access token doesn't work. When I click submit with things how they are, I get this error on the "getcoa.php page":
"Notice: Undefined index: access_token in C:\wamp\www\getcoa.php on
line 6"
This is line 6:
$access_token = $_POST['access_token'];
FYI. The token part is solved.
But I dont think I have been clear on what I'm trying to accheive with BookId. On this page, the only thing the "USER" will see is a drop down menu with a list of BookNames, from which they select ONE, and click a submit button... On the next page, I will make a call to an API endpoint, but I need the BookId to call on that endpoint.
So the BookId for the selected BookName is needed to be somehow posted to the next page, so I can use $_POST on that page to get the BookId and use it to access the endpoint desired, without the end user knowing "BookId" exists in anyway.
Hopefully I have been more clear on what I'm trying to achieve. Sorry if I wasn't to start with.

If I have understood correctly then you are trying to send various parameters to a PHP script for processing depending upon which item from a dropdown menu is selected? Whilst there are a finite number of attributes an option tag can take you can of course use a dataset attribute - or, as in the code below, several.
So, with the help of some simple javascript, the hidden fields are populated when the select menu changes - the values stored in the hidden fields will be the ones sent to the PHP script when the form is submitted.
Previously the hidden fields had their names derived from the contents of the original source data ( the values ) - this would make processing at the server tricky as you would not necessarily know the names to use in the PHP logic tests etc - hence they are assigned names that correspond to the keys from the source data - that way you know to process fields called bookid,bookname & access-token
<?php
/* for test porpoises only */
$access_token=uniqid();
$response='[{
"BookId":"32c03594-1ecb-4f97-8453-5b28a03d26d9",
"BookName":"Book1",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"51d16696-b98a-4b3b-ac67-f36559cff70b",
"BookName":"Book2",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"7b557a75-bf5e-4c29-9f31-43a7fee77520",
"BookName":"Book3",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"c945ade5-d540-4378-9979-3842a1da396b",
"BookName":"Book4",
"Bookstatus":3,
"Country":"AU"
},
{
"BookId":"814869e2-e5af-48bc-a6da-28f272366955",
"BookName":"Book5",
"Bookstatus":3,
"Country":"AU"
}]';
?>
<html>
<head>
<title>Sending values</title>
<script>
function getelement( name ){
return document.querySelectorAll('form input[name="'+name+'"]')[0];
}
function setvalues( e ){
var n=e.options[ e.options.selectedIndex ];
getelement('bookname').value=n.value;
getelement('access-token').value=n.dataset.token;
getelement('bookid').value=n.dataset.id;
}
</script>
</head>
<body>
<h1>CashBooks</h1>
<form action="getcoa.php" method="post">
<select name="books" onchange="setvalues(this)">
<optgroup label='Books'>
<option disabled='' hidden='hidden' selected=true>Please Select
<?php
$json=json_decode( $response );
foreach( $json as $obj ){
echo "<option value='{$obj->BookName}' data-id='{$obj->BookId}' data-token='{$access_token}' data-status='{$obj->Bookstatus}'>{$obj->BookName}";
}
?>
</optgroup>
</select>
<!-- empty, hidden input fields to be populated when dropdown changes -->
<input type="hidden" name="bookid">
<input type="hidden" name="bookname">
<input type="hidden" name="access-token">
<input type="submit" value="Get Chart of Accounts">
</form>
</body>
</html>

Multiple problems found in your script:
In the select box loop, see how to write a select box
https://www.tutorialspoint.com/html/html_select_tag.htm
Fault:
echo '<option value="' . $bookname . '" name="' . $bookname . '">' .
$bookname . '</option>';
It must be something like, and there is no name property required in the options
echo '<option value="' . $bookname . '">' . $bookname . '</option>';
:: Doubts you need to pass the bookid instead of bookname
In the input boxes, you haven't echo the variables,
Instead of
<input type="hidden" name="<?php $bookname; ?>">
<input type="hidden" name="<?php $access_token; ?>">
You need
<input type="hidden" name="bookname" value="<?php echo $bookname; ?>">
<input type="hidden" name="access_token" value="<?php echo $access_token; ?>">

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
$response = '[{"BookId":"32c03594-1ecb-4f97-8453-5b28a03d26d9","BookName":"Book1","Bookstatus":3,"Country":"AU"},{"BookId":"51d16696-b98a-4b3b-ac67-f36559cff70b","BookName":"Book2","Bookstatus":3,"Country":"AU"},{"BookId":"7b557a75-bf5e-4c29-9f31-43a7fee77520","BookName":"Book3","Bookstatus":3,"Country":"AU"},{"BookId":"c945ade5-d540-4378-9979-3842a1da396b","BookName":"Book4","Bookstatus":3,"Country":"AU"},{"BookId":"814869e2-e5af-48bc-a6da-28f272366955","BookName":"Book5","Bookstatus":3,"Country":"AU"}]';
$array=json_decode($response, true);
$arr_len = count($array);//length of the array = 5
$for_len = $arr_len - 1;//length - 1
?>
<h1>CashBooks</h1>
<form action="getcoa.php" method="post">
<select name="books">
<?php foreach ($array as $key => $value) { ?>
<option value='{"<?php echo $value['BookName'] ?>":"<?php echo $value['BookId']; ?>"}'><?php echo $value['BookName'] ?></option>
<?php } ?>
</select>
<input type="hidden" name="<?php echo $bookname; ?>">
<input type="hidden" name="<?php echo $access_token; ?>">
<input type="submit" value="Get Chart of Accounts">
</form>
</body>
</html>
And on page getcoa.php can do this json_decode($_POST['books']);

Related

Pass select dropdown value outside foreach loop as a $_GET request in form action field

I am using a form having select dropdown. I want to pass the value obtained from the selected option as a $_GET request in form action field but any ways to access it outside the foreach loop. Here is the code sample that I have written
<form id="dynamicForm" action="client-detail-dynamic.php?id=<?php echo $_GET['id']; ?>&r_id=<?php **PASS THE DROPDOWN VALUE ID HERE** ?>" method="post">
<select class="form-control" id="dynamicfy" name="dynamicfy">
<?php
$j = 0;
foreach($payment_data as $pd):
?>
<option value="<?php echo $payment_data[$j]->r_id; ?>"><?php echo $payment_data[$j]->fy; ?></option>
<?php $j++; endforeach; ?>
</select>
</td>
<td class="col-md-4">
<input type="submit" name="submit" id="submit" class="btn btn-sm btn-success">
</td>
</form>
NOTE: $payment_data is an array containing the table data with field names r_id, fy etc
I have two methods for this.
First method
Create a hidden field inside form element to store the value of id.Put form action null
<form id="dynamicForm" action="" method="post">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
On submit you will get two values
if(isset($_POST['submit'])){
$id=$_POST['id'];
$r_id=$_POST['dynamicfy'];
header("location: client-detail-dynamic.php?id=" . $id . "&r_id=" . $r_id . "");
exit();
}
Second method use javascript
<select class="form-control" id="dynamicfy" name="dynamicfy" onchange="rdrt(this.value)">
<script>
function rdrt(str){
id=<?php echo $_GET['id']; ?>;
if(str!=""){
location.href="client-detail-dynamic.php?id=" + id + "&r_id=" + str;
}
}
</script>
Rather than changing the page from FORM ACTION what you can do is pick the values and set them in url passed to header:location.
try this.
``<?php
if(isset($_POST['submit'])
{
$option = $_POST['dynamicfy'];
$id = $_POST['id']
header('location: http://client-detail-dynamic.php?id=$id,r_id=$option');
}
?>
<form id="dynamicForm" action="" method="post">
<select class="form-control" id="dynamicfy" name="dynamicfy">
<?php
$j = 0;
foreach($payment_data as $pd):
?>
<option value="<?php echo $payment_data[$j]->r_id; ?>"><?php echo $payment_data[$j]->fy; ?></option>
<?php $j++; endforeach; ?>
</select>
</td>
<td class="col-md-4">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>
<input type="submit" name="submit" id="submit" class="btn btn-sm btn-success">
" />
</td>
</form>
What you are trying to do is go somewhere based in the $_GET['id]. That's not possible server side as you have to FIRST make the request, then execute code. If your aren't trying to bring form data with you to this URL, then try this suggestion. However forget what I about not possible. you could do something like:
<?php
if(isset($_POST['submit-button'])) {
header("location: file.php?something=" . $_GET['id']);
}
// set the form action to nothing and add this to the same page the form is on
// and you can redirect based on the $_GET['id']
?>
To change value on selection of dropdown, You will need to use a jQuery on change of select box.
Please refer following code for same.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(Document).ready(function() {
jQuery('#dynamicfy').change();
});
jQuery('#dynamicfy').change(function() {
jQuery('#dynamicForm').attr('action', 'client-detail-dynamic.php?id=' +<?php echo $_GET['id']; ?> + '&r_id=' + jQuery(this).val());
});
</script>
if you just want selected dropdown on the action page then You may also get selected dropdown on the action page with using $_POST['dynamicfy'] on action page "client-detail-dynamic.php"

Keep select list on reload

I have a select list, but on page reload , the data in the list is not saved of corse.
I have fixed this with TextBoxes and Radio buttons by reading the variables from $_GET.
Here is an example of the form I have now:
<form action="" id="exampleForm" method="get">
<input type="checkbox" name="exampleCheckbox" <?php if (isset($_GET['exampleCheckboxStatus'])) {echo "checked";} ?>>Check this
</br>
<select name="exampleList" multiple>
<option>Apple</option>
<option>Banana</option>
<option>Cherry</option>
</select>
<input type="submit" value="Submit" id="submitButton"> </form>
I would like to keep the values of the 'exampleList' once submitted
(I stay on the same page)
I have seen posts on here that almost look like what I ask, but most of them want to use javascript. Is there an solution for my problem, wich look similiar to what I already have right now? I would like to fix this with php because I dont think I have enough knowledge of Javascript (yet)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
var opts = localStorage.getItem('opts'); // get selected items from localStorage key
opts = opts.split(','); // split result from localstorage to array
$('#exampleList').val(opts); // select options with array
});
</script>
<html>
<body>
<select id="exampleList" multiple>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="cherry">Cherry</option>
</select>
</body>
</html>
When you POST the form you only need to write the selected option values, comma separated, to the localstorage.
I finally found a solution:
The only flaw is the order of the :)
But since I use a plugin for displaying it does not matter much.
The fix:
I created 2 Array lists
list1 with everying in it
list2 with all selected values
Then I subtract list2 from list1 and dont have duplicates
So I can print both in different print methods.
<?php error_reporting(E_WARNING);
$fruitArray = array("Apple", "Banana", "Cherry", "Durian", "Eggfruit", "Fig", "Grapefruit");
$selectedFruitArray = $_GET['exampleList'];
$fruitArray = array_diff($fruitArray, $selectedFruitArray);
?>
<form action="" method="get">
<select name="exampleList[]" multiple>
<?php
foreach($fruitArray as $value) {
echo "<option value='$value'>$value</option>";
}
foreach($selectedFruitArray as $value) {
echo "<option value='$value' selected>$value</option>";
}
?>
</select>
<input type="submit">
</form>
Use FormRepo, a plugin specially made for retaining form data
on page refreshes.
Its usage is also simple:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="FormRepo.js"></script>
<script>
var $form = $('#input')
, $output = $('#output')
, repo = new FormRepo('restclient')
;
// get the last submitted values back
repo.restore($form/*, $form.attr('id')*/ ); // don't necessarily need an identifier
$form.submit(function (e) {
// preserve the last submitted values
repo.preserve($form/*, $form.attr('id')*/ ); // don't necessarily need an identifier
});
console.log( repo.all() );
</script>
You can do it by using session. This is the way using it you can store last selected value in session. Session value will not be destroyed even if you reload paga.
For e.g.,
<?php
session_start(); // Other Code
<div>
<p>Subtitle needs to be
<input type="radio" name="subTitleRadio" <?php if ($_SESSION['subTitleRadio'] != "LIKE") echo "checked"; ?> value="LIKE">contain
<input type="radio" name="subTitleRadio" <?php if ($_SESSION['subTitleRadio'] == "=") echo "checked"; ?> value="=">be equal to
</p>
<input type="search" name="subTitleSearchBox" placeholder="filter for subtitle" class="chosenStyle" value="<?php echo $_GET['subTitleSearchBox'];?>">
</div> //Other Code
?>
PHP Code for set value in session after submit :
<?php
session_start(); //Not required if your form action is on same page, else required //Rest code
$_SESSION['subTitleRadio'] = $_GET['subTitleRadio'] // OR $_POST['subTitleRadio']; // Rest code
?>
Same code works for me.
first of all at value parameters to the options, then you can check if exampleList has the right value and use that. for example:
<option value="apple" <?php if (isset($_GET['exampleList']) && $_GET['exampleList'] == "apple") echo "selected=\"selected\""; ?>>Apple</option>
Well, you could try something along these lines. It's a bit lengthy, you could shorten it up quite a bit. By showing it this way, I hope it's simpler to understand.
<form action="" id="exampleForm" method="get">
<?php
if (isset($_GET['exampleCheckboxStatus'])) {
echo '<input type="checkbox" name="exampleCheckbox" checked> Check this';
} else {
echo '<input type="checkbox" name="exampleCheckbox"> Check this';
?>
<br />
<select name="exampleList[]" multiple>
<?php
if( in_array('apple', $_GET['exampleList']) ) {
echo '<option value="apple" selected>Apple</option>';
} else {
echo '<option value="apple">Apple</option>';
}
if( in_array('banana', $_GET['exampleList']) ) {
echo '<option value="banana" selected>Banana</option>';
} else {
echo '<option value="banana">Banana</option>';
}
if( in_array('cherry', $_GET['exampleList']) ) {
echo '<option value="cherry" selected>Cherry</option>';
} else {
echo '<option value="cherry">Cherry</option>';
}
?>
</select>
<input type="submit" value="Submit" id="submitButton">
</form>
Note that I added [] to the select's name and corrected the br tag.
Adding [] will change the type from "string" (text) to an array (several texts). Then we can check what texts are included.
Try it for yourself, play around with the code a bit.

When and how to insert data into DB on a Joomla page

I'm altering an existing Joomla 2.5 component and I wish to add data to a specific table (already existent upon install) to a couple custom columns.
So, I have this view (_quizInfo.php on the quiz view folder) code which consists of a form that displays some information (retrieved from the DB) and to proceed upon a checkbox being checked to another view (the quiz view). (Basically, it's a couple JS lines enabling the "proceed" button).
Heres the (simplified) code:
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<script type="text/javascript" language="javascript">
function proceed()
{
check = document.getElementById('checkToProceed') ;
proceedButton = document.getElementById('proceedButton') ;
if (check.checked) {
proceedButton.disabled = false ;
} else {
proceedButton.disabled = true ;
}
}
</script>
<form name="quiz_info" method="post">
<?php
echo '<div class="items-row"><div class="item">';
echo '<h2>' . JText::sprintf('YOU_HAVE_CHOSEN_TO_TAKE_QUIZ', '"'.$this->quiz- >title.'"') . '</h2>' ;
echo '<ul>' ;
...
echo '</ul>' ;
$option = JRequest::getCmd('option');
$link = JRoute::_('index.php?option='. $option . '&controller=quiz&layout=default') ;
echo '<p><input type="checkbox" id="checkToProceed" name="checkToProceed" onclick="proceed();" /><label for="checkToProceed">' . JText::_('I_HAVE_READ_AND_UNDERSTOOD') . '</label></p>' ;
echo '<input id="proceedButton" name="proceedButton" disabled="true" value="' . JText::_('PROCEED_TO_QUIZ') . '" type="submit" />' ;
echo '</div></div>';
?>
<input type="hidden" name="option" value="com_jquarks" />
<input type="hidden" name="id" value="<?php echo $this->quiz->id ; ?>"/>
<input type="hidden" name="task" value="showQuiz" />
<input type="hidden" name="view" value="quiz" />
<input type="hidden" name="layout" value="default" />
<?php echo JHTML::_( 'form.token' ); ?>
Now, I've added a form to this page so a user can fill out his/her data and then proceed (I need this data at this step to be stored), so now besides the code already showed I've added the following lines on the form tag:
//Added
echo '<li><p>' . JText::sprintf('Before proceeding you must fill the form bellow:') . '</p></li>' ;
echo '<div style="width: 50%; border: 1px solid; padding: 15px;"><form><div style="width: 100px">Full Name: </div><input type="text" name="fullname" style="width: 100%;"><br/><div style="width:100px"><br>ID document: </div><input type="text" name="iddoc" style="width: 100%;"></form></div>';
//END Added
I've noticed that the form is of POST type but there is no action defined.
The quiz view then stores all the necessary data before displaying the quiz (on the intended table) but I don't know how to proceed to store the _quizInfo view form data in the DB since it apparently isn't supposed to store anything.
The "session" is only stored (on the corresponding table) after clicking proceed and the quiz view is called.
Can anyone point me in the right direction? Not really comfortable with the way Joomla handles DB calls.
-Should I capture the POST data on the default.php file of the quiz view?
-Should I store the form data immediately?
Any help would be greatly appreciated.
Best Regards
Well, I eventually found the answer to my question, which I'm leaving here for anyone who needs it:
Any data that gets passed as POST or GET, even without a clear target/action definition (since we're working with MVC) can be accessed by using JRequest::getVar() or JRequest::get(), as mentioned in the documentation here: http://docs.joomla.org/Retrieving_and_Filtering_GET_and_POST_requests_with_JRequest::getVar

GET method with another variable already attached

I need to pass a few GET variables through. The link I need is
index.php?type=door&qty=4
I can write this easily enough like
But I need to select the $qty amount fron a drop down list. So I have
<form name="qty" method="GET" action="../../../index.php?door-type="<?php echo $door_model; ?>">';
<select>
<?php
for ($front_int=1; $front_int<=99; $front_int++)
{
echo'<option value="'.$front_int.'">'. $front_int . '</option>';
}
?>
</select>
<input type="submit" value="front-qty">
</form>
So how can I append these two values into one so that I get then $_GET them on the next page like I would with that first link I created?
If qty needs to be a select, then give that name to the select. Also, pass the other variable with a hidden field, which is pretty standard. Good luck :)
<form name="NOT_QTY" method="GET" action="../../../index.php">
<input type="hidden" name="door-type" value="<?php echo $door_model;?">
<select name="qty">
<?php
for ($front_int=1; $front_int<=99; $front_int++)
{
echo'<option value="'.$front_int.'">'. $front_int . '</option>';
}
?>
</select>
<input type="submit" value="front-qty">
</form>

Add variable into (specify text field) on the previous page

I have been looking for a way to add the information (string) from a variable in the previous page.
As far as I know this should be possible using javascript somehow.
New one couldn't get the old one to work properly..
<script type="text/javascript">
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=510,width=350,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
Armory Avatar
I have that piece of code that opens the link into a new popup window(which remembers the url of the previous page).
In this window people can insert some information about there WoW character and the realm this character is on. After they do this and hit submit the site displays the url for the avatar retrieved from the blizzard armory.
http://eu.battle.net/static-render/eu/(imagepath)
Code for the popup page: Updated this current code (7-4-2012)
<?php
if (!isset($_POST['submit'])) {
?>
<!-- The fill in form -->
<html>
<head>
<title>Armory Avatar</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Character Name:<input type="text" size="12" maxlength="50" name="cname"><br />
Realm Name:
<select name="rname">
<optgroup label="English Realms">
<option value="aerie-peak">Aerie-Peak</option>
<option value="agamaggan">Agamaggan</option>
<option value="aggramar">Aggramar</option>
etc etc etc.
</optgroup>
</select><br />
<input type="submit" value="submit" name="submit">
</form>
<?php
} else { //If form is submitted execute this
$charname = $_POST["cname"]; //input character name
$realmname = $_POST["rname"]; //input realm name
$charurl = urlencode(utf8_encode($charname)); //prepares character name for url usage
$realmurl = 'http://eu.battle.net/api/wow/character/'.$realmname.'/'; //combines the basic url link with the realm name
$toon = $realmurl.$charurl; //adds the charactername behind the realm url
$data = #file_get_contents($toon); //retrieves the data from the armory api
if ($data) {
// if armory data is found execute this
$obj = json_decode($data); //converts the data from json to be used in the php code ?>
<img src='http://eu.battle.net/static-render/eu/<?php echo $obj->thumbnail; ?>'> </img><br /> <?php //Is url link to image
$armoryname = utf8_decode($obj->name); //makes the name readable again
echo "Name: " . $armoryname . "<br />"; //character name
echo "Level: " . $obj->level . "<br />"; //character level
echo "Achievement Points : " . $obj->achievementPoints . "<br />"; //Achievement Points
if ( $obj->gender == 1 ){ //Deteremines the gender of the character
echo "Gender : Female <br />" ; //displays gender as female
}else{
echo "Gender : Male <br />" ; //dispalays gender as male
}
$image = "http://eu.battle.net/static-render/eu/".$obj->thumbnail;
?>
Image: <a href='http://eu.battle.net/static-render/eu/<?php echo $obj->thumbnail; ?>'> http://eu.battle.net/static-render/eu/<?php echo $obj->thumbnail; ?></a><br />
<!--Button submit code-->
<script type="text/javascript">
$('button.cancel_link').click(function() {
// Change the value of the input with an ID of 'avatarurl'
// with the dynamic value given to you by the external JSON link
window.opener.getElementById('avatarurl').value = '<?php echo $image; ?>';
});
</script>
<input> <!-- The button here -->
<?php
}
else { // if armory data is not found execute this ?>
error code stuf
}
}
?>
Now i need this line of code:
$image = "http://eu.battle.net/static-render/eu/".$obj->thumbnail;
To be returned when the window is closed or simply by hitting another submit button(prefered to happen on close over button). And when either of those happen it needs to insert this into this string:
<input type="text" class="textbox" name="avatarurl" size="25" maxlength="100" value="{$avatarurl}" /></td>
The texbox called avatarurl.
Hopefully any of you know how to modify or create a javascript that does this for you. Since my php is already severely limited and my javascript knowledge is next to none.
You need to modify the way you're closing your pop-up window. Try something like this:
// When a BUTTON with the class name 'cancel_link'
// is clicked, it activates the following
$('button.cancel_link').click(function() {
// Change the value of the input with an ID of 'avatarurl'
// with the dynamic value given to you by the external JSON link
window.opener.getElementById('avatarurl').value = '<?php echo $image; ?>';
});
You need to make sure your closing link has cancel_link as its class name, and that your input element in your parent document has an id of avatarurl.
So after searching trying and thanks to #Jamie i knew where to look.
I found http://www.codingforums.com/showthread.php?t=213298
And this was finally the thing that worked.
On the php page to open it i added:
<script type="text/javascript">
function open_pop(){
window.open('armory.php','AvatarArmory','height=510,width=350,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<html>
.....
<input type="button" value = "OpenArmory" onClick="open_pop()" />
And added id="blogbox" to the input for the textbox.
<input type="text" class="textbox" name="avatarurl" size="45" value="{$avatarurl}" id="blogbox"/>
On the armory.php page i added this button with the javascrip function:
<script type="text/javascript">
function pops(avatar){
textcontent=opener.document.getElementById("blogbox").value;
opener.document.getElementById("blogbox").value = textcontent + " " + avatar;
}
</script>
<input type="button" value = "Insert Avatar.." onClick="pops('<?php echo $image; ?>');window.close()" />
And that worked perfectly.
Thank you jamie for the help.

Categories