Forums

Why is jRequest not working?

trinity 28 Sep, 2011
Just installed chrono forms v4 and Joomla v1.7. The primary
functionality, I want to achieve with chrono is as follows.

1. user clicks on a form link in an article
2. form is loaded in a lightbox
3. article id and url is captured in hidden input fields.

I have used the custom feature of chrono forms to build my form.
Here is the code, I am using to implement step 3.

<?php

$article_id = JRequest::getInt('id', 0, 'get');
$url = JRequest::getString('url', '', 'get');

?>


<input type="hidden" name="ArticleID" value="<?php echo $article_id; ?>" id="articleid"/>
<input type="hidden" name="ArticleUrl" value="<?php echo $url; ?>" id="articleurl"/>


This code is placed within the form tag <form>...code....</form>

This does not work. From related post in the forum, this should work.

http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=23891


I am speculating that it is my form behaviour (loading form in a pop box) that
is causing JRequest not to work. Is this correct? If so, how do I overcome this
problem?

Thinking in this direction, I used the form wizard to run the JRequest code
in controller and view modes during form load (on load event). This
does not work either.


What I am missing?
GreyHead 28 Sep, 2011
Hi trinity,

Used like this JRequest will return values from the Current page URL. If that include the id=xxx parameter then $id will have a value. It's unlikely to include a 'url' parameter unless you are building very customised URLs.

What is the URL of a typical article page on your site?

Bob
trinity 28 Sep, 2011
Hello Bob,

>Used like this JRequest will return values from the Current page URL.

hmm... this is what I was suspecting. So, how do I get the values of the
parent page (so to speak)?

>If that include the id=xxx parameter then $id will have a value.

yes, if I put id=0, it returns 0, which doesnt help very much.

>It's unlikely to include a 'url' parameter unless you are building very customised URLs.

No there is no customised url just the typical Joomla article url. I am thinking, if
I could get the article_id, I might create the url using data from the joomla
database.
trinity 28 Sep, 2011
I have devised a work around which might be usefull
to somebody else...

I used

<?php
$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
?>

to get the article url than at the server, I parsed the url
string to get article id.

Depending on what u are doing, this solution could break, if
you change things around. If anybody, knows a more elegant solution,
i would be happy to hear it.
GreyHead 29 Sep, 2011
Hi trinity,

What is the URL of a typical article page on your site?


If the URL contains the id then you can get it from:
<?php
$id = JRequest::getInt('id', '', 'get');
?>
What I'm not sure about is what happens if you have SEO URLs set up so that the id isn't displayed. I think that then this won't work - but usually with a bit of code you can unravel the SEO URL to get the article ID.

Joomla! makes the current URL available to you in the URI object:
<?php
$url = JFactory::getURI();
?>
If you check the Joomla! docs there are a whole series of methods there for extracting parts of the url including individual parameters.

Bob
This topic is locked and no more replies can be posted.