This is what I am planning to do:
I want to embed a contactform in specific content pages posted by various users.
I want to use the Chronoforms bot to get this done.
I want to use data from com_content related to the specific content item the form is embedded in.
I want the author from the content to be send the email.
I also want to add the title of the content from com_content into the subject line of the contact form.
Is this possible and could you point me in the right direction on how to do this?
<?php echo $row->title; ?>
view the form using the mambot of course!
Cheers
Max
A silly question; where do I add this code? I can't seem to get it to work...
I tried a hidden field in the 'default value' box, but this is not working.
This is the way my form looks right now:
<div class="componentheading">{global:formtitle}</div>
<table border="0">
<tr>
<td>{Name::caption} (*)</td>
<td>{Name::body}<div class="clr"/>{Name::validation}</td>
<td>{Name::description}</td>
</tr>
<tr>
<td>{Your email::caption}</td>
<td>{Your email::body}<div class="clr"/>{Your email::validation}</td>
<td>{Your email::description}</td>
</tr>
<tr>
<td>{Title Function::caption}</td>
<td>{Title Function::body}<div class="clr"/><?php echo $row->title; ?></td>
<td>{Title Function::description}</td>
</tr>
<tr>
<td>{Description::caption}</td>
<td>{Description::body}<div class="clr"/>{Description::validation}</td>
<td>{Description::description}</td>
</tr>
<tr>
<td>{Send:caption}</td>
<td>{Send:body}<div class="clr"/>{Send:validation}</td>
<td>{Send:description}</td>
</tr>
</table>
how do you check its now working now ? the PHP code line you added doesn't output anything ? do you try it in the component page or the content page ?
http://www.volunteeringecuador.info/joomla/internships/blabla.html
I changed the code to show you what else I can get. There is now a hidden field and a textfield with the code. I prefer to have the textbox 'subject' to be prefilled with the title of the content.
<div class="componentheading">{global:formtitle}</div>
<table border="0">
<tr>
<td>{Name::caption} (*)</td>
<td>{Name::body}<div class="clr"/>{Name::validation}</td>
<td>{Name::description}</td>
</tr>
<tr>
<td>{Your email::caption}</td>
<td>{Your email::body}<div class="clr"/>{Your email::validation}</td>
<td>{Your email::description}</td>
</tr>
<tr>
<td>{Description::caption}</td>
<td>{Description::body}<div class="clr"/>{Description::validation}</td>
<td>{Description::description}</td>
</tr>
<tr>
<td>{Subject::caption} (*)</td>
<td>{Subject::body}<div class="clr"/><?php echo $row->title; ?></td>
<td>{Subject::description}</td>
</tr>
<tr>
<td>{Send:caption}</td>
<td>{Send:body}<div class="clr"/>{Send:validation}</td>
<td>{Send:description}</td>
</tr>
</table>
there is something I need to understand now, how do you convert this pseudo code you post here to an HTML form!!! ????
Max
He has the RSForms JavaScript loaded - could this be RSForms pseudocode?
Bob
PS There are an incredible number of scripts loaded, I've never seen so many before, it's a wonder that the page does anything.
I really never looked at this RSForm code, but maybe it is!
@tinus, you need real HTML code in the form area for the PHP snippet I added get tested correctly, as you can see now its just copied to the page output!
Cheers
Max
I have been trying a bunch of components to see what works best for me. I guess I mixed them up a bit!
I will get back to you with the proper Chronoform code in a bit.
Sorry for wasting your time so far.
@Bob
I realize there are a lot of scripts running on the page. If you look closer though, you can see that most of them are related to two things; my template and Jreviews. I am looking for a lighter template, this one kills my loading time. Jreviews is the way it is...
BTW, the size of my page is smaller than your homepage. So as long as scripts are tied together properly, I should be ok!
I have almost the same task:
I want to use data from com_content related to the specific content item the form is embedded in.
I want the author from the content to be send the email.
I also want to add the title of the content from com_content into the subject line of the contact form.
Could anyone help with PHP code to get article's author data (name, e-mail). After I can send variables to hidden fields and use it in form e-mails settings, right?
I use com_qcontacts for authors info, but I think all necessary data already in article (com_content)?
you need PHP code to get the id of the article and read other data from jos_content table! easy to do, look at the code examples here in the forums, ask again if you need more help but its better to make a try first😉
Regards
Max
Hi almer,
you need PHP code to get the id of the article and read other data from jos_content table! easy to do, look at the code examples here in the forums, ask again if you need more help but its better to make a try first😉
Regards
Max
Yes, I understand what I need but don't now how to do it :o
One's more my task:
1. Get article title and put it in hidden field for re-use (pass to DB and e-mail, use as a form subject, etc.)
2. Get article's author details (created_by_alias from xxx_content table, username, id & email from xxx_user table) to re-use (save in DB and e-mail sent by form)
Finally, article's author should have e-mail with form data and should know from what article it is exactly, form data should be saved in DB (it's easy), sender should have partly copy of form's e-mail (shouldn't be a problem).
One author might have many articles and some articles might consist form, forms might be different.
Any practical help? Example of code, were to put code (in form, before or after submitting, etc.)?
Did you write code for any part or should we start from the first point I told you about ?
Regards
Max
Hi Artem,
Did you write code for any part or should we start from the first point I told you about ?
Regards
Max
Thank you very much, Max.
Looks likes we've to start from zero😟
I'll try to make draft of form beginning with plases to put pieses of code:
<?php
/* Writer data section*/
// Check if writer is guest or user
$user =& JFactory::getUser();
???????
// If user, get name and email for pass into appropriate fields, userid pass to hidden field for save in DB
// If guest, just do nothing, guest will fill it, we just validate no-empty name and right e-mail format
?>
<input type="hidden" name="userid" value="<?php echo $user->id; ?>"><!--Save in DB -->
<input type="hidden" name="username" value="<?php echo $user->name; ?>"><!-- Use as in Name field -->
<input type="hidden" name="useremail" value="<?php echo $user->email; ?>"><!-- Use in E-mail field-->
<?php
/* Article data section*/
// Get and save id, title an created_by from _content table
?>
<input type="hidden" name="article_id" value="<?php echo $article->id; ?>"><!-- Save in DB and -->
<input type="hidden" name="article_title" value="<?php echo $article->title; ?>"><!-- Save in DB. Make a clickable link, use in e-mail template -->
<input type="hidden" name="author_id" value="<?php echo $author->id; ?>"><!-- Save in DB -->
<input type="hidden" name="author_name" value="<?php echo $author->name; ?>"><!-- Save in DB and e-mail template-->
<?php
// Get article's author e-mail to use as e-mail address to send a form data
?>
<input type="hidden" name="author_email" value="<?php echo $author->email; ?>"><!-- Use in E-mail field for send form data-->
I hope it will be enouth to make form. This is my way of thinking but I'm not a programmer. Some things might be much easier or more complicated, I don't know.
this code is to get the content data from the content table :
$database =& JFactory::getDBO();
$query = "SELECT * FROM #__content WHERE id = '".JRequest::getVar('id')."'";
$database->setQuery( $query );
$article = $database->loadObject();
use it and let me know!
Regards
Max
This code:
<?php
global $mainframe;
$user = JFactory::getUser();
$database =& JFactory::getDBO();
$query = "SELECT * FROM #__content WHERE id = '".JRequest::getVar('id')."'";
$database->setQuery( $query );
$article = $database->loadObject();
//Here I don't know how to pass into query as ID $article->created_by; to get other authors data but I have it
$query = "SELECT * FROM #__users WHERE id = '".JRequest::getVar('id')."'";
$database->setQuery( $query );
$author = $database->loadObject();
?>
<input type="hidden" name="article_id" value="<?php echo $article->id; ?>">
<input type="hidden" name="article_title" value="<?php echo $article->title; ?>">
<input type="hidden" name="author_name" value="<?php echo $article->created_by_alias; ?>">
<input type="hidden" name="author_id" value="<?php echo $article->created_by; ?>">
<input type="hidden" name="author_email" value="<?php echo $author->email; ?>">
<input type="hidden" name="user_id" value="<?php echo $user->id; ?>">
<input type="hidden" name="user_name" value="<?php echo $user->name; ?>">
<input type="hidden" name="user_email" value="<?php echo $user->email; ?>">
This code gives me:
_POST: Array
(
[article_id] => 32 - true
[article_title] => Right Title, - true
[author_name] => Right alias name, - true
[author_id] => 63 - true
[author_email] => -- this is empty
[user_id] => 65 - true
[user_name] => Гость - true
[user_email] => xxx@inbox.ru - true
[7462574060feb5207a7464301350fe14] => 1
)
There are still some questions:
1. How to pass into query as ID $article->created_by; (for example) to get other authors data?
2. How to automatically pass user's name and e-mail (if available) to form's fields? Like in Chrono Comments.
3. How to make additional queries to other or same tables if I need (syntax and variables names rule, please)
You pushed me far away from dead point! Thank you!
You add any variable into the $query.
$query = "
SELECT *
FROM #__users
WHERE id = ".$database->quote($some_variable).";";
Bob
This code works fine:
$query = "SELECT * FROM #__users WHERE id = ".$database->quote($article->created_by).";";
$database->setQuery( $query );
$author = $database->loadObject();
Now I have all the necessary data. Let's try use it!🙂
But still one question:
2. How to automatically pass user's name and e-mail (if available) to form's fields? Like in Chrono Comments.
Thank you again, Max and Bob!
In your form html
<?php
$user =& JFactory::getUser();
?>
. . .
<div>Hi <?php echo $user->username; ?> . . .</div>
. . .
<input type='hidden' name='userid' value='<?php echo $user->id; ?>' />
Bob
Finally, code that retrieve data about article, author and user who sends form. It's just PHP code part before HTML form itself.
<?php
/* Form sender data section*/
// Check if form sender is guest or user
global $mainframe;
$user = JFactory::getUser();
// If user, get name and email for pass into appropriate fields. If guest, just do nothing, guest will fill it, we just validate no-empty name and right e-mail format
?>
<!-- This is part of form HTML -->
<input class="cf_inputbox required" maxlength="150" size="30" id="text_1" name="text_1" type="text" value="<?php echo $user->name; ?>">
<input class="cf_inputbox required validate-email" maxlength="150" size="30" id="text_2" name="text_2" type="text" value="<?php echo $user->email; ?>">
<!-- End -->
<?php
/* Article and Author data section*/
// Get Article's data...
$database =& JFactory::getDBO();
$query = "SELECT * FROM #__content WHERE id = '".JRequest::getVar('id')."'";
$database->setQuery( $query );
$article = $database->loadObject();
// Get Article's Author data...
$query = "SELECT * FROM #__users WHERE id = ".$database->quote($article->created_by).";";
$database->setQuery( $query );
$author = $database->loadObject();
?>
<!-- You can save all you need in the hidden fields if you wish or use it directly in the form fields -->
<input type="hidden" name="article_id" value="<?php echo $article->id; ?>">
<input type="hidden" name="article_title" value="<?php echo $article->title; ?>">
<input type="hidden" name="author_name" value="<?php echo $article->created_by_alias; ?>">
<input type="hidden" name="author_id" value="<?php echo $article->created_by; ?>">
<input type="hidden" name="author_email" value="<?php echo $author->email; ?>">
<input type="hidden" name="user_id" value="<?php echo $user->id; ?>">
<input type="hidden" name="user_name" value="<?php echo $user->name; ?>">
<input type="hidden" name="user_email" value="<?php echo $user->email; ?>">
<!-- End of code before form HTML -->
Marry Christmas!