Forums

possibility to validate in PHP if JS is off

Qbik 21 Feb, 2008
Is it possible?

without checking that can i double validation

Now when I add this code

<?
$err=0;
if ((empty($nazwisko)) || (!preg_match('|^[_a-z0-9.-]*[a-z0-9]@[_a-z0-9.-]*[a-z0-9].[a-z]{2,3}$|e', $email)) || (!ereg( '^[0-9]{9}$' , $telefon )) || (strlen($wiadomosc)<6))
	{
	echo "<form name='form' method='post' action='?nr=basen_send'>";
	echo "<h4><font color=\"bordo\">Nie wypełniłe¶ wszystkich pól formularza... uzupełnij brakuj±ce pola</h4>";
	}
	
	if (empty($nazwisko)){
	++$err;
	echo "<font color=\"bordo\">Podaj Imię i Nazwisko!</font><br>
	<input type='text' name='nazwisko'><br><br>";
	}
	else{
	echo "<input type='hidden' name='nazwisko' value='$nazwisko'>";
	}

	if(!preg_match('|^[_a-z0-9.-]*[a-z0-9]@[_a-z0-9.-]*[a-z0-9].[a-z]{2,3}$|e', $email)){
	++$err;
	echo "<font color=\"bordo\">Podaj E-mail!</font><br>
	<input type='text' name='email'><br><br>";
	}
	else{
	echo "<input type='hidden' name='email' value='$email'>";
	}

	if (!ereg( '^[0-9]{9}$' , $telefon )){
	++$err;
	echo "<font color=\"bordo\">Podaj numer Telefonu!</font><br>
	<input type='text' name='telefon'><br><br>";
	}
	else{
	echo "<input type='hidden' name='telefon' value='$telefon'>";
	}

	if (strlen($wiadomosc)<6){
	++$err;
	echo "<font color=\"bordo\">Wpisz tre¶ć wiadomo¶ci!</font><br>
	<textarea name='wiadomosc' rows='8' cols='50'></textarea><br><br>";
	}
	else{
	echo "<input type='hidden' name='wiadomosc' value='$wiadomosc'>";
	}
	if ((empty($nazwisko)) || (!preg_match('|^[_a-z0-9.-]*[a-z0-9]@[_a-z0-9.-]*[a-z0-9].[a-z]{2,3}$|e', $email)) || (!ereg( '^[0-9]{9}$' , $telefon )) || (strlen($wiadomosc)<6))
{
echo "<input name='Submit' type='submit' value='Wy¶lij wiadomo¶ć' title='wy¶lij wiadomo¶ć' alt='wy¶lij wiadomo¶ć'>";
echo "</form><br><br>";//zamykamy formularz
}
?>


in before sending email it shows blank input (not fill up) but send email after it

I want to check only two input email and telephone, so If someone have JS set to of he can't send form before fill up this two input.

Is it possible to do that?<br><br>Post edited by: Qbik, at: 2008/02/21 12:04
GreyHead 21 Feb, 2008
Hi Qbik,

The only way to do client side validation is to use JavaScript. If JavaScript is off then the form will be submitted and you have to use Server side validation. For ChronoForms this would typically be in PHP and you could put the code in the OnSubmit before email box. If the validation fails then you need to call showform() to re-display the form and add your error messages.

I haven't checked in detail but the code you have here looks OK excpet that variable like $nazwisko have no value unless you've set $nazwisko = $_POST['nazwisko'].



Bob
Qbik 21 Feb, 2008
Hi GreyHead

I put this code to 'On Submit code - before sending email:
(PHP code with tags)'

the empty fields appear but mail was send so something is missing
GreyHead 21 Feb, 2008
Hi Qbik,

See my last email. You have to use showform() to tell ChronoForms to show the form again and not to continue and send the email. Look at the code in chronocontact.php that deals with the imageverification to see how to do this.

Bob
Qbik 27 Feb, 2008
Hi Bob

Ok If i understand i have to put my code to on submit on brackets of showform()

Yes?<br><br>Post edited by: GreyHead, at: 2008/02/28 13:55
GreyHead 28 Feb, 2008
Hi Qbik,

I just don't understand that . . . here's a code snippet:
<?php
if ( $validation_error ) {
  showErrorMessage('Sorry, You have made an error');
  showform($_POST);
  return;
}
?>
where $validation_error has been set to true if you find an error.

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