Forums

really need help with form!!!

glens1234 01 Mar, 2008
HI. Firstly, i couldnt get the link to the form to work. Then i disabled the SEF URL's extension and it worked.

Is this a known issue? If so is there any updates which will allow it to work with SEF URL's?

Secondly, I want to create a form which returns results from a database as opposed to storing the data.

So i put the following html in the html box.


   <p> Please select the languages in order to find an appropriate translator (NOTE: Use the shift button to select multiple languages):</p>
  
      <table border="0" cellspacing="0" cellpadding="2">
        <tr><td>Languages Spoken</td>
		<td><select name="languages_spoken[]" multiple size="5">
		<option value="English">English</option>
		<option value="French">French</option>
		<option value="Spanish">Spanish</option>
		<option value="German">German</option>
		</select></td>
           
		   </tr>
		   <tr>
		    <td><input type="submit" name="Submit"
               value="Submit"></td>
         </tr>
      </table>
  


Then i inserted the following php code into the autoGenerated code box.


<?php
$languages_spoken = $_POST['languages_spoken'];
$lang_imploded = implode(",", $languages_spoken);
$query = "SELECT * FROM #__chronoforms_1 WHERE lang_spoken LIKE '$lang_imploded%'";

$result = mysql_query($query) or die ('Error, insert query failed'.mysql_error());


Then insert the following code in to the On Submit code - after sending email box


// Print out the contents of the entry
$num_rows = mysql_num_rows($result); 
print "There are $num_rows records.<P>"; 
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n"; 
?>


However, this does not seem to work!

Then i tried submiting the form using the form URLs box. I type in the following URL.

templates/prime_languages/process_search.php - which is where the php file is located.

That did not work either.

I noticed in the autoGenerated code for one of my other forms there was the code... $database =& JFactory::getDBO();

So tried adding this to the top of my php code but still no joy.

In fact i have tried all different combinatations.


Can someone please please shed some light on the subject as i have been stuggling with this for many days now!!!

Thanks.
GreyHead 01 Mar, 2008
Hi glens1234,

What exactly do you want to do - I can't make it out from these chunks of code.

BTW: there's a note on the Autogenerated page that reads "Please don't touch this unless you know what you are doing". That code is used to write form data to the database. It will not read data from the database, and unless you are careful it won't write it either.

ChronoForms usually doesn't have problems with SEF URLs, what are the URLs that work and don't work? and what SEF extension are you using?

Bob
glens1234 01 Mar, 2008
Hi. Thanks bob!

Basically...
I already have a form which sends data to to the database.
Now, i want to retreive data from the database and display the results.

So i cannot use a select statment in the auto generated code box?
Ok, thats good to know. So is there anywhere else i can use a select statement??

What about in the
On Submit code - before sending email:
(PHP code with tags)

Or...
On Submit code - after sending email:
(PHP code with tags)

When i use the Form URL's section to link to an external file, i.e search_translators.php, i get "This is a test", which i put in php file to test it was finding the file. So in this case the problem is with the php code.

However, I have tested both the form and the form processing script separately, so i know the code is correct.

This is the code for search_translators.php.


<?php
echo 'this is a test';
$database =& JFactory::getDBO();

$lang_spoken = $_POST['languages_spoken'];
$lang_imploded = implode(",", $lang_spoken);
$query = "SELECT name, languages_spoken FROM jos_chronoforms_1 WHERE languages_spoken LIKE '$lang_imploded%'";

$result = mysql_query($query) or die ('Error, insert query failed'.mysql_error());


// Print out the contents of the entry
$num_rows = mysql_num_rows($result); 
print "There are $num_rows records.<P>"; 
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n"; 
?>


Another thing i noticed when looking at the autoGenerated code of one of my other forms was the use of the $database->query() and $database->setQuery() functions. Are these mandatory funtions which execute a database quesry in joomla? In which case can someone sugguest how i might use these in conjunction with my code?


Ok. I think that's all for now.
Thanks.
glens1234 01 Mar, 2008
Hi. Thanks bob!

Basically...
I already have a form which sends data to to the database.
Now, i want to retreive data from the database and display the results.

So i cannot use a select statment in the auto generated code box?
Ok, thats good to know. So is there anywhere else i can use a select statement??

What about in the
On Submit code - before sending email:
(PHP code with tags)

Or...
On Submit code - after sending email:
(PHP code with tags)

When i use the Form URL's section to link to an external file, i.e search_translators.php, i get "This is a test", which i put in php file to test it was finding the file. So in this case the problem is with the php code.

However, I have tested both the form and the form processing script separately, so i know the code is correct.

This is the code for search_translators.php.


<?php
echo 'this is a test';
$database =& JFactory::getDBO();

$lang_spoken = $_POST['languages_spoken'];
$lang_imploded = implode(",", $lang_spoken);
$query = "SELECT name, languages_spoken FROM jos_chronoforms_1 WHERE languages_spoken LIKE '$lang_imploded%'";

$result = mysql_query($query) or die ('Error, insert query failed'.mysql_error());


// Print out the contents of the entry
$num_rows = mysql_num_rows($result); 
print "There are $num_rows records.<P>"; 
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n"; 
?>


Another thing i noticed when looking at the autoGenerated code of one of my other forms was the use of the $database->query() and $database->setQuery() functions. Are these mandatory funtions which execute a database quesry in joomla? In which case can someone sugguest how i might use these in conjunction with my code?


Ok. I think that's all for now.
Thanks.
glens1234 01 Mar, 2008
Ok ill make this my last post as this is becoming a more general joomla/php issue as opposed to a chrono forms one.

After following an example from the joomla developers site i have now revised my code to test the output.


<?php
echo 'this is a test';
$database =& JFactory::getDBO();

$lang_spoken = $_POST['languages_spoken'];
$lang_imploded = implode(",", $lang_spoken);
$query = "SELECT name, languages_spoken FROM #_chronoforms_1 WHERE languages_spoken LIKE '$lang_imploded%'";

$database->setQuery($query);
$rows = $database->loadObjectList();

foreach ( $rows as $row ) {
  echo "$row->name: $row->language_spoken\n";
}
?>


I still only get "this is a test".

Thanks
GreyHead 01 Mar, 2008
Hi Glens1234,

Which version of Joomla are you using? I think that JFactory only works in Joomla 1.5.

Let's just stick some debug code in here to see what's happening:
<?php
echo 'this is a test';
$database =& JFactory::getDBO();

$lang_spoken = $_POST['languages_spoken'];
echo "_POST: ";print_r($_POST['languages_spoken']); echo "<br /.";
$lang_imploded = implode(",", $lang_spoken);
echo "lang_imploded: ";print_r($lang_imploded); echo "<br /.";
$query = "SELECT name, languages_spoken FROM #_chronoforms_1 WHERE languages_spoken LIKE '$lang_imploded%'";

$database->setQuery($query);
$rows = $database->loadObjectList();
echo "rows: ";print_r($rows); echo "<br /.";

foreach ( $rows as $row ) {
  echo "$row->name: $row->language_spoken\n";
}
?>
Depending on what prints out you can see where the code is breaking down.

Bob

PS This looks like a candidate for Max's Profile PlugIn.
glens1234 01 Mar, 2008
Hi.

Im using 1.5.

I entered the code with the echo statements and still nothing!
I even added an additional line of code to 'echo' the '$database =& JFactory::getDBO();' statment.

echo "result: ";print_r($database); echo "<br /.";

This is really strange!

Could it be that my file, due to where it is located, does not have permission to connect to the database?
Im just guessing really.

Thanks.
GreyHead 02 Mar, 2008
Hi glens1234,

No - you can definitely connect to the database!

If you are seeing nothing after 'this is a test' that suggests that there is a problem with the JFactory Line. Try
$database = &JFactory::getDBO();
The & is in a different place.

Bob
glens1234 02 Mar, 2008
Hi.

Sorry, i copied and pasted that code from the code above.
I have now removed the space and tested it...still no joy.

Could the fact that i am in legacy mode cause issues?

thanks.
GreyHead 02 Mar, 2008
Hi glens1234,

No problem, the slightly different version came from the Joomla docs.

Legacy mode shouldn't make any difference.

Is the form on-line? If so can you give me admin access. I'm up to my eye-brows at the moment but will try to find time to take a look.

Bob
glens1234 02 Mar, 2008
Hi.

Unfortunatly i am working locally.
If anyone can think of any additional ways in which i can debug my script so i can determine exectly where the problems lies i would very much like to hear it.

Thanks.
GreyHead 03 Mar, 2008
Hi glens,

I cant' do anything until tomorrow morning but by all means e-mail me the form (take a Form Backup in the Forms Manager) at the address in my sig and I'll take a look.

Bob
glens1234 03 Mar, 2008
Hi.

I has been pointed out to me that $database=&JFactory::getDBO();
does not work because php has no way of knowing what JFactory is or what the function getDBO() should do?

I have been informed that the best way to go about this would be create the script as a module or plugin. That way i could load the classes associated with JFactory in order or it to connect to the database!

i have looked at few tutorials on how to create modules and it is slightly too advanced for my level of knowledge.

However, is it possible to include the procesing script on the same page as the html code in chrono forms?

Im guessing not but im running out of options.

cheers
GreyHead 03 Mar, 2008
Hi glens,

There is nowhere in Joomla that I'm aware of that you can't access the database. You may need some global statements to make that possible.

To repeat myself: by all means e-mail me the form (take a Form Backup in the Forms Manager) at the address in my sig and I'll take a look.

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