Jump to content

Tutorial for creating a membership form and saving data


kevinritt

Recommended Posts

I would like to take info from a membership form that I created for my website and store it in a database.  Can anyone recommend a tutorial that would guide me through the basics of doing this? The membership form has about 25 fields that I'd like to store in a db and referrence as needed. This is a wordpress site and i tried Gravity Forms but I need to have more flexibilty in the form creation.

(I know this forum is for code already written, so admin can you move to apporpriate forum?)

 

Thanks

Link to comment
Share on other sites

Thanks Voip03,

That tutorial will get me started but my form is quite extensive: name, address, state, zip, phone, business, etc and will have input, radio, drop down fields. Creating the form is not a problem. The things I'm weak on are validation (best practices, security), inserting into database (I can do basic but I want to make sure I do it correctly) and I need a way to access the info once it's submitted. I'd need to send an email to admin whenever the form is submitted.

Gravity Forms is great but it's the customization that's the problem.

I know it's a lot - thanks for any help

Link to comment
Share on other sites

Never trust the user and always validate user input

At the user end you can use JavaScript to validate the input, at the sever side PHP can be use.

 

1.Input fields are not empty

if(!empty($_POST["FirstName"]))
{ not empty}

 

2. Email validation

 

//Validate an E-mail Address
function check_email_address($email)
{ 
	// First, we check that there's one @ symbol, and that the lengths are right 
  		if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
	{ 
    		// Email invalid because wrong number of characters in one section, or wrong number of @ symbols. 
    		return false; 
		} 
	// Split it into sections to make life easier 
	$email_array = explode("@", $email); 
	$local_array = explode(".", $email_array[0]); 
	for ($i = 0; $i < sizeof($local_array); $i++)
	{ 
		 if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i]))
		 {	return false; 	} 
	}	 
	if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name 
	$domain_array = explode(".", $email_array[1]); 
	if (sizeof($domain_array) < 2) { 
		return false; // Not enough parts to domain 
	} 
	for ($i = 0; $i < sizeof($domain_array); $i++) { 
	if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { 
		return false; 
	} 
	} 
	} 

  	return true; 
}

 

3.PHP and Radio Buttons


<?PHP

$male_status = 'unchecked';
$female_status = 'unchecked';

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

$selected_radio = $_POST['gender'];

if ($selected_radio = = 'male') {
$male_status = 'checked';
}
else if ($selected_radio = = 'female') {
$female_status = 'checked';
}
}

?>

The HTML FORM code:

<FORM name ="form1" method ="post" action ="radioButton.php">

<Input type = 'Radio' Name ='gender' value= 'male' 
<?PHP print $male_status; ?>
>Male

<Input type = 'Radio' Name ='gender' value= 'female' 
<?PHP print $female_status; ?>
>Female

<P>
<Input type = "Submit" Name = "Submit1" VALUE = "Select a Radio Button">
</FORM>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.