How do I use the variable I requested [Half-SOLVED]?

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
Marvin_Martiano
Joomla! Intern
Joomla! Intern
Posts: 92
Joined: Fri Sep 09, 2011 12:36 pm

How do I use the variable I requested [Half-SOLVED]?

Post by Marvin_Martiano » Wed May 20, 2015 10:53 pm

Heavily rewritten post* but a (logical/philosophical/technical) question remains:

Why can I not treat a requested (in the tmpl/default.xml) variable in the same way as the hidden variables in my form? Because having to look it up from the URL seems illogical?

I'm dealing with a handful of variables that I treat all the same, except one that I get by requesting it in the configuration of a menu item... All others I can easily read off from $this->items; but the requested one is not there. [EDIT] I can easily read it off with JFactory::getApplication()->input->get('myparam', '0', 'int'); as it's an integer, but this seems strange/unnatural versus the others.

A related question is why the "hidden" variables are not hidden (you can read them from the HTML or in Firebug/Inspect-element) so [1] it exposes my db-variable names for no reason? And [2] they don't seem to take a CSS class (or is that Protostar's fault?), so their containers take up vertical space (which I cannot kill without javascript, as there's no CSS "parent" selector?

----
(* Basically I was an over-tired idiot circling around -- all in all just forgotten an "echo", therefore convinced that I couldn't touch my variable, and I kept complicating and complicating my efforts at getting it from several wrong locations and handing it over in less and less sensible ways)

Marvin_Martiano
Joomla! Intern
Joomla! Intern
Posts: 92
Joined: Fri Sep 09, 2011 12:36 pm

Re: How do I use the variable I requested [Half-SOLVED]?

Post by Marvin_Martiano » Fri May 22, 2015 11:37 am

To answer my own question about the "hidden" parameters: It's up to the writer of the view to take care of this, it's not done automatically by Joomla. And Joomla cannot take care of it, it cannot practically know that you're wrapping DIVs around a thing that should be hidden.

So the solution is trivial: The view's original display instructions

Code: Select all

<?php foreach ($this->form->getFieldset('myfields') as $field) : ?>
					<div class="fieldcontainer">
						<div class="fieldlabel">
							<?php echo $field->label; ?>
						</div>
						<div class="fieldcontent">
							<?php echo $field->input; ?>
						</div>
					</div>
				<?php endforeach; ?>
now just have to check for fields being "hidden" or not -- here I strip it all out by only showing if type is not "Hidden" (capital letter is needed):

Code: Select all

<?php foreach ($this->form->getFieldset('myfields') as $field) : ?>
					<?php if($field->type != 'Hidden') : ?>
					<div class="fieldcontainer">
						<div class="fieldlabel">
							<?php echo $field->label; ?>
						</div>
						<div class="fieldcontent">
							<?php echo $field->input; ?>
						</div>
					</div>
				<?php endif; endforeach; ?>
The alternative is to keep the hidden fields in and make the CSS hide them by adding a class (as e.g. RSforms does, judging by the screenshot on a topic on their forum) --- but what's the point, a bit more HTML and CSS are involved, as well as exposing parameters and values? You did hide(didn't make them readonly) them for a reason, and this (by default, unless you do some renaming in parameter handover which can cause naming mistakes) shows a db field name and possibly embarrassing info (e.g. parameter is "user_service_level" with value "overcharge_because_user_is_clown"): in that first DIV, add a class name like so...
<div class="fieldcontainer <?php if($field->type = 'Hidden') : echo 'nodisplay'; endif; ?>">

helln
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Tue Jun 16, 2015 2:40 pm

Re: How do I use the variable I requested [Half-SOLVED]?

Post by helln » Tue Jun 16, 2015 4:47 pm

Hey,

the third parameter of JInput->get is the filter parameter what filters the returned values, in your case integer ('int'), so it will not return anything else than an integer. try the following code for strings:

Code: Select all

JFactory::getApplication()->input->get('myparam', 'defaultVal', 'cmd');
There are several methods like, getString etc. to deal with this filter automatically, so i would not use the get method directly. See:
https://api.joomla.org/cms-3/classes/JInput.html

Code: Select all

<?php if($field->type != 'Hidden') : ?>
indicates, that you have fields with type="Hidden" defined in your form XML file. Try changing them to:

Code: Select all

<field name="mysecretvariable" type="hidden" default="" />
Then they should be invisible in the normal browser view. Well correct me if I'm wrong, but since HTML forms are submitted by the client and those input elements, even hidden, still are part of the submitted data, they will always be visible in the HTML source code (or Firebug/Inspect-element), because your Browser needs to submit them to the server.

Regards
Nik


Locked

Return to “Joomla! 3.x Coding”