Forums

conditional URL redirect when tying into Joomla reg

rodsdesign 13 Oct, 2008
normally, a conditional redirect based on user input is pretty simple...


$year=date('Y');
if ($year-$_POST[birthday_year] > 13) {
<meta http-equiv="refresh" content="0;url=index.php?option=com_chronocontact&chronoformname=mailinglist">
}


(I know that's just the year - its for example only)

However, when tied in with Joomla Registration - I don't think the "On Submit Code - before sending emai" (or after) can redirect away from the standard Joomla check your email page...

Is there a way around this?

If registrants are under 13 - we don't want them seeing the next form to sign up for the mailing list.

thanks🙂
GreyHead 13 Oct, 2008
Hi rodsdesign,

Are you in Joomla 1.5? (I forget). Youc an redirect with
<?php
global $mainframe;
$mainframe->redirect('url');
?>
To kill ChronoForms you may also need to add
$error_found = true;
this will make CF skip the email sending and database saving.

Bob
rodsdesign 13 Oct, 2008
thanks Bob...
yes - 1.5
but i need the Joomla registration to work too🙂
If I do what you suggest - won't it skip that?
Max_admin 13 Oct, 2008
Hi Rod, what does your form do at the moment and what are you trying to exclude from this with your redirect ?

Cheers,

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
rodsdesign 13 Oct, 2008
Hey Max,

At the moment, the form registers the user in Joomla user's table. (that works just fine).

What I'm trying to do is the following:

form 1 - gets registration information and month/year of birth - registers them as a Joomla user.
form 2 - if they are over 13 - then they have the opportunity to sign up for a newsletter - if not - just redirects to home page.

Do I have this backwards?

Should Form 1 get the information, pass it to form 2 THEN register them as a new user? Then my question would be - how can I pass the data from form 1 to 2? -

Does this make sense...? Sorry - i get the feeling this last part maybe pretty much a noob question...lol

Rod
GreyHead 13 Oct, 2008
Hi Rod,

You can do this by having a form with multiple sections
<?php
switch ($_POST['form_page']) :
  case 1:
   //basic form html including dob
   break;
  case 2:
  //under 13 signup
   break;
  case 3: 
    // adult sign-up code
   break;
}
?>

By using some hidden fields to set the page values and checking them in OnSubmit before it's quite simple to create this kind of form.

Bob
rodsdesign 17 Oct, 2008
Hi Bob/Max,

It seems like this would be a great tutorial... but I've been up for 3 nights straight and my client needs to launch tomorrow.... and I STILL don't get this😟 (sorry - I'll even send a donation for it!!!)

Could you throw in a real example for the above... with real code from start to finish?

if this helps - here are the two forms:

<input type="hidden" id="text_10" name="text_10" value="user">
<h3>Sign Up</h3>
<div  class="form_item">
<div class="form_element cf_textbox"><label class="cf_label">Username</label><input class="cf_inputbox required" maxlength="150" size="30" id="text_0" name="text_0" type="text" value="<?php  echo $_POST['text_0'];?>"></div><div class="clear"> </div></div>

<div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Email Address</label><input class="cf_inputbox required validate-email" maxlength="150" size="30" id="text_3" name="text_3" type="text" value="<?php  echo $_POST['text_3'];?>"></div><div class="clear"> </div></div>

<div  class="form_item"><div class="form_element cf_password"><label class="cf_label">Password</label><input class="cf_inputbox required" maxlength="150" size="30" id="text_1" name="text_1" type="password" value="<?php  echo $_POST['text_1'];?>"></div><div class="clear"> </div></div>

<div  class="form_item"><div class="form_element cf_password"><label class="cf_label">Confirm Password</label><input class="cf_inputbox required" maxlength="150" size="30" id="text_2" name="text_2" type="password" value="<?php  echo $_POST['text_2'];?>"></div><div class="clear"> </div></div>

<div  class="form_item"><div class="form_element birthday_month"><label class="cf_label">Month of Birth:</label> <select name="birthday_month" id="birthday_month");" autocomplete="off">

<option value="-1">Month:</option>

<option <?php if ($_POST['birthday_month']=='1') echo 'selected';?>  value="1">Jan</option>
<option <?php if ($_POST['birthday_month']=='2') echo 'selected';?>  value="2">Feb</option>
<option <?php if ($_POST['birthday_month']=='3') echo 'selected';?>   value="3">Mar</option>

<option <?php if ($_POST['birthday_month']=='4') echo 'selected';?>  value="4">Apr</option>
<option <?php if ($_POST['birthday_month']=='5') echo 'selected';?>   value="5">May</option>
<option <?php if ($_POST['birthday_month']=='6') echo 'selected';?>   value="6">Jun</option>
<option <?php if ($_POST['birthday_month']=='7') echo 'selected';?>  value="7">Jul</option>
<option <?php if ($_POST['birthday_month']=='8') echo 'selected';?>   value="8">Aug</option>
<option <?php if ($_POST['birthday_month']=='9') echo 'selected';?>   value="9">Sep</option>
<option <?php if ($_POST['birthday_month']=='10') echo 'selected';?>   value="10">Oct</option>
<option <?php if ($_POST['birthday_month']=='11') echo 'selected';?>  value="11">Nov</option>
<option <?php if ($_POST['birthday_month']=='12') echo 'selected';?>   value="12">Dec</option>

</select>  </div></div>
<div  class="form_item"><div class="form_element birthday_year"><label class="cf_label">Year of Birth:</label> 

<select name="birthday_year" id="birthday_year" autocomplete="off"><option value="-1">Year:</option><option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>

<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>

<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>

<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>

<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>

<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>

<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>

<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>

<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>

<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>

</select></div></div>

<div  class="form_item"><div class="form_element cf_captcha"><label class="cf_label">Enter captcha text</label><span>{imageverification}</span></div><div class="clear"> </div></div>

<div  class="form_item"><div class="form_element cf_button"><input value="Register" name="undefined" type="submit"></div><div class="clear"> </div></div>


<?php


$year=date('Y');
$month=date('m');

if ($year-$_POST['birthday_year'] < 13) { 

echo '<meta http-equiv="refresh" content="0;url=index.php">';


} else {

?>



<div  class="form_item"><div class="form_element cf_text"><span class="cf_text">Would you like to join the D&J maling list?  We won't spam you... but we'd love to shoot something over every once in a while...</span></div><div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_radiobutton"><label class="cf_label"></label><div class="float_left"><input value=" yes!" class="radio" id="_yes!0" name="radio0" type="radio"><label for="_yes!0" class="radio_label"> Yes!</label><br><input value=" no thanks" class="radio" id="_no thanks0" name="radio0" type="radio"><label for="_no thanks0" class="radio_label"> No Thanks</label><br></div></div><div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_button"><input value="Submit" name="undefined" type="submit"></div><div class="clear"> </div></div>

<?php } ?>


My credit card is ready🙂 pleaseeeee?🙂

thanks guys
GreyHead 18 Oct, 2008
Hi rodsdesign,

There are a few buglets in your code. I've posted a working version below but first here's the structure with some explanation. Form HTML
<?php
// test if the form has been submitted
// in your code the name of the submit button is 'undefined'
if ( $_POST['submit'] == '' ) {
    // this is a new form
?>
    <!-- original form code here -->
<?php
} else {
    // this is the second form
?>
    <!-- second form code here -->
</php
}
?>

In the Onsubmit after box
<?php
// test the submitted data
$year   = date('Y');
if ( $year - $_POST['birthday_year'] >= 13 ) {
    // user passed test 
    // this reshows the form but $_POST != "" so the second form will display
    showForm($_POST);
    $error_found = true;
} else {
    // user failed test
?>
    <!-- show a message here --> 
<?php
    // add a redirect in here if you like
}
?>

Notice that both sets of form code are in the form_html box. The OnSubmit after tests the reponse and redirects as needed. (I used OnSubmit after as you need to have Email on for the OnSubmit Before code to execute.

Bob

Full code- form HTML
<?php
if ( $_POST['undefined'] == '' ) {
    // this is a new form
?>

<input type="hidden" id="text_10" name="text_10" value="user" />
<h3>Sign Up</h3>
<div class="form_item" >
<div class="form_element cf_textbox" >
    <label class="cf_label" >Username</label>
        <input class="cf_inputbox required" maxlength="150" size="30" id="text_0"
    name="text_0" type="text" value="<?php  echo $_POST['text_0'];?>" /></div>
<div class="clear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textbox"><label class="cf_label">Email
Address</label><input class="cf_inputbox required validate-email" maxlength="150"
    size="30" id="text_3" name="text_3" type="text" value="<?php  echo $_POST['text_3']; ?>" /></div>
<div class="clear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_password"><label class="cf_label">Password</label><input
    class="cf_inputbox required" maxlength="150" size="30" id="text_1"
    name="text_1" type="password" value="<?php  echo $_POST['text_1'];?>" /></div>
<div class="clear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_password"><label class="cf_label">Confirm
Password</label><input class="cf_inputbox required" maxlength="150" size="30"
    id="text_2" name="text_2" type="password" value="<?php  echo $_POST['text_2'];?>" /></div>
<div class="clear"> </div>
</div>

<div class="form_item">
<div class="form_element birthday_month"><label class="cf_label">Month
of Birth:</label> <select name="birthday_month" id="birthday_month"
    );" autocomplete="off">

    <option value="-1">Month:</option>
<?php
    $month_array = array( 1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr',
        5 => 'May', 6 => 'Jun', 7 => 'Jul', 8 => 'Aug', 9 => 'Sep',
        10 => 'Oct', 11 => 'Nov', 12 => 'Dec' );
    foreach ( $month_array as $k => $v ) {
        $selected = "";
        if ( $_POST['birthday_month'] == $k ) {
            $selected = "selected='selected'";
        }
        echo "<option $selected value='$k' >$v</option>";
    }
?>

</select></div>
</div>
<div class="form_item">
<div class="form_element birthday_year"><label class="cf_label">Year
of Birth:</label> <select name="birthday_year" id="birthday_year" autocomplete="off">
<option value="-1">Year:</option>
<?php
for ($i = 2008; $i >= 1934; $i-- ) {
    echo "<option value='$i'>$i</option>";
}
?>
</select></div>
</div>

<div class="form_item">
<div class="form_element cf_captcha"><label class="cf_label">Enter
captcha text</label><span> {imageverification} </span></div>
<div class="clear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_button"><input value="Register"
    name="undefined" type="submit"></div>
<div class="clear"> </div>
</div>

<?php
} else {
    // this is the second form
?>
<div class="form_item">
<div class="form_element cf_text"><span class="cf_text">Would you like to join
the D&J maling list? We won't spam you... but we'd love to shoot something
over every once in a while...</span></div>
<div class="clear"> </div>
</div>
<div class="form_item">
<div class="form_element cf_radiobutton"><label class="cf_label"></label>
<div class="float_left"><input value=" yes!" class="radio" id="_yes!0"
    name="radio0" type="radio"><label for="_yes!0" class="radio_label" > Yes!</label><br>
<input value=" no thanks" class="radio" id="_no thanks0" name="radio0"
    type="radio"><label for="_no thanks0" class="radio_label"> No Thanks</label><br>
</div>
</div>
<div class="clear"> </div>
</div>
<div class="form_item">
<div class="form_element cf_button"><input value="Submit" name="undefined"
    type="submit"></div>
<div class="clear"> </div>
</div>
<?php
}
?>
OnSubmit after:
<?php
$year   = date('Y');
if ( $year - $_POST['birthday_year'] >= 13 ) {
    echo "test 1";
    showForm($_POST);
    $error_found = true;

} else {
    echo "test 2";
    // this is a new form
?>
    <p>We're really sorry but you are too young to subscribe to our list.
    Please come back in a few years.</p>
<?php
    // add a redirect in here if you like
}
?>
rodsdesign 27 Oct, 2008
Hi guys,

I had to take the week off... and the client pushed back the launch date... so now I'm back at it.

thanks for the very specific form... I really appreciate it.

one significant issue...
the code for OnSubmit causes 2 emails to be sent / 2 entries in the database. one with the contact details, one with only the info from form 2. Is there any way to combine them? Ideally - one email should be sent with all the info... I may just be asking too much here - but I just don't know.

any other approach?
dandy84 18 Mar, 2009
Hi all! First this component i think is very good and compliments!
Second im trying to use the code of this discussion i have only maked a simple "copy and past" but i have this type of error. (Im using chronoform v. 3.1 rc2 with J!1.5.9):

Parse error: syntax error, unexpected $end in .../modules/mod_chronocontact/helper.php(354) : eval()'d code on line 85

can you help me?

Thank u in advance for reply!

Daniele
GreyHead 18 Mar, 2009
Hi daniele,

The error message says that there is something wrong, probably around line 85 of your Form HTML. (I no longer have the Joomla 1.0 module installed to check exactly.)

Bob
Max_admin 18 Mar, 2009
Hi Daniele,

please post your form code, does the form work fine when you open it in its own page ?

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
dandy84 19 Mar, 2009
thank for reply!

Hi Daniele,

please post your form code, does the form work fine when you open it in its own page ?

Max



yes doesnt work aslo in its own page. i have copied all the code that greyhead posted previously! just a copy and past of the complete example.

Hi daniele,

The error message says that there is something wrong, probably around line 85 of your Form HTML. (I no longer have the Joomla 1.0 module installed to check exactly.)

Bob



i know this, attention im using joomla 1.5 not 1.0
dandy84 19 Mar, 2009
all works! ok no problem my error! sorry for your lose time with me.
dandy84 19 Mar, 2009
i have another problem im trying to change the condition with this:
   <?php
    if ($_POST['select_4']== StudenteCinese) {     
        echo "test 1";
        showForm($_POST);
        $error_found = true;

i have a dropdown box with some choices and only if the user choice StudenteCinese appear the other form. If i go on its our link the forms works but if i load by the module doesnt work. why?

this is the link

in the top there is the module down is link try to choice studente cinese.

thanks for attention
GreyHead 20 Mar, 2009
Hi dandy84,

I don't think that the module has any way of reloading the page exactly as it was before so this approach won't work there. What you could perhaps do woudl be to use an iFrame in the module, or an AJAX form so that only the module content refreshes.

Bob
dandy84 20 Mar, 2009
im not so expert...so i have to use the tags Iframe into the html code?
GreyHead 20 Mar, 2009
Hi dandy84,

Try using the Joomla wrapper module and put the url for your form in it but add &tmpl=component at the end to that you don't get all the Joomla page displaying as well.

Bob
dandy84 20 Mar, 2009
i have tried to make a wrapper but doesnt work, i have the same problem.thanks aniway for the replies. do you have other suggestions?

you can try to visit the page at <!-- w --><a class="postlink" href="http://www.erasmuspoint.net">www.erasmuspoint.net</a><!-- w -->, wrapper is in the right but the problem is the same.
GreyHead 20 Mar, 2009
Hi dandy84,

Sorry, I misunderstood the problem - and now I don't know what it is.

Please tell me exactly what you want to happen?

What should I see when I choose the Chinese option?

Bob
dandy84 20 Mar, 2009
if i choose studente cinese appear the form for inscribe to newsletter else appear a message, is the same code that you have posted previously the only chenged is from birthday >=13 to this new condition and i have added a new form with a dropdown list

but if you try the module, if you choose anything appear always the registration to the newsletter.
GreyHead 20 Mar, 2009
Hi dandy84,

I get the newsletter form whatever I put in the form - all the selections do exactly the same.

Bob
dandy84 20 Mar, 2009
yes this is the problem the newsletter should work only if i choose studente cinese...i have maked the if-else condition
GreyHead 20 Mar, 2009
Hi dandy84,

[sendfb][/sendfb]
Bob
dandy84 20 Mar, 2009
ok thank u for your help!

[attachment=0]prova.zip[/attachment]
Max_admin 20 Mar, 2009
if ($_POST['select_4']== StudenteCinese)


should be

if ($_POST['select_4']== "StudenteCinese")


try this ?

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
dandy84 20 Mar, 2009
doesnt work...😟
dandy84 21 Mar, 2009
now i have maked new the wrapper with &tmpl=component. Now all works well but when i push on register the result appear with loading a new web page and not only the component. you can try directly to my website http://www.erasmuspoint.net
dandy84 21 Mar, 2009
please, can u help me?
This topic is locked and no more replies can be posted.