Forums
Redirect from form to differnt connection
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
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
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
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
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?
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).
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
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
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
<?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.
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
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
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
.
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
<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";
}
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
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
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?
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
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">