Forums

Require Assistance!!!!

varsha 16 Jun, 2010
I have six forms, every user who registers would have registered on one of the 6 forms.

now on logging into the website, he has option to edit his profile on the single link how to do i identify the logged in user to the form he has registered and bring it to him for editing.

Note: i have used profile pageplugin to get data , added hidden field to make update happen, got user id dynamically in the url(its not requried i guess ).

How to make this work at front end with that edit link on the home page once he logs in.


Urgent
Max_admin 18 Jun, 2010
Hi Varsha,

I think you need to run some PHP code before the form is even loaded to switch between the different forms, and of course store a filed with form_id in your users data table

Or maybe do a redirect through some form to other forms based on the same form_id field value stored

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
varsha 21 Jun, 2010
Hye max,

I tried with the second option of using an intermediate form to redirect to other forms, tru php coding ...sad it dosent seem to work its coz i have no idea of php, until now was working with extensions and other usages..

i will give the code here could you check it out if it works...

1) a url is contructed manually
2) pass this url into a variable
3)created a javascript onLoad function and cal this php url( this is where it just work, not able to pass the variable the javascript)

could you please help me with this and the code toooooo...i could manage only this... :?

<?php

$aaaaaaaaaa;
$user =& JFactory::getuser();
//echo "user->id  ".$user->id ; 
//$aaaa =array("aa","bb","ccc");
$userType = array("tmpstudentprofile","vform", "acadmicprofile","tempaauthorprofile","enduserprofile");

//echo  "aaaaaa  ". count($userType);
for($i=0; $i<count($userType); $i++){
  // echo  " \n for loop : ". $i." - ". $userType[$i];
   hai($userType[$i], $user->id);
}

function hai($Tname, $uid){
    //echo "Tname - Uid : " .$Tname."  ,". $uid;
    $redirectUrl="http://localhost/ae/index.php?option=com_chronocontact&chronoformname=";
    $db=& JFactory::getDBO();
    $Query= ' SELECT cf_user_id FROM '.
            ' jos_chronoforms_'.$Tname.
            ' WHERE cf_user_id ='.$uid;
   // echo "Query  : ". $Query;
    $db->setQuery( $Query );
    $result = $db->loadResult();
    //echo $Tname."   Total Records --- ". count($result);
   // echo "\n";
    if(count($result)!=0){
     //echo "url : ".$redirectUrl.$Tname."&cf_user_id=".$uid;
       //echo " \n redirectUrl = ".$redirectUrl.$Tname."&cf_user_id=".$uid;
      echo 'bbb'.$aaaaaaaaaa = $redirectUrl.$Tname."&cf_user_id=".$uid;
      // $redirectUrl = .$redirectUrl.$Tname;
    }
}
?>
<body onload= "haiOnload()" >
<div class="form_item">
  <div class="form_element cf_heading">
    <h1 class="cf_text">InterMediate Form</h1>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Temp text</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="text_1" name="text_1" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>
</body>

<input type="hidden" name="hidUrl"  id="idHidURL" value="<? $aaaaaaaaaa  ?>" />
<script>
function haiOnload () {
//alert("aaa - 1 : " + 
  //var aa= '<?php  $aaaaaaaaaa ?>';
 var sss = document.getElementById('idHidURL').value;
 alert("haiOnload : "+ sss );
//alert("haiOnload : ");
}
GreyHead 23 Jun, 2010
Hi varsha,

I don't understand what you are trying to do here. I think perhaps you need a link table to connect the uer_id and the form type? Then you could look that up instead of checking each table in turn.

There are several typos in your code that won't be helping.
$user =& JFactory::getUser();
<input type="hidden" name="hidUrl"  id="idHidURL" value="<?php echo $aaaaaaaaaa ?>" />
and Body tags are not permitted in the Form HTML.

Bob
Addy 31 Jul, 2010
I am not sure, but it looks as if the poster is trying what I would like to do.

The unique id string auto generated for the database (uid) I would like to take from the first form table and use it as a ID. I am not looking for a user id, more a var which is different every time someone looks on form 1. Then I place this into the user session and have it load into each form there after, so every table has a common ID.

Now I could use a query and search the database of the form I just created, but I can see issues in that, so thought as you have already done a random string, I could tap into that.

The question is, I cannot see it in the $_Post of the debug of the form submit, so I am not sure where to find it, so to grab it ?
GreyHead 31 Jul, 2010
Hi Addy,

You may be able to modify this code snippet. Here I'm updating the same databse record in each step of a multi-page form. The cf_id is created when the first step is saved; in the second step I look up the value and put that into a hidden input which is then passed on to each succeeding step.

I use a second hidden field to save the form name of the step so that I can refer back to is from the next form.
<input type='hidden' name='step_name' id='step_name' value='<?php echo $MyForm->formrow->name; ?>' />
<?php
$cf_id =& JRequest::getString('cf_id', '', 'post');
if ( !$cf_id ) {
  $last_step_name =& JRequest::getString('step_name', '', 'post');
  if ( $last_step_name ) {
    $formData =& CFChronoForm::getInstance($last_step_name);
    $data =& $formData->tablerow['jos_assessments'];
    $cf_id = $data->cf_id;
  }
}
echo "<input type='hidden' name='cf_id' id='cf_id' value='".$cf_id."' />";
}
?>

Bob
Addy 31 Jul, 2010
Hmm.. Thank you for your post. I think that makes sence, but at what point from the form load does the uid created. The string must be created and stored somewhere, so to add the value to the database.
Because it is not in the $_POST array, I am guessing it's created before any button is pressed?

Does the code below search the current form table?
    
    $formData =& CFChronoForm::getInstance($last_step_name);
    $data =& $formData->tablerow['jos_assessments'];
    $cf_id = $data->cf_id;


So this is in order of code:

- Checking the form name
- Load a value in $cf_id which should have been already created
- Check if it's empty
- If it is empty, based on the form name in 'step_name' which the value is then put into $last_step_name (the name of the form)
- If $last_step_name equals something, check the database table of the current form. getInstance, I take it shows ONLY the entered by by that user, then get the cf)id value, put it into $cf_id ?

Correct??? If more than one user was entering at the same time, there would be no chance of the cf_id getting mixed up ?
Addy 31 Jul, 2010
$uid =& JRequest::getString('uid', '', 'post');
if ( !$uid ) {
  $last_step_name =& $MyForm->formrow->name;
  if ( $last_step_name ) {
    $formData =& CFChronoForm::getInstance($last_step_name);
    $data =& $formData->tablerow['jos_chronoforms_form_start'];
    $uid = $data;
  }
}


Tried the above code, it is not bring the value over😟
GreyHead 31 Jul, 2010
Hi Addy,

The UID ('cf_id' in this case) is created when the data is saved to the database table. It's the primary key value of the new record. ChronoForms then saves this into the tablerow object along with the other saved data.

Your interpretation is more or less correct.

In the code this line
$data =& $formData->tablerow['jos_assessments'];
needs to have the name of the table from the corresponding DB Connection.


Bob
Addy 31 Jul, 2010
It could be me not explaining myself, or just not understanding!

The table I have, has the cf_id as the primary key, but I am not looking for that, I am looking for the uid random string. Here is my table:



This is the data once saved:



You can see the long string right of uid. I need this, to be in every form created after the first one (jos_chronoform_form_start). This cannot be user pacific, but form created pacific.

What I am looking to do, is to get that uid random string and put it into a var which I can then put into a session variable. Putting it in the session is not my problem, it's getting hold of the uid (random string) and storing it.

Using this code

$uid =& JRequest::getString('uid', '', 'post');
if ( !$uid ) {
  $last_step_name =& $MyForm->formrow->name;
  if ( $last_step_name ) {
    $formData =& CFChronoForm::getInstance($last_step_name);
    $data =& $formData->tablerow['jos_chronoforms_form_start'];
    $uid = $data;
  }
}


Using the above code does not get the data from either the stored var - uid or the uid random string stored in the table ('jos_chronoforms_form_start').

So what I need is the created random string stored in the databse table called uid to also be stored in $uid ?
Addy 31 Jul, 2010
For reference, I am putting the code to collect this information in the formcode tab under On Submit after email?
Addy 31 Jul, 2010
I really need assistance with this please Bob!

I need to understand it, and know where and how to collect the random uid string thats created and auto placed in the table as shown above.

Please help, as the direction you have shown is not working for me.

Thanks in advance!
nml375 31 Jul, 2010
Hi,
A few comments:
The 'tablerow' property of the CFChronoForm object is only filled after the DB storage is completed, and cannot be used to retrieve a JTable instance from an earlier submission - That is, if you store data from Form1 in jos_chrono_form1, then you cannot read that from within Form2, but only in the "post processing" part of Form1 (on submit - after email).

Adding a hidden cf_id input will not work as planned. CF uses JTable objects for DB storage, these have a very important behavior: If the primary key is assigned a value, then JTable assumes this row already exists, and tries to edit it rather than adding it as a new record. But, since we're trying to add a new record, the "UPDATE TABLE SET ... WHERE cf_id = 123" SQL-query will silently fail.

The uid column is filled by default with a hashed random value, which cannot be trusted to be unique to the user or session. That is, two users may very well end up with identical uid values along the road. Your best bet for a unique identifier would be the primary key value of the first table.

To fetch the cf_id from the inserted data, and store it in the session storage; I'd use the following code on the "on submit - after email" code of the first form (form_start):
<?
$session =& JFactory::getsession();
$session->set('primary_key', $MyForm->tablerow['jos_chronoforms_form_start']->cf_id, 'mynamespace');
?>


Then, on the following forms, I'd either add a hidden form input (simple, but users might fake this), or use the "serverside validation" code to verify that the session value exists and add it to the form field values posted:
<input type="hidden" name="parent" value="<?
$session =& JFactory::getsession();
echo $session->get('primary_key', 0, 'mynamespace');
?>" />

or
<?
$session =& JFactory::getsession();
$t = $session->get('primary_key', 0, 'mynamespace');
if ($t == 0) {
  return "You have to complete the first form!";
}
JRequest::setVar('parent', $t, 'post');
?>


Finally, once the last child-form has been completed, clear the session data:
<?
$session =& JFactory::getSession();
$session->clear('primary_key', 'mynamespace');
?>


The code is not tested, and written from memory, so it will most likely need some debugging. It also assumes that each "child" DB-table has a row named "parent", which links the child to the "parent" (jos_chronoforms_form_starts).

/Fredrik

Edit: Two minor typos sorted.
Addy 31 Jul, 2010
That you Fredrik! That makes alot of sense and thank for you spending the time to write it. I understand now the use of it, and how best to deal with it.

I do have one question, maybe stupid, but you mentioned "mynamespace". Could you explain what this is, and why I need it ?

Thank you again! Very much appreciated.
nml375 31 Jul, 2010
Hi Addy,
Certainly, the JSession class implements "namespaces" - a convenient way to avoid name collisions (that is, when two pieces of code try to use the same session storage name at the same time).
ChronoForms make use of a separate namespace, so even though say the MultiPage CFPlugin makes use of the session storage 'chrono_step_myform', it is stored in a separate namespace; and even if I were to add a piece of code like below, this would not interfere with the MultiPage plugin:
<?
$sess =& JFactory::getSession();
$sess->set('chrono_step_myform', 'bad value'); //Using default namespace
$sess->set('chrono_step_myform', 'bad value', 'mynamespace');  //Using 'mynamespace' namespace
//Neither interferes with the md5('chrono') namespace used by chronoforms
?>


You could of course choose pretty much any string you'd like instead of 'mynamespace', as long as you use the same througout all forms that need to access the session data.

/Fredrik
Addy 31 Jul, 2010
Thank you again Fredrik!

I have tried a number of combinations without much luck! Here is the code I have used on Form 1 (start)
$session =& JFactory::getsession();
$session->set('primary_key', $MyForm->tablerow["jos_chronoforms_form_start"]->cf_id, 'mynamespace');

The above code I have entered onSubmit after email. At this time, I am not looking to send a email.

This is what I am using to display the value of cf_id on form 2
<input class="cf_inputbox required" maxlength="150" size="30" title="" id="text_3" name="text_3" type="text" value="<?php echo $session->get('primary_key', 0, 'mynamespace');
?>"  />


It is displaying in the text_3 text box: 0 Which I am guessing is the default!

I am at a loss. Spent some more time searching the forums, found a number of topics regarding get this ID to sent in emails, and I have seen success, just not for me. Not sure why?

It might be worth noting, I am not using any plugin, and I simply moving from form to form.
GreyHead 31 Jul, 2010
Hi Addy,

Please now go back and read my earlier post which tells you one way to do this.

Bob
nml375 31 Jul, 2010
Hi Addy,
Yes, that would be the default value.
Could you check the RunOrder settings of the form?

For $MyForm->tablerow['...'] to actually contain something, the autogenerated block has to be executed before the onSubmit block.

/Fredrik
Addy 31 Jul, 2010
Resolved!!!!!!

The problem, after reading another post was down to the order in which the code on run. I am not sending an email, so I left the database to run after the email, and changed the autoGenerated code to:

Order of Plugins block = 1
Order of Autogenerated block = 2
Order of OnSubmit block = 3

So the code fires, the data is saved, hence able to enter the cf_id, and for me to collect it. This has been a 4 day task! And I am going to have a whisky now!!!

You will notice Fredrik it was your last post on the link above that resolved and finally made the penny drop for me. So thank you twice!

The code you gave worked! Thank you Thank you Thank you!!!!
This topic is locked and no more replies can be posted.