Dinamic Url redirect from a field value

elblues 23 Nov, 2011
Hi,
I've read the threads about the subject, but I would need some little more help with my issue.
I'm using CF 4RC2 on J! 1.5.22, and I need the user to be dinamically redirected to form2 or form3 in another page of the site when he submits the form1, depending on the value he has choosen in a field of form1; form1 should also post data to the other form. Example: in form1 the user fills name and email fields in, then chooses from a radio "purchase" or "information" and when he submits he is redirected to the Purchase form (in the first case) or to the Information form (in the second case), in which name and email fields are already filled in with the values ha has typed in form1.
Should I do this with CF plugins or some php code? I had found this:
$MyForm =& CFChronoForm::getInstance();
$MyForm->formrow->redirecturl = $uri;

but I do not know how to complete it nor where I should put it in CF4.
Any help will be most appreciated!
Thank you!
GreyHead 24 Nov, 2011
Hi elblues,

In CFv4 there are two actions that you will need to drag into the OnSubmit event. First a ReDirect URL action that will let you build a dynmaic URL; second, a ReDirect User action that will do the actual redirection (this should be the final action in the event).

Bob
elblues 24 Nov, 2011
Hi Bob,
thank you very much for your reply.
May I ask you some more details about the two actions? I would need the user to be redirected to one url if he chooses a value from a radiobox, or to another if he chooses the other value of the same field: which kind of param should I put in the actions? Do I need 2 Redirect Url actions (one for each redirect)? Should I leave the Redirect User empty as suggested in the Help?
Sorry for all these questions! And thanks once again...
GreyHead 25 Nov, 2011
Hi elblues,

which kind of param should I put in the actions?


Depends what the URLs for the redirect pages are.

Do I need 2 Redirect Url actions (one for each redirect)?


No, the purpose of the ReDirect URL action is to create a dynamic URL i.e. one that depends on the data from the form.

Should I leave the Redirect User empty


Yes.

Bob
elblues 25 Nov, 2011
Hi Bob,
and thank you once again.
The fact is that i do not need to build up a new url with the value of the form field, but to redirect user to an existing one, depending on his choice (the "dynamic" of the subject refers to the redirect, not to the url!).
May i kindly ask you to make me an example of how i have to configure form actions?
I have these elements:
FORM1
name_field
email_field
radio_field (choice between value 1 and value 2)
submit_button

value1: redirect to
/info.html = FORM2
name_field2 = name_field
email_field2 = email_field

value2: redirect to
/shop.html = FORM3
name_field3 = name_field
email_field3 = email_field

I thank you so much...
GreyHead 29 Nov, 2011
Hi elblues,

In that case you can still use the ReDirect User action but add the URL you want to use to $form->data['redirect_url'] or you can use the Joomla! $mainframe->redirect() method.

Bob
Max_admin 01 Dec, 2011
Hi elblues,

Adding to Bob's suggestions, you may also use a "Custom server side" validation box to route to 2 different "Redirect URL" actions, one in the "on fail" and one in the "on success", just make sure that you make the validation fail for one of the values.

Actually it will not be used as a validator in this scenario, it will be a binary value checker or something like that.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
armand 09 Dec, 2011
Hi,

I have a similar problem.

I have tried on forum to solve my problem but nothing.

On the web site http://www.worldonvoip.com/, you can see the form : CREER UN COMPTE.

I'll like that :
- when a user field the form, some informations in this form be used to complete my url
- and i also need that the url be send to execute API.

My API url get this structure :

https://worldonvoip.com/API/Request.ashx?command=createcustomer&username=xxxx&password=xxxx&customer=&customerpassword=&geocallcli=&tariffrate=1

I need that chronoform help to take in my form and repalce them in the url and then excecute the url.
customer=input_text_1 (NOM D'UTILISATEUR)
customerpassword=input_password_2 (MOT DE PASSE)
geocallcli=input_text_9 (TELEPHONE)


Thanks for your help.
AF.
Max_admin 09 Dec, 2011
Hi Armand,

Do you need a redirect to this URL ?

if yes then here is an example, use the code below in a "custom code" action in the "on submit" event:


<?php
$mainframe =& JFactory::getApplication();
$mainframe->redirect('https://worldonvoip.com/API/Request.ashx?command=createcustomer&username='.$form->data['username_field'].'&password='.$form->data['pass_field'].'&customer=&customerpassword=&geocallcli=&tariffrate=1');
?>


Please replace the fields names in the code.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
armand 10 Dec, 2011
Hi,

I have used the custom code and i get the good result (means creation of the account in the second base).

My new problem is that when the execution of my API, the technical result appears :

<CreateAccount><Customer>tehou18</Customer><CustomerLoginName>tehou18*worldonvoip.com</CustomerLoginName><Result>Failed</Result><Reason>GeoCallCLI not in correct format.</Reason><Result>Success</Result><Reason>Tarifflist added</Reason><Result>Success</Result><Reason>Request completely succeeded</Reason></CreateAccount>


Is it possile to do that this technical reason those not appears, and then i can place my own message.

Thanks.
AF.
GreyHead 10 Dec, 2011
Hi armand,

Hard to tell from the information you've posted but it looks as though perhaps you should not be Redirecting to the API url but instead making a call to it using cURL. You'll need to check the API documentation to see exactly what is needed.

Bob
armand 11 Dec, 2011
Hi,

How can i do excute my API in a new frame, not in the mainframe ? or
to excute it in an invisible frame, not in the mainframe ?

Tx.
GreyHead 11 Dec, 2011
Hi armand,

Sorry I don't understand the question?

Bob
armand 11 Dec, 2011
By frame, i means windows.

I'll like that my API been execute in a new windows or in an invisible windows, and not in the principal windows.

Then, the principal page steal open and i'll be able to place another message.

Tx
armand 12 Dec, 2011
Hello,

(i'm french speaking).

There is no body to help me for my precedent question about windows in php ???


I trying once again to use Redirect URL.

Please, in the ''Params/Fields map'', may i put mapping with this format :

customer=form_input_text_1
customerpassword=form_input_password_2

Tx.
GreyHead 12 Dec, 2011
Hi armand,

Vous pouvez écrire ici en français si vous voulez.

There is no body to help me for my precedent question about windows in php ???

I don't underetand what the question is, sorry :-(

Please, in the ''Params/Fields map'', may i put mapping with this format


Yes, that's correct.

Bob
armand 19 Dec, 2011
Hi Bob,

J'ai réussi à faire fonctionner la redirection vers mon API, autant avec l'aide du code PHP qu'avec la redirection web de l'utilisateur.

Seulement, ça ne résout pas véritablement mon problème de base.

Je voudrais en fait exécuter cet API sans pour autant que l'utilisateur soit redirigé vers le lien de l'API, et donc sans qu'il ne puisse avoir accès à ce lien au niveau de la barre d'adresse de son navigateur.

Y a-t-il une solution ?

AF.

The Google version:

I managed to run the redirect to my API, all with the help of PHP code with the user's redirection.

But it does not really solve my basic problem.

I would actually run this API without the user being redirected to the link to the API, so that it can not access this link at the address bar of their browser.

Is there a solution?

GreyHead 19 Dec, 2011
Bonjour Armand,

Si vous souhaitez envoyer seulement les données et non l'utilisateur, puis utiliser l'action CURL.

If you would like to send just the data and not the user; then use the CURL action

Bob
armand 19 Dec, 2011
Je pensais effectivement que le CURL était destiné à celà. Mais, j'ai essayé en vain; l'API n'est pas exécuté avec le CURL.

Je met comme "URL" un truc du genre :
https://promowebsa.org/API/Request.ashx?command=createcustomer&username=&password=&customer=&customerpassword=&geocallcli=&tariffrate=

Au niveau de "HEADER IN REPONSE", je laisse NO.

Et comme "fields map", j'ai entré ceci :

username=xxx
password=xxx
customer=input_text_1
customerpassword=input_password_2
geocallcli=input_text_9
tariffrate=1


Ai-je commis une erreur ?
armand 20 Dec, 2011
Hi Bob,

Yesterday, i have send a reply about CURL.

I was saying that i have allready try to solve my problem using CURL but nothing.

What i did is put this url in CURL :
https://promowebsa.org/API/Request.ashx?command=createcustomer&username=&password=&customer=&customerpassword=&geocallcli=&tariffrate=

For "HEADER IN REPONSE", i leave NO.

In fiel map, i wrote this :

username=xxx
password=xxx
customer=input_text_1
customerpassword=input_password_2
geocallcli=input_text_9
tariffrate=1


Do i get something wrong because it not work ?
GreyHead 20 Dec, 2011
Hi armand,

You have to separate out the query string from the Target URL here. In the url you posted
https://promowebsa.org/API/Request.ashx?command=createcustomer&username=&password=&customer=&customerpassword=&geocallcli=&tariffrate=
everything before the ? is the Target URL and everything after the ? has to be handled as part of the query string.
The Target URL is
https://promowebsa.org/API/Request.ashx

And these values have to be added to the Code box:
command=createcustomer
username=
password=
customer=
customerpassword=
geocallcli=
tariffrate=
You already have all of these except for command=createcustomer

There is a problem with the standard CURL action; it can only use form variables, it can't accept constant values like command=createcustomer :-(

So we have to use a Custom Code action *before* the cURL action to add these to the Form Data.

In the Custom Code action add:
<?php
$form->data['command'] = 'createcustomer';
$form->data['username'] = 'xxx';
$form->data['password'] = 'yyy';


Then in the cURL action put
command=command
username=username
password=password
customer=input_text_1
customerpassword=input_password_2
geocallcli=input_text_9
tariffrate=1

Bob

* If you use my custom cURL [GH] action then you can add both fixed and variable values and you don't need the extra Custom Code action.
armand 20 Dec, 2011
Hi Bob

Thanks for your indications.

I'll try them and read doc.

I'll give the result.

AF.
armand 22 Dec, 2011
Hello Bob,

It's good now. Immediatly i suscribe a licence to remove the "commercial" link on my web.

Can you tell me if a documentation exist then i will read to know how managing many others aspect of chronoforms ?

Tx.
GreyHead 22 Dec, 2011
Hi armand,

There is only a small amount of documentation for CFv4 - most of the knowledge is in th forums here. There are a few tutorials on this site; there are some videos here and there are a few more articles on my site here - I'm gradually adding more CFv4 articles and videos when I can find the time.

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