Forums

Generating a code with a short form

fredfitaire 24 Feb, 2011
Hi,

I'm looking for a solution that I could include in an article, allowing my user to generate a code from an article.
A bit more details :

I use the "Artsexylightbox" plugin from artetics that gives the possibility to include a Picasa gallery within an article. The way to include it in an article is to paste a code like this:

{artsexylightbox Picasaalbumname}{/artsexylightbox}

It's not user friendly enough, so I would like to include a short form in my online help, only one field asking for the Picasa album name. Then, this form would return in another field the complete code that could be copied and paste in the article by my user.

Is this possible with ChronoForms ?

Thanks for your help.
;)

Do not hesitate to ask if it's not clear !
GreyHead 24 Feb, 2011
Hi fredfitaire ,

That sounds as though it should be possible. Hard to tell for sure without building it though.

Bob
fredfitaire 24 Feb, 2011
Thanks Bob for the confirmation, but now ... the killing question: how ?!!! 🤣
fredfitaire 01 Mar, 2011
Well ... no answer, but my question was probably too rough ! So I worked a bit and found myself the begining of a solution.

I added the following code within my article:
<form method="post" action="verif.php" target="blank"><br />Paste your Picasa gallery address in this field: <input name="address" size="50" type="text" /><br /><input value="then press this button" type="submit" /><br /></form></div>


and then, created the following "verif.php" file:
<?php
$address = $_POST['address'];
if(empty($address))
{
print("You didn't copy your Picasa album address !");
exit();
}
preg_match('@^(?:https://)?([^/]+)/([^/]+)/([^/]+)@i', $address, $matches);
$result=$matches[3];
echo '<div align="center"><font face="arial" size="2" color="blue">This is your code : </font><br/><br/>';
echo '{artsexylightbox picasaUser="myusername" picasaAlbum="';
echo str_replace("#","",$result);
echo '" carousel="true" carousel_visible="4"}{/artsexylightbox}';
echo '<font face="arial" size="2" color="blue">Paste it within your article</font>';
?>


Sorry if the code is not at its best but I'm not a php developper. I only assembled some code parts found on the web.
Anyway, it does work well ! except that,

- it doesn't use ChronoForms but works with the standard Joomla form code. Therefore, I get no benefits from the ChronoForms style and functionalities.
- the verif.php file is placed in the www directory of my site. So that means an add-on file that is not on the Joomla package. I'm not sure it's safe ...
- the result is shown on a new page (or tab, depending on your browser settings). I would like it to be displayed on the same page as the one hosting the form (so, my article), and placed in a new field (in order that the code is not parsed by Joomla)

Well, now that the hardest part of the job is done, who can help me to integrate this in Chronoforms ?!

Thanks 😀

NB: for those who wish to understand my php file, this is a typical Picasa album URL:
https://picasaweb.google.com/username/albumname#
So my code:
- starts at https://picasaweb.google.com
- then search for the third field --> gives "albumname#"
- then erases the last #
GreyHead 01 Mar, 2011
Hi fredfitaire,

In Chronoforms I think this would look something like this.
Form HTML:
<div>Paste your Picasa gallery address in this field: <input name="address" size="50" type="text" /><br /><input value="then press this button" type="submit" /></div>

Serversided validation:
<?php
$message = '';
$address =& JRequest::getVar('address', '', 'post');
$mainframe->enqueuemessage('$address: '.print_r($address, true).'<hr />');
if ( !$address ) {
  $message = "You didn't copy your Picasa album address !";
} elseif ( !filter_var($address, FILTER_VALIDATE_URL) ) {
  $message = "This doesn't appear to be a valid URL !";
} elseif ( strpos($address, 'https://picasaweb.google.com/') !== 0 ) {
  $message = "This doesn't appear to be a Picasa album address !";
}
if ( $message ) {
  return $message;
}
?>

In the OnSubmit After Email box:
<?php
$address =& JRequest::getVar('address', '', 'post');
$address = substr($address, 29, strlen($address) - 30 );
$vars = explode('/', $address);
?>
<div align="center">
  <font face="arial" size="2" color="blue">This is your code : </font><br/><br/>
  {artsexylightbox picasaUser="<?php echo $vars[0]; ?>" picasaAlbum="<?php echo $vars[1]; ?>"
    carousel="true" carousel_visible="4"}{/artsexylightbox}
  <font face="arial" size="2" color="blue">Paste it within your article</font>
</div>
Not tested and may need debugging.

Bob
fredfitaire 02 Mar, 2011
Thanks a lot Bob !

There are some remaining bugs:

- serversided validation:
The URL is wrong in your code (https://picasa.googleweb.com). The good one is https://picasaweb.google.com/ . Despite the modification, I always get a "This doesn't appear to be a Picasa album address !" message, even if my URL is good. I tried to understand what is wrong in the code but didn't find any answer. So I disabled the server side validation to check the rest.
It's better if the validation works, but if you have no time to debug it, it doesn't really matter !

- OnSubmit After Email:
Does work well except that the # is not removed from the picasa album name. On my previous (ugly !) code, I did it with :
echo str_replace("#","",$result);

I tried to modify your code with :
<div align="center">
  <font face="arial" size="2" color="blue">This is your code : </font><br/><br/>
  {artsexylightbox picasaUser="<?php echo $vars[0]; ?>" picasaAlbum="<?php echo str_replace("#","",$vars[1]); ?>" 
    carousel="true" carousel_visible="4"}{/artsexylightbox}
  <font face="arial" size="2" color="blue">Paste it within your article</font>
</div>

The Picasa album name has no # now but I'm not sure that this modification has a proper php code ...

Anyway, thanks again, I really appreciate your help😉
GreyHead 02 Mar, 2011
Hi fredfitaire,

The serverside validation needs this line fixed
} elseif ( strpos($address, 'https://picasaweb.google.com/') !== 0 ) {
The problem is that the correct result is 0 and that equates to 'false' in the code I had.

The OnSubmit After Email code needs this line changed to drop the # off the end
$address = substr($address, 29, strlen($address) - 30 );


Bob

PS I'll go back and fix my original post.
fredfitaire 03 Mar, 2011
Tested your bugs fix, all is OK !
Nice job Bob, thanks😉

I will now seek in the forum a way to include this form in an existing article.
GreyHead 03 Mar, 2011
Hi fredfitaire,

Use the ChronoForms Mambot/Plug-in from the downloads area here.

Bob
fredfitaire 03 Mar, 2011
Ok, found, installed and all is ok !

Well, I'm a bit a perfectionist 😶 and would prefer displaying the form result in a pop up or a lightbox rather than a new page (from which I must return back to my article).

I tried to adapt your "Show a form in a light-box " article to my need but without success.
The main difference whith my own need is that I call the form not from a module but within an article. So I don't need the form to be in the lightbox, just the result.
Is it possible easily ? Just give me some clues, I'll try to do it by myself !
GreyHead 03 Mar, 2011
Hi fredfitaire,

I'm not sure, but Fredrik (nml375) posted something on modal buttons a day or two ago that might do what you want.

Bob
fredfitaire 03 Mar, 2011
OK, you probably refer to this topic: http://www.chronoengine.com/forums.html?cont=posts&f=2&t=21032&p=65467#p65467

I spent an hour trying to do the same, but didn't succeed.
What I did:

- I kept the same main form (called "genecode") as previously

- I created a new form (called "lightbox") with the following HTML code:
<?php
JHTML::_('behavior.modal', 'button.modal');
?>
<a class="modal"
  href="/index.php?option=com_chronocontact&%20%20chronoformname=genecode&tmpl=component"
  rel="{handler: 'iframe', size: {x: 400, y: 200}}"
>Générez votre code</a>


- within my article, I added the following code:
<button rel="{handler: 'iframe', size: {x: 700, y: 500}, href: '/index.php?option=com_chronocontact&chronoformname=lightbox&tmpl=component'}">Click me!</button>


When I click on the button, no lightbox opens. What did I miss ?
nml375 03 Mar, 2011
Hi fredfitaire,
First, the button lacks the "modal" class, which you used in your pattern ('button.modal'). This will prevent the onClick-event from being applied to your button.

Secondly, I just discovered there's an issue with the modal.js script where the rel-property is not properly read in a DOM fashion. This will cause an empty, white modal to be opened on some browsers, regardless of the content of the rel-attribute.
Fix follows:
Locate the fromElement function (around line 133 or so) in media/system/js/modal.js.
Edit the line accordingly:
if (this.element && this.element.rel) options = $merge(options || {}, Json.evaluate(this.element.rel));
/* Change into this */
if (this.element && this.element.getProperty('rel'))
  options = $merge(options || {}, Json.evaluate(this.element.getProperty('rel')));


As I've understood though, you're trying to show the result of the submission in a modal, while the form remains on the underlying page? If this is the case, I'm afraid you'll have to do quite a lot more.

/Fredrik
fredfitaire 04 Mar, 2011
Hi Fredrik,

Thanks for your help.

I've added class="modal" to the button code. Now, a lightbox opens upon a click, but it's displayed blank.
Then, I modified the modal.js as explained, but the lightbox remains blank ...

As I've understood though, you're trying to show the result of the submission in a modal, while the form remains on the underlying page? If this is the case, I'm afraid you'll have to do quite a lot more.


Yes, that's exactly what I would like to do. But if the form is also on the lightbox, it's not a real problem.

I'm not sure I will spend more time on this enhancement. Bob's solution works well, so I'll probably use it.
Unless you have another idea of what could be wrong in my code ?

Anyway, thanks again for your help😉
nml375 04 Mar, 2011
Hi,
Do you notice any javascript-errors while loading the page or clicking the button?

Also, could you post or PM a link to the form?

/Fredrik
fredfitaire 04 Mar, 2011
No javascript errors while loading ...

For a reason that I don't understand, the lightbox only appears for registered (and logged) users.
Nothing happens for the visitors. Therefore, I'll create you a registered member account and send it to you with the URL by PM.
nml375 04 Mar, 2011
Hi,
I've had some time to check the form now. It seems I made an error in the other thread; you cannot use the 'href' value within the ref-property, it has to be 'url'.

/Fredrik
fredfitaire 07 Mar, 2011
Thanks Fredrik, but even with 'url', it doesn't work.
Many thanks for your help but I give up and will keep Bob's solution.
This topic is locked and no more replies can be posted.