Looking For a PHP Form Script

Hello Everyone!
<snip /> I’m looking for a PHP Form Script to go with the form I created. Can someone tell me where I can find a good PHP Form Script.

Thanks for your kind help in advance.

GerrySH

Can you elaborate? What kind of php form script? login? register? email?

Something like this?

<form action="" method="post">
<input type="text" name="username"><br />
<input type="password" name="password"><br />
<input type="submit" value="submit">
</form>

You need to supply more details if you want a useful reply.

The website I used to use for this sort of thing was Hotscripts

Well you can always use my GUI API, which provides easy ways to create HTML forms, tables and other components/containers in plain PHP. Heres the link, you will need basic OOP knowledge to use it properly though:
http://www.phpclasses.org/package/7857-PHP-A-PHP-GUI-API-for-programmers.html

Hi Godz06;5611945]
Thanks for replying so quickly to my inquiry. I need a php script for the form below.
GerrySH

form action=“http://www.mywebsite.com/” method=“post”>
<input type=“hidden” name="subject value=“Form Submission” />
<input type=“hidden” name=“redirect” value=“thankyou.html” />

  &lt;p&gt;
  &lt;label&gt;First Name:&lt;br /&gt;
    
    &lt;input name="first name" type="text" id="first name" size="30" maxlength="40" /&gt;
  &lt;/label&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label for="last name"&gt;Last Name:&lt;br /&gt;
      
    &lt;/label&gt;
   
    &lt;input name="last name" type="text" id="last name" size="30" maxlength="40" /&gt;
    &lt;/p&gt;
  &lt;p&gt; 
    &lt;label for="email"&gt;E-Mail:
      &lt;br /&gt;
    &lt;/label&gt;
   &lt;input name="email" type="text" id="email" size="30" maxlength="40" /&gt;
    &lt;/p&gt;
  
  &lt;p&gt;
 
  &lt;label&gt;Type Your Comments Here: 
    &lt;br /&gt;
    &lt;textarea name="comments" id="comments" cols="45" rows="10"&gt;&lt;/textarea&gt;
  &lt;/label&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label&gt;
      &lt;input name="submit" type="submit" id="submit" accesskey="s" onclick="MM_validateForm('first name','','R','last name','','R','email','','RisEmail');return document.MM_returnValue" value="Submit" /&gt;
    &lt;/label&gt;
  &lt;/p&gt;
  

 
 &lt;/form&gt;

Hi Rubble: I did supply the name of my website but it was edited out by an administrator. Thanks for your tip, I’ll check out Hotscripts.

Hall of Famer! Thanks for the link. Have a good day.
GerrySH

You are very welcome. The script is very easy to use once you know how to program in OOP, its even better suited for a MVC framework in which the view is rendered in one place. If your form is simple, you may use the FormBuilder class to simplify the process of creating PHP forms.

Hall of Famer!

I’m embarrassed to say that I have little knowledge of PHP and have no idea what to do with all the files in your GUI API. Am I supposed to download all the files? I don’t have a windows computer but can I download the files to my mac computer? I’ll follow your advice and use the FormBuilder class because I have a very basic form. See I paste the form below. Thanks again for all the info. GerrySH

form action=“http://www.mywebsite.com/” method=“post”>
<input type=“hidden” name="subject value=“Form Submission” />
<input type=“hidden” name=“redirect” value=“thankyou.html” />

  &lt;p&gt;
  &lt;label&gt;First Name:&lt;br /&gt;
    
    &lt;input name="first name" type="text" id="first name" size="30" maxlength="40" /&gt;
  &lt;/label&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label for="last name"&gt;Last Name:&lt;br /&gt;
      
    &lt;/label&gt;
   
    &lt;input name="last name" type="text" id="last name" size="30" maxlength="40" /&gt;
    &lt;/p&gt;
  &lt;p&gt; 
    &lt;label for="email"&gt;E-Mail:
      &lt;br /&gt;
    &lt;/label&gt;
   &lt;input name="email" type="text" id="email" size="30" maxlength="40" /&gt;
    &lt;/p&gt;
  
  &lt;p&gt;
 
  &lt;label&gt;Type Your Comments Here: 
    &lt;br /&gt;
    &lt;textarea name="comments" id="comments" cols="45" rows="10"&gt;&lt;/textarea&gt;
  &lt;/label&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label&gt;
      &lt;input name="submit" type="submit" id="submit" accesskey="s" onclick="MM_validateForm('first name','','R','last name','','R','email','','RisEmail');return document.MM_returnValue" value="Submit" /&gt;
    &lt;/label&gt;
  &lt;/p&gt;
  

 
 &lt;/form&gt;

Well I can easily translate your code above into the below PHP code using my GUI API:


$form = new FormBuilder("myform", "http://www.mywebsite.com", "post");
$form->buildPasswordField("hidden", "subject", "Form Submission", TRUE)
     ->buildPasswordField("hidden", "redirect", "thankyou.html", TRUE)
     ->buildComment("First Name: ", TRUE)->buildTextField("firstname")  
     ->buildComment("Last Name: ", TRUE)->buildTextField("lastname")
     ->buildComment("E-mail: ", TRUE)->buildTextField("email")
     ->buildComment("Type your comment here: ", TRUE)->buildTextArea("comments")
     ->buildButton("Submit", "submit", "submit");

You have to create your own actions.
There is no generator that gets an “HTML” and returns “the PHP” code that makes some action.
You have to define that action.

So, you’d better start to code :slight_smile:
Also, you have some nasty HTML errors (I think you used some generator <my guess: Dreamweaver> and, you should type it by hand).

  1. Check your quotes
  2. Do not have id or name with spaces (“first name” is bad. Use “first_name”)
  3. Align your code, it will be easier to debug.
  4. The submit does not need a label
  5. Avoid JavaScript validations. You may have AJAX, but this is another chapter.
  6. The FORM action may be empty. The form will send the request to the current PHP page.

I have some time and I will write some code for you but, it’s not tested.


<?php

error_reporting(E_ALL);

$ERROR = array();

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

	$requiredFields = array(
		'first_name' => 'First Name',
		'email' => 'E-Mail',
		'comments' => 'Your Comments',
	);
	foreach( $requiredFields as $field => $label )  {
		if( false == isset($_POST[$field]) || '' === trim($_POST[$field]) ) {
			$ERROR[] = 'The field '.$label.' is required.';
		}
	}

	if( false == filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
		$ERROR[] = 'You provided an invalid email address.';
	}
	
	if( empty($ERROR) ) {
		
		// do whatever you need
		$to = 'you@example.com';
		$subject = 'website message';
		
		$message = "First name: {$_POST['first_name']}<br /><br />\

		Last name: {$_POST['last_name']}<br /><br />\

		Email: {$_POST['email']}<br /><br />\

		Comments: {$_POST['comments']}<br /><br />\

		IP: {$_SERVER['REMOTE_ADDR']}<br /><br />\

		Server date: ".date('d M Y H:i:s');
		
		$headers  = 'MIME-Version: 1.0' . "\\r\
";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\\r\
";
		$headers .= 'From: ' . $_POST['email'] . "\\r\
";
		
		if( @mail($to, $subject, $message, $headers) ) {
			header('Location: '.( isset($_POST['redirect']) ? $_POST['redirect'] : './' ));
			exit;
		} else {
			$ERROR[] = 'Cannot send the email.';
			// this will not work on localhost unless you have a mail-server installed
		}
	}
	
}

?>
<form action="" method="post">

	<?php if( !empty($ERROR) ) { ?>
		<p style="color:#c00"><?php echo '- '.implode('<br />- ', $ERROR) ?></p>
	<?php } ?>

	<input  type="hidden" name="subject" value="Form Submission" />
	<input type="hidden" name="redirect" value="thankyou.html" />

	<p>
		<label>First Name: *<br />
		<input name="first_name" type="text" id="first_name" size="30" maxlength="40" /></label>
	</p>
	<p>
		<label>Last Name:<br />
		<input name="last_name" type="text" id="last_name" size="30" maxlength="40" /></label>
	</p>
	<p>
		<label>E-Mail: *<br />
		<input name="email" type="text" id="email" size="30" maxlength="40" /></label>
	</p>

	<p>
		<label>Type Your Comments Here: *<br />
		<textarea name="comments" id="comments" cols="45" rows="10"></textarea></label>
	</p>
	<p>
		<input name="submit" type="submit" id="submit" accesskey="s" value="Submit" />
	</p>
</form>

PS: I once had an ajax contact form, when I had a blog. By time, I decided that I’m not a blogger so, I deleted the blog.
If you are interested send me a PM with your email and I will give you the code (I will search into my archive, hope I’ll find it).

Hall of Famer!
That’s amazing! Thanks for all your help.
GerrySH

Vectorialpx! Thanks for your help. I’ll PM you.