Buy Now
Sign in

How to check for empty fields?

345d54 , July 25 2007, 23:29
3
345d54 6
July 25 2007, 23:29 #1404
Hello,

I want to check that there are no empty fields when a guest submits the form.
My form is called "contact" and until now looks something like this:

<?php global $my; $mainframe; ?>
<p>Name: <input type="text" name="name" value="<?php echo $my->username; ?>" /></p>
<p>Email: <input type="text" name="email" value="<?php echo $my->email; ?>" /></p>
<p>Telefon: <input type="text" name="Telefon"></p>
<p>Betreff: <input type="text" name="betreff"></p>
<p>Nachricht: <textarea name="nachricht" cols="30" rows="5" wrap="virtual"></textarea> </p>
<p><input type="submit" name="Submit" value="Senden"></p>
<p><input type="hidden" name="title" value="<?php echo $mainframe->_head['title']; ?>" />


In the general settings of the form I filled in

onsubmit=return validateForm()
in the row:

Form tag attachment:
something like onSubmit()

Now I guess I need to fill in the form code field:

On Submit code - before sending email:
(PHP code with tags)

the script: validateForm (which I lack at the moment and have no clue how it should look like=)

is there anyone who knows?

THanks in advance
Hanne
GreyHead 64
July 26 2007, 00:11 #1405
Hi Hanne,

Please have a look at this post which has a simple form validation example telling you how to do this (at least for a single field).

Bob<br><br>Post edited by: GreyHead, at: 2007/08/11 15:01
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
3
345d54 6
July 26 2007, 02:16 #1406
thank you for the hint - it works fine.



function checkForm(form)
{
if(form.name.value == ""«») {
alert("Please enter your name!"«»);
return false;
}
return true;
}



but now: how can I add another field?



function checkForm(form)
{
if(form.name.value == ""«») {
alert("Please enter your name!"«»);
return false;
}
return true;

if(form.email.value == ""«») {
alert("Please enter your Email!"«»);
return false;
}
return true;
}



I read something about && but I can´t find out about the syntax, I am doing trial and error fun stuff for about 2hours now and I guess it´s just peanuts for you - so have mercy!<br><br>Post edited by: 345d54, at: 2007/07/25 22:41
GreyHead 64
July 26 2007, 05:03 #1407
Hi 345d54,

One way is to stack up the if clauses like:
 function checkForm(form)
{
if(form.name.value == ""«») {
alert("Please enter your name!"«»);
return false;
} else if (form.email.value == ""«») {
alert("Please enter your Email!"«»);
return false;
}
return true;
}


Not tested but should work.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
3
345d54 6
July 26 2007, 13:30 #1409
It works just fine!

Thank you Bob - the support in this Forum is amazing.
L
lydbury 6
October 10 2007, 00:55 #2684
That's exactly what I want to do but cannot make it work. Am I correct that I leave the script exactly as it is (just change the name of the filed) and then paste into the html or should it go in the javascript box?

Then does the call stay as it is?

Do I need to change the form name at all.

Grateful for your help.

Duncan
GreyHead 64
October 10 2007, 02:12 #2685
Hi Duncan,

In the latest version of ChronoForms you can set up field validation from the Form Manager. Just enter the names of the required fields in the Validation tab.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
L
lydbury 6
October 10 2007, 02:52 #2686
Thank you.