Forums

[Solved] Actually replace Joomlas contact form?

Scotty 21 May, 2009
HI folks, great component! I've used it on several sites to display a single contact form but this time I need to actually replace the Joomla default contact form.

I have a normal Joomla 'Contact Category Layout' page set up with about 10 contacts (this will increase) and I need these to link to a custom contact form. Not a different form for each contact (ie. all forms will look the same) but each contacts form would have to email to that contact of course.

Is this possible?

I've had a search around the forum and don't see that this question has come up before.
GreyHead 22 May, 2009
Hi Scotty.

Create the ChronoForms Form using a 'Dynamic To' in the Email Setup. Create a link on the Contact page with the URL of the form and add an extra &toemail=user1@example.com to the end of each link.

Get the link value in the Form HTML using JRequest::getVar('toemail', 'default value', 'get'); and put this in a hidden field in the form.

Use the hidden field name in the Dynamic To' box.

Bob

PS Probably it's better to use a code instead of the actual e-mail - there's a current discussion of how to do this in another theread here.
Scotty 22 May, 2009
Hi Bob and thanks for your help. I'm a bit lost however...

I have added a hidden field with the value JRequest::getVar('toemail', 'default value', 'get');

Create a link on the Contact page with the URL of the form and add an extra &toemail=user1@example.com to the end of each link.



My intention is to use Joomlas default contact category page like so...

[attachment=0]contacts.jpg[/attachment]

...and when one of the contacts is clicked it will bring up the new customised form. This form will then be sent to that contact.

It is the 'Name' column in the table above that links to the form for that contact and this appears to be defined in line 79 of components/com_contact/views/category/view.html.php as follows...

$contact->link = JRoute::_('index.php?option=com_contact&view=contact&id='.$contact->slug.'&catid='.$contact->catslug);
			if ($pparams->get('show_email', 0) == 1) {
				$contact->email_to = trim($contact->email_to);
				if (!empty($contact->email_to) && JMailHelper::isEmailAddress($contact->email_to)) {
					$contact->email_to = JHTML::_('email.cloak', $contact->email_to);
				} else {
					$contact->email_to = '';
				}
			}


So... do I change the link to index.php?option=com_chronocontact&chronoformname=contact&toemail=user1@example.com? and if so, how do I get the [email]user1@example.com[/email] to be the actual email of the contact the was clicked?

I should add... I'm a PHP n00b so please keep it simple🙄 and thank you again for helping.
Max_admin 24 May, 2009
Hi Scotty,

in the onsubmit before email box:


<?php
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', JRequest::getVar('toemail'));
?>


Cheers,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Scotty 25 May, 2009
OK guys thank you for the help on this.

I've changed line 79 of components/com_contact/views/category/view.html.php to...
$contact->link = JRoute::_('index.php?option=com_chronocontact&chronoformname=joomla_contact&id='.$contact->slug.'&toemail='.$contact->email_to);


So now I have the list of contacts linking to the custom form with the toemail=contacts@mail.com at the end of the URL. Great. But...

I'm having a problem with the hidden field. I'm not sure if I'm doing this right at all. I've added...
<?php $toemail = JRequest::getVar('toemail', 'default value', 'GET'); ?>

...to the start of the Form HTML and the hidden field looks like...
<input value="<?php echo $toemail['toemail']; ?>" id="hidden_6" name="hidden_6" type="hidden" />

but when the form is submitted all I am getting is the first letter of the contacts email address in the hidden field.

From the debug text...
$_POST Array: Array ( [text_0] => Joe Bloggs [text_1] => joe@mail.com [text_2] => joe@mail.com [text_3] => Test Subject [text_4] => Test message. [hidden_6] => b [button_5] => Submit [55a9a7c66da0d7b2f72ce3bf945d52de] => 1 )

This is the same with or without Maxs' code for the onsubmit before mail.

Any ideas?
GreyHead 26 May, 2009
Hi Scotty,

I think the hidden field code should be
<input value="<?php echo $toemail; ?>" id="hidden_6" name="hidden_6" type="hidden" />
but don't see where the 'b' comes from :-(

Bob
Max_admin 26 May, 2009
Hi Scotty,

your code has some wrong piece, please use the fix Bob posted and if you still have problems then the email may be encoded using the base64_encode function and then decoded but lets see what happens after you do the fix above first!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Scotty 26 May, 2009
Perfect!

Thanks very much for all your help both of you. Thanks to Bobs correct code the form is now working exactly as I wanted.
Scotty 26 May, 2009
Dang! Now I've run into a related problem.

The url ends in &toemail=XXX and the email sends perfect UNLESS the user makes a mistake. I have captcha enabled and server side script that compares two email addys.

If a user gets the captcha wrong or the email addys are different the form reloads(blank?) with an error message but the &toemail=XXX has now gone from the URL. It's now index.php?option=com_chronocontact&task=send&chronoformname=contact.

Any ideas?
Max_admin 28 May, 2009
yes, edit your code piece earlier from :
    <?php $toemail = JRequest::getVar('toemail', 'default value', 'GET'); ?>

to
    <?php $toemail = JRequest::getVar('toemail'); ?>


then add a hidden field to your form and call it "toemail" and inside the value attribute add:

 <?php echo JRequest::getVar('toemail'); ?>


this will ensure that the email is always there even if the the form is reloaded, assuming you have the republish option set to yes!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Scotty 28 May, 2009
Yep. Works!

I didn't have republish enabled.

Thanks again Max.
jvince 10 Aug, 2009
Hi,
As I see this would be a common enough requirement for many people switching to CF, can i beg you to add the full form code in a manner that we can 'import' it easily ... pretty please?

Many thanks,

- Vince
jvince 12 Aug, 2009
I'm obviously not very good a begging am i? :-)
Best wishes,

- Vince
GreyHead 12 Aug, 2009
Hi Vince,

I'm sure that you are a superb beggar - I'm just rushed off my feet at the moment and not clear exactly what you want. Spell it out in words of one syllable that don't require me to go ferret around the Joomla code and you may get a few coins in the hat.

Bob
jvince 12 Aug, 2009
Hi Bob,
As per the subject of this topic, we need to replace the standard Joomla contact form, whilst retaining the functionality of dealing with all contacts without having to create a new form for each - as the oroginal poster explained, better than I can.

Because I see this as a probable standard requirement for many of us using CF, I was suggesting that it may be good to have a ready-made solution for it added as a .cfbak file for evryone to easily import?

It could then be added either to this topic
ChronoForms ShowCase - Share your forms with others
or, in the downloads section?

Hope I was clearer this time.
Thanks as always,

- Vince
jvince 26 Aug, 2009
Hi,
Any chance of helping to do this pretty please?
many thanks,

- Vince
GreyHead 26 Aug, 2009
Hi Vince,

At present - very little chance. Max seems to have disappeared (I guess he's coding hard on something) and I'm juggling several projects with deadlines coming up.

Bob
Scotty 30 Sep, 2009
Sorry Vince, I wasn't subscribed to the thread but I got an email about your PM.

Instructions...

1. At the start of your FormHTML insert...
<?php $toemail = JRequest::getVar('toemail', 'default value', 'GET'); ?>


2. Within your form, place the following hidden field...
<input value="<?php echo $toemail; ?>" id="hidden_to" name="hidden_to" type="hidden" />


3. In your emails setup create a 'Dynamic To' and insert hidden_to in the box.

4. In /components/com_contact/views/category/view.html.php find on line 79...
$contact->link = JRoute::_('index.php?option=com_contact&view=contact&id='.$contact->slug.'&catid='.$contact->catslug);
...and change to...
$contact->link = JRoute::_('index.php?option=com_chronocontact&chronoformname=contact&id='.$contact->slug.'&toemail='.$contact->email_to);
NB: replace '=contact' in the path above with the name of the form you want to link to.

And that's it. Remember this will ONLY work in a contacts category view (List of contacts) but I'm sure you can implement it for all contact links. Also, remember that your contacts email addresses will be in the HTML of the Contact List page and will be readable by spam bots.

I've attached my actual contact form also. It's exactly the same as the standard Joomla form except it has a 'confirm email' field and it has CAPTCHA enabled.

Scotty
jvince 30 Oct, 2009
Hi Scotty,
Really appreciate this.
Sorry for delay in replying, but it's been very manic work-wise.

I'll test your form solution over next few days and report back either way on how it works out in case it helps anyone else as well.

Best wishes,

- Vince
jvince 01 Nov, 2009
I tried, but it doesn't seem to solve my problem unless I am missing something.

Don't want to really create a form for evry contact individually.

Also, don't really want to edit core files (/components/com_contact/views/category/view.html.php) and risk the form breaking during Joomla updates.

Hopefully the gurus here can help us, as we could all do with a replacement of the Joomla standard version.

here's hoping.

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