Refresh form... without submit...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deuxk
Forum Newbie
Posts: 1
Joined: Sat Jun 02, 2007 1:43 am

Refresh form... without submit...

Post by deuxk »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I try to make refresh my form page when the user chose a country (pays, i'am french). I have program all think for change and load the new states but when i change the country the page don't refresh and i don't have idea for make this work!!! I show you my code and if you have solution for it's really appreciate.

thanks

Code: Select all

<?
include("administration/dbconnect.php");

$sign_up = 'modules/signup_user/';

define( "FILE_COUNTRY", $sign_up . "country.txt" );
define( "FILE_CA_PROVINCES", $sign_up . "provinces.ca.txt" );
define( "FILE_US_STATES", $sign_up . "states.us.txt" );

function	submit( $var ){
	global	$HTTP_POST_VARS, $HTTP_GET_VARS ;
	return ( strlen(trim($HTTP_POST_VARS[ $var ])) ) ? trim( $HTTP_POST_VARS[ $var ] ) : trim( $HTTP_GET_VARS[ $var ] );
} 


function	displayCountry( $default = "Canada" ){
	print "<select name='country' onchange='document.frmUser.submit();'>\n" ;
	print "<option value=''>Select</option>\n" ;

	$countries = file( FILE_COUNTRY );
	foreach( $countries as $c ){
		$value = htmlspecialchars(trim($c)) ;
		$selected = strtoupper($default) == strtoupper(trim($c)) ? " selected " : "" ;
		print "<option value=\"$value\" $selected>$value</option>\n" ;
	}
	print "</select>\n" ;
}
	
	
	
	
function generateActivation ($length = 18)
{
  $activation_random = "";
  $possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
  $i = 0; 
  while ($i < $length) { 
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
    if (!strstr($activation_random, $char)) { 
      $activation_random .= $char;
      $i++;
    }
  }
  return $activation_random;
}


function VerifierAdresseMail($adresse)
{
$Syntaxe='#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#';
if(preg_match($Syntaxe,$adresse))
return true;
else
return false;
} 







$erreur = '';
$inscription = '';


if (isset($_POST['submit'])) {

// verifier si les champs sont rempli au complet
if ($_POST['login'] != null && $_POST['nom']!= null && $_POST['prenom'] != null && $_POST['adresse'] != null && $_POST['region'] != null && $_POST['codepostal'] != null && $_POST['telephone'] != null && $_POST['courriel'] != null && $_POST['courriel_verif'] != null && $_POST['password'] != null && $_POST['password_verif'] != null) {



$login = addslashes($_POST['login']);
$nom = addslashes($_POST['nom']);
$prenom = addslashes($_POST['prenom']);
$adresse = addslashes($_POST['adresse']);
$region = $_POST['region'];
$codepostal = addslashes($_POST['codepostal']);
$telephone = addslashes($_POST['telephone']);
$courriel= htmlentities($_POST['courriel']);
$courriel_verif = htmlentities($_POST['courriel_verif']);
$password = md5($_POST['password']);
$password_verif = md5($_POST['password_verif']);
$activation = generateActivation();
$status = 0;


// verifier si le login est deja pris
$requete = mysql_query("SELECT login FROM users WHERE login = '$login'") or die(mysql_error());
$compte = mysql_num_rows($requete);

if ($compte == 0) {

		// verification si le email est ecrit correct et si il est deja pris!
		if ($courriel == $courriel_verif) 
		{
		$requete = mysql_query("SELECT courriel FROM users WHERE courriel = '$courriel'") or die(mysql_error());
		$compte = mysql_num_rows($requete);
		
		if ($compte == 0) {

			 // verification si le email est correctement ecris.
			 if(VerifierAdresseMail($courriel)) 
			 	{
					//verification si les 2 password sont pareille
					if ($password == $password_verif) {
				
						//verification si le password a plus de 4 caractere
						if (strlen($password) >= 4) {
					
				
				
							// enregistrer & link a l'acceuil 
							mysql_query('INSERT INTO users (id, login, prenom, nom, adresse, region, codepostal, telephone, courriel, password, activation, status, timestamp) VALUES ("","'.$login.'", "'.$prenom.'", "'.$nom.'", "'.$adresse.'", "'.$region.'", "'.$codepostal.'", "'.$telephone.'","'.$courriel.'","'.$password.'","'.$activation.'","'.$status.'","'.$time.'")');
							$sujet = 'Votre activation';
							$expediteur = 'Administration';
							$message = 'Cliquer ici pour activer votre compte : https://www.filmoptionsales.com/site.ph ... ctivation;
							mail($courriel, $sujet, $message, $expediteur);
							
							$inscription = 'ok';
							
				
						} else { $erreur = $txt17;  }
					} else { $erreur = $txt18;  }
				} else { $erreur = $txt19;  }
			} else { $erreur = $txt20;  }
		} else { $erreur = $txt21; }
	} else { $erreur = $txt22; }
} else { $erreur = $txt23; }
}




if ($inscription == '') {
?>
<center>
	<table width="600" CELLPADDING= CELLSPACING=0>
		<tr>
		<td align="center" class="text1"><h3><? echo $txt25; ?></h3></td>
		</tr>
	</table>

<form action="site.php?cmd=inscription&type=user" method="post" name="frmUser">
<br />

<? if ($erreur != '') {?>
	<table width="600" BORDER=1 CELLPADDING= CELLSPACING=0 align="center">
		<tr>
		<td align="center" style="color:red;"><? echo $txt26; ?><br /><br />
		<? echo $erreur; ?><br /><br /></td>
		</tr>
	</table>
<br /><br />
<?
}
?>

<table width="600" BORDER=0 CELLPADDING= CELLSPACING=0 align="center">
	<tr>
	<td width="100" class="text1"><? echo $txt3; ?></td><td><input type="text" size="30" name="login" onKeyPress="return login(this, event)" value="<? echo $_POST['login']; ?>" /></td>
	</tr>
	<tr>
	<td width="100" class="text1"><? echo $txt4; ?></td><td class="text1"><input type="text" size="30" name="prenom" onKeyPress="return lettersonly(this, event)"  value="<? echo $_POST['prenom']; ?>" /></td>
	<tr>
	<td width="100" class="text1"><? echo $txt5; ?></td><td class="text1"><input type="text" size="30" name="nom"  onKeyPress="return lettersonly(this, event)" value="<? echo $_POST['nom']; ?>" /></td>
	</tr>
	<tr>
	<td width="100" class="text1"><? echo $txt6; ?></td><td class="text1"><input type="text" size="50" name="nom"  onKeyPress="return lettersonly(this, event)" value="<? echo $_POST['adresse']; ?>" /></td>
	</tr>	

		<tr>
			<td class="text1" nowrap width="140">Ville :</td>
			<td><input type="Text" name="city" size="30" value="<?= submit("city") ?>"></td>
		</tr>
		
		<tr>
			<td class="text1" nowrap>Pays :</td>
			<td>
			<?
				$defaultCountry = strtoupper( submit( "country" ) ? submit( "country" ) : "United States" );
				displayCountry( $defaultCountry ) ;
			?>				
			</td>
		</tr>
		
		<tr>
			<td class="text1" nowrap>Province/State :</td>
			<td>
			<?
				if( $defaultCountry == "UNITED STATES" || $defaultCountry == "CANADA" ) {
					$provStates = file( $defaultCountry == "UNITED STATES" ?  FILE_US_STATES : FILE_CA_PROVINCES  );
			?>
					<select name="provOrState">
			<?
					foreach( $provStates as $ps ) {
						print "<option value=\"" . htmlspecialchars(trim($ps)) . "\">" . htmlspecialchars(trim($ps)) . "</option>\n" ;
					}
			?>			
					</select>
			<?		
				} else {	
			?>			
						<input type="Text" name="provOrState" size="30" value="">
			<?
				}
			?>				
			</td>
		</tr>
		
		<tr>
			<td class="text1" nowrap>Postal Code/Zip Code :</td>
			<td><input type="Text" size="30" name="postalCode" value="<?= submit("postalCode") ?>"></td>
		</tr>
		
		
				
		
	<tr>
	<td width="100" class="text1"><? echo $txt10; ?></td><td class="text1"><input type="text" size="30" name="courriel" value="<? echo $_POST['courriel']; ?>" /></td>
	</tr>
	<tr>
	<td width="100" class="text1"><? echo $txt11; ?></td><td class="text1"><input type="text" size="30" name="courriel_verif" value="<? echo $_POST['courriel_verif']; ?>" /></td>
	</tr>
	<tr>
	<td class="text1"><? echo $txt12; ?></td><td class="text1"><input type="password" name="password" value="" /></td>
	</tr>
	<tr>
	<td class="text1"><? echo $txt13; ?></td><td class="text1"><input type="password" name="password_verif" value="" /></td>
	</tr>
</table><br />

<input type="submit" name="submit" value="<? echo $txt24; ?>" />
</form>
<a href="site.php"><? echo $txt14; ?></a><br /><br />
</center>
<?
}
else { ?>
	<br /><br />
	<table align="center">
	<tr><td class="text1" align="center"><? echo $txt15; ?></td></tr>
	<tr><td class="text1" align="center"><a href="site.php"><? echo $txt16; ?></a><br /></td></tr>
	</table>
	<br /><br />
	<? }
mysql_close();
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Eghh. Too much code and no highlighting (you should edit your post to include the

Code: Select all

bbCode around your code).

Have you done any debugging? Maybe you should put more time into pinpointing the problem.   
Just output any variables that are necessary for the code to work and see what their values are.
Post Reply