|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
magicmike Smarty n00b
Joined: 24 Feb 2015 Posts: 3
|
Posted: Thu Feb 26, 2015 1:34 am Post subject: Dependable Selections |
|
|
Please go easy on me I'm new to Smarty and programming as a whole.
I want to build a small site for my hobby that helps compare paints for model kits etc.
so I looked for some php dependable dropdowns and worked with this one.
http://amecms.com/article/Building-Chained-Select-Boxes-with-Jquery-and-PHP
In normal PHP I can get it working fine but I would like to use it in partnership with smarty so I assigned my variables in my homepage based on the first dropdown with manufacturers such as Revell and Italeri.
Code: | $manufacturers = Array( [0] => Tamiya, [1] => Revell, [2] => Italeri); | etc
And all worked fine until I tried using smarty the variable goes via Jquery and to the request file and I get the right response and I can see in the source the html dropdown options but I can't select them or see them.
Code: | <b>Notice</b>: Undefined index: manufacturers in <b>C:\xampp\htdocs\libs\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code</b> on line <b>42</b><br />
<br />
<b>Notice</b>: Trying to get property of non-object in <b>C:\xampp\htdocs\libs\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code</b> on line <b>42</b><br />
<select name="posted_data[manufacturers]" id="manufacturers">
</select> |
Am I missing something or should I say I'm obviously missing something but what !! - can't seem to get my head around what's not happening. Once again apologies for the lameness undoubtedly this will be something so simple I need to a dunces cap |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Feb 26, 2015 2:57 am Post subject: |
|
|
Please show us, how do you assign and use variables?
It seems, you are using the name in a context, where it is unavailable. |
|
Back to top |
|
magicmike Smarty n00b
Joined: 24 Feb 2015 Posts: 3
|
Posted: Thu Feb 26, 2015 10:09 pm Post subject: |
|
|
Ok so do my fetch array for manufacturers
Code: | if($result1 = $db_conx->query("SELECT `manufacturers`.`manufacturer` FROM `manufacturers`")){
if($count = $result1->num_rows) {
$rows = $result1->fetch_all(MYSQLI_NUM);
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($rows));
$list = iterator_to_array($it,false);
$manufacturers = array_combine(range(1, count($list)), array_values($list));
}
}
$smarty = new Smarty;
$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->assign("manufacturers", $manufacturers);
$smarty->assign("type", '----');
$smarty->assign("subtype", '----');
$smarty->assign("models", '----');
$smarty->display('index.tpl'); |
This populates the initial dropdown for manufacturer and it works fine in smarty
using
Code: | {html_options id="manufacturers" name="posted_data[manufacturers]" options=$manufacturers} |
When I select any manufacturer I can see the request going off and the response is the correct
which is basically an array of cars, warships, tanks, etc
but its not populating the type dropdown allowing it to be selected.
Obviously this is happening via the javascript as shown in the link
Code: | {literal}
<script>
$('#manufacturers').change(function(){
var manufacturers = $(this).val();
$.post('request2.php', {manufacturers:manufacturers}, function(data){
$('#type').html(data);
});
});
</script>
{/literal} |
|
|
Back to top |
|
magicmike Smarty n00b
Joined: 24 Feb 2015 Posts: 3
|
Posted: Tue Mar 10, 2015 7:34 pm Post subject: |
|
|
Ok thought I would try this on a fresh start and used an different version
Code: |
function ajax_post(){ // Create our XMLHttpRequest object
var hr = new XMLHttpRequest(); // Create some variables we need to send to our PHP file
var url = "request.php";
var man = document.getElementById("manufacturers").value;
var vars = "manufacturers="+man;
hr.open("POST", url, true); // Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // Access the onreadystatechange event for the XMLHttpRequest object
hr.onchange = function()
{ var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
alert(hr.responseText);
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
}
|
Now I can see the data going to the .php file but I can't see any responses.
but if I assign the variables in the php file to smarty I can see a response only then via the smarty variable.
But again the next dropdown isn't changing its state from empty to full so I'm obviously doing something stupid...lol
How do you check that the javascript is actually responding ?
[/quote] |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|