Forums

check email to add a one time fee for checkout.

Zach 03 Feb, 2013
I am new to using Chronoforms. Really great extension for Joomla.

I work for a non-profit organization. They are wanting to do a sign up for an event they are putting on for students. They want to charge a one time fee per family. Form only signs up one student at a time. That way they easily count the number of students signed up.

If a family has 2 students sign up. It would check for the parents email address in the database on the first student sign up.

If its not there, it would add a paypal button which adds the one time fee. If email address already exits, it would add a pay button without the one time fee.

Then the second student would sign up. It would check the email. See that it exists already and select the no fee button.

How would I code this in chronoforms?

Thanks
Zach
GreyHead 03 Feb, 2013
Hi Zach,

It sounds like a better approach would be to have a single form that allows you to add extra children. There was a thread about building a form like that a month or two ago.

To do it the way you suggest an Ajax look up of the email is probably going to be the simplest answer.

There's an article here from the ChronoForms Book which describes how to do this in CFV3. There's also a paid tutorial here on using Ajax in CFv4.

Bob
Zach 24 Feb, 2013
OK. I followed the tutorial and got it to work in my form. It will color the email address red or green.

When they click on my submit button, It will save the data and send them to PayPal. Now how do I program the submit button to know if the fee needs to be added? I have one with the fee and one without the fee.
GreyHead 24 Feb, 2013
Hi Zach,

You can add two submit buttons to your form with different names and check which one was used after the form is submitted.

Or you could check again to see if the email exists - that's the more secure method as it doesn't rely on the check run in the browser.

Bob
Zach 27 Feb, 2013
If I did something like this to select the different buttons. Where would I put the code.

<?php

if ($response = 'ok') {
// fee //
	$name = '... Fee button code goes here ...';
}
else
{ 
// no fee //
	$name = '... no fee button code goes here ...';
}

echo $name;
?>
GreyHead 27 Feb, 2013
Hi Zach,

Use a Custom Code action in the On Submit event of your form.

Note that ChronoForms adds the form results to the $form->data array so you will probably want to use $form->data['response']

For more info please go to the FAQS and select 'CFv4 Working with Form Data' in the drop-down.

Bob
Zach 28 Feb, 2013
Ok I have added the code and it works but I get the following error message.

Notice: Undefined index: response in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\bigten\administrator\components\com_chronoforms\form_actions\custom_code\custom_code.php(19) : eval()'d code on line 3



Here is my code:
<?php

if ($form->data['response'] == 'ok') {
// fee //
	$name = '... Fee button code goes here ...';
}
else
{ 
// no fee //
	$name = '... no fee button code goes here ...';
}

echo $name;
?>
[/quote]
GreyHead 28 Feb, 2013
Hi Zach,

It sounds as though $form->data['response'] doesn't exist. Is that possible?

Bob
Zach 01 Mar, 2013
I added a debugger to the onSubmit and some times response shows up and some times it doesn't. Then I went from my test server to the live site and tried it.

I don't get any errors. But the onSubmit doesn't pick the correct button to display.

If you would like, I can create an admin/password so you can check out my code.
GreyHead 01 Mar, 2013
Hi Zach,

What do you see in the Debugger output?

Bob
Zach 01 Mar, 2013
Here is what I get.


Data Array: 
Array
(
    [option] => com_chronoforms
    [chronoform] => test
    [event] => submit
    [Itemid] => 
    [email] => zachary@validhtmlcode.com
    [Submit] => Submit
    [3f7f4e075123a942174e73689b2ec88e] => 1
)

Validation Errors:

Array
(
)
GreyHead 01 Mar, 2013
Hi Zach,

As you see, the only form input there is 'email', there is no 'response'.

Bob
Zach 28 Mar, 2013
How do I get the "$response" to show up in the form->data then? It is called to display the red or green background. Which works.
GreyHead 29 Mar, 2013
Hi Zach,

Sorry, but where/how is $response used to set the display background? I don't see that in any of the code here.

Bob
Zach 29 Mar, 2013
It is from the code in the "ChronoForms v4 using ajax" file I downloaded. It is from the "Email Checker". The code is as follows:


<?php
// get the query info
$email = JRequest::getString('email', '', 'post');
$email = strtolower(trim($email));
// check that the email field isn't empty
$response = 'in use';
if ( $email ) {
// Check the database
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__users`
WHERE LOWER(`email`) = ".$db->quote($email).";
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count == 0 ) {
$response = 'ok';
}
}
//send the reply
echo $response;
// stop any further processing
$mainframe->close();
?>
GreyHead 30 Mar, 2013
Hi Zach,

That code is running in a completely separate Form event used just when there is an Ajax query from your form.

If you want to do something with the Ajax response then you need to edit the JavaScript in your form to add the value (whatever that is) to a form input.

Bob
Zach 03 Apr, 2013
How would I do that? Not familiar with JS.
This topic is locked and no more replies can be posted.