Forums

Redirect from form to differnt connection

fredm 15 Apr, 2011
I have been struggling with this and I have not been able to get an answer because of my inability to describe the issue, basically I want to use a connection (connection A) in the normal fashion but on the form used to edit Connection A records I want to have a button that sets a session variable to a value and redirects to another connection (Connection B ) which uses that session variable in the query. I have tried to affect the redirect url by putting it in the Form Redirect Url blank and I have tried to use the redirect plugin. Am I looking for too much, in the wrong place or just not doing it correctly?
fredm 16 Apr, 2011
Is this question too difficult? I was expecting a response by now. Maybe I am looking for the wrong thing but I can't find an answer in the cookbook.
Max_admin 17 Apr, 2011
Hi fredm,

Honestly I can't understand what you need to do but for this complicated stuff you better use Chronoforms V4, study it well first to understand how it works (there are few tutorials in the V4 forums) then try t do what you need, should be easier and more customizable

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fredm 17 Apr, 2011
Ok, maybe I ma just not clear enough, being that I am working on it directly it is easy for me so I am probably not explaining well enough. But here we go, I am working with a community theatre, I am trying to track production information. WHo directed, blah, blah blah. I have a Chronoconnection which lists the productions and opens the Chronoform to edit it. This works perfectly, in another ppart of the application I have it sending multiple emails, substituting text for field values, it is great and I am very happy with what it allows me to accomplish. Now comes the BUT! Every production has a list of many performance dates, the number of which varies form show to show. The problem is that I am trying to put a button on the Chronoform that edits the Production to link to a Chronoconnection which lists the performance dates and allows me to edit them individually. I have tried changing the redirect url by changing it in the general tab and I also tried the redirect plugin. I really think what I am trying to do is probably really simple if I were clearer in my explanation or smarter in recognizing what goes on.

I had included a little text diagram in an earlier post which looked real good on my end, but I just looked at it in the preview mode and I can see that it could not have been helpful. So here is my best effort at eplaining the tables.


Productions tables -> a connection to list them -> a form to edit them--> a button to redirect to the connection for the ProductionDatesList (with info to affect the query)


ProductionDatesList -> a connection to list them -> a form to edit them
Max_admin 17 Apr, 2011
Hi fredm,

well, It's a bit clearer now, what prevents you from adding a link to the product edit form which will take you to the dates Connection ? I can't understand whats the problem with that, the link will take you to the dates list and you may just enable the editing for those dates as well as long as the dates connection is working fine

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fredm 20 Apr, 2011
Ok I got the form to redirect ( I can not figure out what I was doing wrong). Now I am having a problem with the use of JRequest. My idea is to store a key value in a session variable and when the connection form opens it reads the variable to use in setting up a query, so that I only get the Production Dates for the Production we were editing. I just can't figure out the syntax and I can't seem to find a clear example.
GreyHead 21 Apr, 2011
Hi fredm,

JRequest doesn't get Session variables (get, post, cookie & server only). You need to use JSession instead.

<?php
$session =& JFactory::getSession();
$session->set('name', 'value', 'namespace');
?>

<?php
$session =& JFactory::getSession();
$var = $session->get('name', 'default value', 'namespace');
?>
Using Namespace is optional in both cases, it defaults to 'default'.

Bob
fredm 21 Apr, 2011
Ok before I give uo and admit failure here is the code:

On form 1 have a hidden field named cf_id There is also a button and it looks like this:
<INPUT TYPE="BUTTON" VALUE="Production Dates" ONCLICK="mNewRedirect()"> 


In the Javascripy block I have this:

function mNewRedirect() {
                var out1 = document.getElementById('cf_id');
                if (out1.value.length >0) {
                out1.value = out1.value.substring(0,0);
                };

               <?php
               $session =& JFactory::getSession();
               $session->set('fProduction', out1.value);
               ?>
          window.location.href='http://www.slidelllittletheatre.org                                /index.php?option=com_chronoconnectivity&Itemid=143&fProduction=out1.value';
               }


When I click the button it sends me to the right connection which has the following code in the in the where sql block:

<?php
              $where=''
              $session =& JFactory::getSession();
              $myfProduction = $session->get('fProduction',null);
              if ( $myfProduction ) {
              $where = ' WHERE fkProductions = '.$myfProduction;
               }
              echo $where;
              ?>



And I get this when the page loads up:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
Parse error: syntax error, unexpected T_VARIABLE in /homepages' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_ProductionDates
Parse error: syntax error, unexpected T_VARIABLE in /homepages/13/d294629477/htdocs/slt/components/com_chronoconnectivity/libraries/connection.php(168) : eval()'d code on line 3
New
Production Dates
Date Time(24hr) Adults Seniors Youth Comps No Shows Receipts
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
Parse error: syntax error, unexpected T_VARIABLE in /homepages' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_ProductionDates
Parse error: syntax error, unexpected T_VARIABLE in /homepages/13/d294629477/htdocs/slt/components/com_chronoconnectivity/libraries/connection.php(168) : eval()'d code on line 3

Warning: Invalid argument supplied for foreach() in /homepages/13/d294629477/htdocs/slt/components/com_chronoconnectivity/libraries/connection.php on line 300
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
Parse error: syntax error, unexpected T_VARIABLE in /homepages' at line 1 SQL=SELECT count(*) FROM jos_chronoforms_ProductionDates
Parse error: syntax error, unexpected T_VARIABLE in /homepages/13/d294629477/htdocs/slt/components/com_chronoconnectivity/libraries/connection.php(168) : eval()'d code on line 3




So two questions, can you point me in the right direction and when I buy you a beer do you drink it before you answer of after?
GreyHead 22 Apr, 2011
Hi fredm,

The error is referring to a query with COUNT in it which isn’t the one that you are setting up here. Do you have any other code in the WHERE box?

Bob

PS I'm also not sure that the PHP will work in the middle of the JavaScript (but it might).
fredm 22 Apr, 2011
Thanks for everything but, nope all that was there was a short query but I think that was related to the query in the where messing it up. In any case I have made some progress with your regarding the use of php session variables. I can set a variable and retrieve it and use it in my query. The problem now seems to be being able to set the environment variable to the value of the contents of the cf_id field. I get "cf_id" or "cf_id.value" as text instead of the contents. So I am think it has something to do with how I am setting it. If I just set it to what the contents equal it seems to work fine. So I am thinking it has to do with string conversion or something.
GreyHead 23 Apr, 2011
Hi fredm,

I think that the problem is probably with this code.
function mNewRedirect() {
                var out1 = document.getElementById('cf_id');
                if (out1.value.length >0) {
                out1.value = out1.value.substring(0,0);
                };

               <?php
               $session =& JFactory::getSession();
               $session->set('fProduction', out1.value);
               ?>
          window.location.href='http://www.slidelllittletheatre.org                                /index.php?option=com_chronoconnectivity&Itemid=143&fProduction=out1.value';
               }
I can't work out what it is supposed to do and I doubt that the PHP in the middle will do anything useful.

Bob
fredm 23 Apr, 2011
Naturally you are correct it fails, but it seems as if the problem is being able to get the value of the hidden input named cf_id and pass it to a session variable. When executing the aforementioned code the session variable is set but I get just the name not the value when I retrieve it.
GreyHead 24 Apr, 2011
Hi fredm,

I'm sorry I find it really hard to understand where this code is and what it is trying to do.

If you already have a value for cf_id in a hidden input can't you just add to to a link url instead?

Bob
fredm 24 Apr, 2011
Thanks for your patience, instead of you trying to figure out how I am trying to do this can you tell me what I need to do to get the cf_id field from a chronoform into a session variable so it can be retrieved and used as part of the query where statement in a chronoconnection. Your answer really needs to be explicit because apparently part of the problem is my lack of understanding concerning where certain pieces of code go ie. is it javascript or PHP, does it go in the form or a piece of special code. I am sorry to be such a pain but I am trying to use this experience to learn about this stuff and I am finding it very confusing. I feel like I have gotten close but each time I just can't seem to get it to work.
fredm 24 Apr, 2011
I really feel like the answer to this must be so obvious and you guys know it but you can't imagine I am having problems because it is so simple. But I am......
GreyHead 25 Apr, 2011
Hi fredm,

As I don't understand what you are trying to do I don't know where the cf_id code comes from. That makes it hard to tell you how to get it into a session variable.

Bob
GreyHead 25 Apr, 2011
Hi fredm,

Please see this post earlier in this thread and replace 'value' with $cf_id

Bob
fredm 25 Apr, 2011
Okay I have this code in a ChronoForm for editing a record in the Production Table.
<?php
$session =& JFactory::getSession();
$session->set('myProductionKey', $cf_id );
?>

I have tried locating it in the body block, the javascript block and in the on submit block after the email.

I have the following code in the where block of a chronoconnection which lists the records in the ProductionDates table with the intention of limiting the list to those records whose fkProduction field equal the session variable I pass in which should contain the cf_id of the related production
<?php
$where='';
$session =& JFactory::getSession();
$myfkProduction = $session->get('myProductionKey',0);
$where = " where fkProductions = ".$myfkProduction." ";
echo $where;
?>

It seems like it is always defaulting to 0 even when the record in Production has a cf_id value of 1. I put a copy of the above Where code in the header of the connection and it shows that the query is where 'fkProductions' = '0'.

If I force a value by replacing $cf_id in the code that sets the session variable with a literal value it works as desired but if I pass $cf_id it seems to fail. In my opinion, yeah I know like I should have an opinion, but anyway it seems as if the the value of $cf_id is not in scope or not set when the code executes. I have tried to move it around but no luck.
GreyHead 26 Apr, 2011
Hi fredm,

You asked for the code for getting $cf_id into a session variable and that's what you have. You also need to make sure that $cf_id has a value when you put it in the session variable.

The code snippet is PHP so it doesn't go into the Form JavaScript box. It will work in most of the other boxes depending on what you are trying to do here. My best guess is that the On Submit After Email box is the right place.

Bob
fredm 26 Apr, 2011
I know you guys are probably sick of hearing from me but I thought it was clear that I was attempting to use the cf_id, a primary key field from one table as a foreign key field in another table. I beleive this is a very common process and I thought it would be fairly straight forward. So no wthe question becomes how do I get the value of the hidden field cf_id which is generated by Chronoforms into a Session Variable which I can pass to the query of a chronoconnection?
GreyHead 26 Apr, 2011
Hi fredm,

I'm sorry to be going round in circles but I still don't know where this "hidden field cf_id which is generated by Chronoforms" is coming from.

If you have used a DB Connection to save or edit a record then the saved values, including the value of cf_id, are available after the DB Connection in an object $MyForm->tablerow["#__some_table_name"]

Bob
fredm 26 Apr, 2011
When you create a form in Chronoforms then use CF to create the database table it adds the field to the table and sets it up to be a primary key. Since it is a Primary key it would also serve as a foreign key in any child records tied to the record with cf_id as the primary. I put a hidden field named cf_id on my form so I could capture the primary key of the record. I want to pass this to the connection for the child records so I can create a where that would limit the records to those associated with the form.
GreyHead 27 Apr, 2011
Hi fredm,

Please see my last post.

Of course, the cf_id value is not available until the record is created (after the form is submitted) so it isn't available when the Form HTML is created and can't be set in a hidden input in the Form HTML.

Bob
fredm 27 Apr, 2011
Obviously that is true but after the record is created if I got to the for to edit it I can access the cf_id by using a hidden input. Is there a way for me to pass the value from that hidden input a connection for use in the where block? I am not real concerned about the method, I previously mentioned I wanted to use a session variable but that is not the important thing. What I really need is the best way to get the value of the hidden field passed to the connection.
fredm 27 Apr, 2011
Would it be better to use Curl or pass it the way you guys pass cids in the url. If so how do I get the cf_id in the url and back out in the connection?
.
GreyHead 28 Apr, 2011
Hi fredm,

I'm sorry I am once again completely lost. You already have the code which you asked for to let you pass it in the User session; You could equally use a text, file, a cookie, a database entry or add it to the URL. I can pretty much guarantee that you don't want to use cURL; the ReDirect plug-in would be better suited but is a sledgehammer to crack a nut in this case.

Where is the URL that you are using to redirect to the CC Listing?

Bob
fredm 28 Apr, 2011
Here is the for code the form. It still contains code from my earlier attempt as passing the variable to a session variable. The is a piece of code in the Javascript at the bottom for the click event which redirects to the connection I want to hit. My goal is to send make the value of the hidden field available to the connection for use in the query. I am not really concerned about how it gets there since it will just be a number, but the more secure the better. I appreciate your patience, I just can't seem to grasp where to use which type of code, html, PHP or Javascript and which variables are available to each at any given time.



<table border=0 Width=60% align="center" >
<tr align="center">
<td align="right">Production</td>

<td><input  align="left" maxlength="75" size="40" name="Production" type="text"></td>
<td></td>

<td align="right">Publisher</td>

<td><input align="left" maxlength="75" size="40" name="Publisher" type="text"></td>

</table>

<br>

<table border=0 Width=90% align="center" ><tr>
<td right>Director
</td>

<td>
<input align="left" maxlength="35" size="35" name="Director"  type="text"></td width=3%>

<td></td>

<td align="right">Producer</td>

<td><input align="left" maxlength="35" size="35" name="Producer"  type="text"></td>
</tr>
</table>

<br>

<table border=0 Width=60% align="center" >
<tr>

<td align="right">Stage Manager</td>

<td><input align="left" maxlength="35" size="35" name="StageManager" type="text"></td>

</table>
<br>


<table border=0 Width=100% align="center" >
<tr align="center">
<td align="right" valign="top" width="5%">Cast</td>

<td align="left" width="45%"><textarea rows="3" cols="50" name="Cast"></textarea></td>
<td align="right"  valign="top" width="5%">Crew</td>

<td align="left"  width="45%"><textarea rows="3" cols="50" name="Crew"></textarea></td>
</tr>
</table>

<table border=0 Width=100% align="center" >
<tr><td colspan="2" align="center">
<input type="button" value="Production Dates" onclick="myReDirect()";>
</td>
<td colspan="2" align="center">
<input value="Submit" name="Submit" type="Submit"  >
</td>
</tr>

<tr>
<!-- <input id="cf_id" name="cf_id" type="hidden"> -->
<!--     line 97 -->
</td>
</tr>
</table>

<?php
$session =& JFactory::getSession();
$session->set('myProductionKey', $cf_id );
?>


function myReDirect(){
window.location = "http://www.slidelllittletheatre.org/index.php?option=com_chronoconnectivity&Itemid=143";
}
fredm 04 May, 2011
I have two tables, Productions and PerformanceDates, each has a primary key of cf_id. There is a 'one to many' realtionship between them. PerformanceDates has a field which contains a foreign key to the Productions table named fkProductions. I am trying to set a session variable with the value of the cf_id field and redirect to a chronoconnection where the session variable is recalled and used as in a where statement. I have been able to redirect the page by adding a button whose click event changes the window redirect. I have been unable to get the session variable to work. I have tried setting it in different locations on the form and on the on submit before and after email blocks. I need real clear explanations because I am really starting to doubt my intelligence on this one. Any help would be greatly appreciated as I am trying to help a local non-profit, but so far I am failing miserably.
GreyHead 07 May, 2011
Hi fredm,

This looks like the same question as in your previous thread. I still find it impossible to answer the question because it is unclear where the information is that you are trying to write to the session variable.

You already have the code to get the cf_id for a new record in the OnSubmit After Email box. You can add it to a session variable there using the session code which you also have.

Bob
fredm 07 May, 2011
Thanks for responding, I just can't seem to put it together so that it works. What I am trying to do is put the value of the hidden field 'cf_id' into the session variable so I can retrieve it in the "where" block of a Chronoconnection to filter the records. I have tried as many things as I can come up with, actually trying again right now, but I just don't seem to be able to get it to work. I don't actually want the cf_id of a new record, I want the cf_id of the existing record. I am going to try what I think you are suggesting and see what I can get. Should this process show up in the debug form if it is turned on.
GreyHead 07 May, 2011
Hi fredm,

I'll merge these two threads because I can't see that this is a different topic.

I don't think that I have anything new to offer here.

If you turn Debug on in the form you will see the data that is being submitted, including the value of any hidden input; but not the results of any processing that is done after the form is submitted.

Bob
fredm 07 May, 2011
Thanks for your patience. Based on your last post I did the following:

Placed this code in the submit after email block, $cf_id I am hoping will grab the value of a hidden input and mymessage is just a test.
<?php
$session =& JFactory::getSession();
$session->set('myProductionKey', $cf_id );
$session->set('mymessage', 'here is some message text');
?>

This code is placed in the where block of a chronoconnection that the above form redirects to.
<?php
$session =& JFactory::getSession();
$myfkProduction = $session->get('myProductionKey');
$where = "";
if ($myfkProduction)
{
$where = " where fkProductions = ".$myfkProduction." ";
}
?>

This code is placed in the body block of the chronoconnection.
<?php
$session =& JFactory::getSession();
$mymessage = $session->get('mymessage');
echo "Test";
echo "<br>";
echo $mymessage;
echo "test";
?>


Nothing shows up when I get to the connection. Could teh problem be that I am using button onclick (in javascript) event to redirect to the connection so the On submit never executes, if so how do I dynamically redirect the page?
GreyHead 07 May, 2011
Hi fredm,

Could the problem be that I am using button onclick (in javascript) event to redirect to the connection so the On submit never executes

Yes, that's exactly right. If you use any immediate redirect, including the ChronoForms OnSubmit URL then ChronoForms never sees the form.

If you want to use the JavaScript redirect then you'll need to modify the script so that it gets the value from the hidden input and adds it to the URL.

Or you can put your Session adding code into the Form HTML.

Otherwise you can use the ReDirect plug-in (which is probably overkill for this application) or just build and set a redirect url in one of the OnSubmit Before boxes.
<?php
$cf_id = JRequest::getInt('cf_id', '', 'post');
$uri = 'some_uri&cf_id='.$cf_id;
$MyForm =& CFChronoForm::getInstance();
$MyForm->formrow->redirecturl = $uri;
?>

Bob
fredm 07 May, 2011
Thanks let me play with this, I really need it in a session variable so I can drill down through the receiving chronoconnection. I will let you know what happens, I know you can hardly wait.😉
fredm 07 May, 2011
Here is where we stand, I can set a session variable and pass it around put the problem seems to be capturing the appropriate variable value. I have a hidden input field on the form entitled cf_id. When I view the source of the page it has the expected value.

I tried the following code at the top and bottom of the html block of the form with no change.

<?php
$cf_id = JRequest::getInt('cf_id', '', 'post');
echo "my Id ".$cf_id;
$session =& JFactory::getSession();
$session->set('myProductionKey', $cf_id );
$session->set('mymessage', 'here is some message text');
?>
$cf_id seems to keep coming up blank. Below is the line for the hidden input just in case.

<input id="cf_id" name="cf_id" id="cf_id" type="hidden">
GreyHead 07 May, 2011
Hi fredm,

The code there will get it correctly if it is set in the URL used to call the form - if it isn't then it will be blank.

I'm sure we've been here before :-(

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