Forums

Help with a Search form

simong 09 Dec, 2010
Hi Bob...
I am wondering if you can help... I have created a multi-page form that is functioning well - I can complete the form, view the data and even go back and update the resulting pages correctly in the database - by adding "cf_id=000" after the string... it all works perfectly. (In essence I am at about Page 300 of the Cookbook)

What I am having a lot of trouble getting my head around is building - a simple query that will call up my form - so that I can edit it... click submit and it will update the data. I feel sure the basics are there in the Cookbook... though I am not seeing them for the trees.

Can you reference the Cookbook in providing a solution?

Thanks in advance for your help

Simon
GreyHead 09 Dec, 2010
Hi Simon,

When you say you want to call up the form - this is the Multi-page form?

Basically the answer is the same as for any other form. You need to look up the saved results from the database table and set the values in the Form HTML.

Looking at the table of Contents I think the book only uses the Profile Page plug-in to do this which is not all that much use to you with a multi-page form. There is some information in the ChronoConenctivity 'View Details' tutorial here. It doesn't cover an editable version but the mechanics are the same.

Bob
simong 09 Dec, 2010
Hi Bob.


Well... no. In essence all I am trying to do is do a simple SEARCH and DISPLAY RESULTS (that were input from a Chronoforms multi-page form)

So... First name; Surname; Username
-> SUBMIT
= Email; Address; Date of Birth; Phone; etc etc.

(I am unsure whether I should be asking here or over at Joomla.) I only want to produce the string that gets me the "...... &cf_id=00" mentioned on page 300. (A simple search result; I will then place this result, into a mutlipage form that allows the Admin to edit the SPECIFIC data)

You probably already cover it ... though I am just not seeing it

Simon
GreyHead 10 Dec, 2010
Hi Simon,

A rather circular answer but where is the cf_id stored? How would you know which is the correct one? Is it linked to the user in some way?

Bob
simong 10 Dec, 2010
haha Bob... seems it is about time I bought you a beer... now is that a Stella Artois or Duvel???

I have created a 'membership' form that extends the Joomla user db... it holds not only "name" and "email" but also height, weight etc. It works perfectly with a db I have titled 'jos_chronoforms_CLBase' (is also integrated with the jos_content and jos_user db)

Here is the initial page - the form that I would like to use to bring up the data...
http://www.artatwork.com.au/peakFit/index.php?option=com_chronocontact&chronoformname=mbr_UPDATER

step two is
http://www.artatwork.com.au/peakFit/index.php?option=com_chronocontact&chronoformname=mbr_Update2
This form is editable; and will update the User's extended rego info. "CF_ID" is in the CLBase table

By adding "&cf_id=160" (for example) you get the user/member info.

My question... what does it take to draw the CF_ID=00 from the CLBase table and add it to the URL


Sorry for the verbosity

Simon
GreyHead 11 Dec, 2010
Hi Simon,

I'm still missing something. I take it that cf_id isn't the same as the Joomla! user ID?

To get from Form 1 to Form 2 I'd expect something like:
<?php
$frstname = JRequest::getString('frstname', '', 'post');
$name = JRequest::getString('name', '', 'post');
$prefUID = JRequest::getString('prefUID', '', 'post');
$where = array();
if ( $frstname ) {
  $where[] = "`name` LIKE '$frstname%'";
}
if ( $name ) {
  $where[] = "`name` LIKE '%$name'";
}
if ( $prefUID ) {
  $where[] = "`username` = '$prefUID'";
}
$where = implode (' AND ', $where);
$db =& JFactory::getDBO();
$query = "
  SELECT `cf_id`
    FROM `#__users`
    $where ;
";
$db->setQuery($query);
$cf_id = $db->loadResult();
$mainframe->redirect('index.php?option=com_chronocontact&chronoformname=mbr_Update2&cf_id='.$cf_id);
?>
There are some problems with this. The search may not return a single result, this will give you the first result if there are several. It will also not handle all partial matches - so Sim would find Simon, but mon wouldn't.

Bob

PS I notice that you are using textareas as inputs and not text inputs - is there a reason for this?
simong 11 Dec, 2010
hi Bob...
answers -
:: the cf_id is not the same as the Joomla ID; no. Should it be??? and
:: textareas as inputs!! I honestly did not look; the form was probably built on the 12 iteration of a form I liked, that I found in a client's website -😀 The whole thing will need to be re-written and ported to the clients site (it has the validated license)

Just regarding the "first and partial" result - I was hoping having the three fields would compensate... this all stems back to my original question (some weeks ago) about putting all the UserNames into a drop-down. ( Which prompts another question - I am full of them [hehe] - could that be adapted here??? )

Though let me go away and try this code you have suggested (thanks again); and see what results I can produce...

TIA, Simon
GreyHead 11 Dec, 2010
Hi Simon,

If it's data that is uniquely linked to a user then it usually makes sense to use the Joomla! user id as an index as it's easy to access.

The User drop-down could work here perfectly well.

The problem with searches that return multiple results is that you really need to show a list of possible results and then let the user pick the one that they want. This isn't too hard to do but this code doesn't include that intermediate step.

Bbo
simong 19 Dec, 2010
Hi Bob

Its not working!
I am wondering if there is need to use the "Multi-Page" plug in at all. (It seems I am getting nowhere!!! 😟 )

Could I not just use a simple form/query to request the "cf_id" and then append it (somehow) to a form's URL?

That is - load all the "User names" with the >> e c h o JHTML::_('list.users'... etc; grab this 'selection' and simply append it to the form's URL (am I repeating myself!!!! It must be easy!!! though I am more comfortable with interface than with data)

Simon

(If its overly complex I am more than happy to buy you that beer for Christmas!)
simong 20 Dec, 2010
Hi Bob...

I have found the following code (see below) and am wondering if it is possible to include this in my initial form to call up the 'cf_id" and its associated data; then in the second (associated) form use the Cook Book recipe, for updating the database.

If I can get it to work I will post the code here.


<?php
$url = "http://www.simon.com?cmd=list";  // The simple url
$name = "option";                        // The parameter name
$value = "new";                          // The parameter value
$newUrl = $url . "?$name=$value";        // appending the values
 
// prints:http://www.simon.com?cmd=list?option=new
print($newUrl);
?>



TIA Simon
simong 25 Dec, 2010
Bob...

Can you be of any help; it would be appreciated. Outwardly it would seem simple enough.. a form to find the UserID (cf_id) and then open another form (in Edit mode) that has the User's details... can you be of any help? I am completely stumped after 3-4 weeks of it.

Thanks, Simon

btw. merry Christmas and the best to you for the new year
GreyHead 27 Dec, 2010
Hi Simon,

I confess that I'm completely lost about where the problem is. I'v been back through the thread and tried to make sense of it again.

You have a form 'mbr_UPDATE' that shows a list of members and returns the Joomla! ID of a selected member. That bit seems straightforward and seems to be working.

You have a second form 'mbr_Update2' that uses a value of the 'cf_id' parameter to extract the data for a particular member.

The cf_id parameter is not the Joomla! ID* so the problem is to link the two correctly??

I don't understand what the data is that yyou are using. For example I can find data for trish Delaware (cf_id=56), alphonse Mussen (cf_id=58), sylvia Henson (cf_id=60), albert Steiner (cf_id=62) but none of these names seem to appear in the member drop-down in the mbr_UPDATE form???

Does the user data table include the Joomla! User ID??

Bob

* The easy answer to this is still to use the Joomla! User ID to link to the two tables directly.
simong 29 Jan, 2011
Hi Bob..
am back after a short break... now going back looking at all the forms - and letting the dust settle; seems I have a working complex... made-up of an extended membership REGISTRATION form - multiple page; the second page recognizing and POSTING some of the new Users details already submitted; and finally an editable DOCUMENT created with each completed form in a Category within "Contents" (The form is writing to the Contents db, the User db and also an extended Member database)

I am now about to get this "select a User" and edit the results form happening - via the Joomla User db

I will come back.. just felt I'd touch bases and let you know the progress - and that it hasn't become a lost cause quite yet 😀
GreyHead 30 Jan, 2011
Hi Simon,

Thanks for the update and good luck with the next steps.

Bob
simong 14 Feb, 2011
Hi Bob
I can not for the life of me get this first step to function... the outcome is always the second page form... and an alert saying I must log-in (even though I have logged-in as Admin). Can you tell me if this code appears correct? If it is perhaps I am messing-up elsewhere.
Much appreciate your feedback... Simon


<select="id">
<?php
echo JHTML::_('list.users', 'id', true, 0, NULL, 'name', false);
?></select>

<br />
</td>
</tr>
<tr class="qst1"><td class="qst_a" colspan="2"></td></tr>
<tr>
<td class="qst_hd">
<div align="center"> <input type="reset" /></div>
</td>
<td class="qst_hd"><br />
<input class="" type="submit" name="Search the Database" value="Search the Database" onclick="<a href='index.php?option=com_chronocontact&chronoformname=member_UD2&id={id}'>" />
<input type="hidden" name="cf_id" /><br />
<br />
</td>
</tr>




The URL:
http://www.artatwork.com.au/peakFit/index.php?option=com_chronocontact&chronoformname=member_Update
(the best name to use is - jones - have added/removed soooo many in testing) TIA
GreyHead 14 Feb, 2011
Hi Simon,

This bit won't work:
onclick="<a href='index.php?option=com_chronocontact&chronoformname=member_UD2&id={id}'>"
The id syntax only works after a form is submitted - not when it is submitted so the url that is being redirected to here is broken.

And ... you shouldn't need it. If you make the OnSubmit URL of this form index.php?option=com_chronocontact&chronoformname=member_UD2 (in the box on the Form General tab) then the value of id will be passed automatically as a 'post' variable.

Bob

PS Remember to remove the whole 'onclick' attribute from the Form HTML.
simong 23 Feb, 2011
Hi Bob

Happy to report I am nearly there... or at least there appears light at the end of the tunnel.
A couple of questions to clean things up... and feel sure they are related somehow.

1. I am getting double entries in the CF database; in particular I am getting a cf_user_id field that is zeroed (0)... constantly on submission.
2. I am getting this error message when I post any revision (on Submit in the final form; after I submit the changes/updates to the data) -

::::::
Tableusers::store failed - 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 'WHERE id='234'' at line 1 SQL=UPDATE `jos_users` SET WHERE id='234'
::::::

(I went through the threads here and noticed something about the Joomla User table, though am a little unsure)

Where should I be looking to get this double entry omitted and this error message... is it related?

Thanks in advance. Appreciate your input. Simon


PS:
:: http://www.artatwork.com.au/peakFit/index.php?option=com_chronocontact&chronoformname=PFmbr_Update
:: choose "Chair"
This topic is locked and no more replies can be posted.