Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 972687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:09:45+00:00 2026-05-16T03:09:45+00:00

Right now i been creating a form for a comment section, a Login section,

  • 0

Right now i been creating a form for a comment section, a Login section, and sending email for a site i’m doing. The code I using was from a tutorial I learned and has too much HTML in it. It was the only way I knew how to create a form and valid the data. I wanted to ask if there was a better way to create forms and if there was a way to create a form in OOP PHP? I want learn to go beyond basic stuff to OOP.

Here’s an example of the code I using for the moment:

<?php include 'includes/validation.php' ?>

<!-- START CONTENT -->
  <div id="mainContent">
  <div class="portContentTop"><img src="graphx/image.gif" alt="" border="0" /></div>
  <div class="portContent">
   <img src="graphx/image.gif" alt="Contact Me" border="0" /><h1 class="hidden">Contact</h1><br />
            If you wish to contact me, please fill out the form or send me an email at <a href="mailto:user@gmail.com">user@gmail.com</a>.
   <br />
             <? if( isset($_POST['send'])&& (!validateName($_POST['name']) || !validateEmail($_POST['email']) || !validateMessage($_POST['message']) ) ):?> 
            <div id="errorMessage">
             <ul>
                 <? if(!validateName($_POST['name'])):?>
                 <li>Your name must be 4 characters long.</li>
                    <? endif ?>
                    <? if(!validateEmail($_POST['email'])):?>
                    <li>Your email address has an error.</li>
     <? endif ?>
                    <? if(!validateMessage($_POST['message'])):?> 
                    <li>Your comment must be 10 characters long.</li>
                    <? endif ?>
             </ul>
            </div>
            <?php elseif(isset($_POST['send'])):?>
            <?php
    $name=strip_tags($_POST['name']);
    $email=strip_tags($_POST['email']);
    $message=strip_tags($_POST['message']);
    $subject= "A message from me was submitted by ".$name." ";
    $sentto= "user@gmail.com";

    $contents = "Name: ".$name. "\n".
       "Email: ".$email. "\n".
       "Message: ".$message. "\n";

    mail($sentto, $subject, $contents);

   ?>
            <div id="errorMessage">
                <ul class="errorValid">
                 <li>Your message has been sent.</li>
             </ul>
            </div>
            <? endif?>
   <form method="post" id="customForm" name="customForm" action="" >
             <table  border="0" align="center" cellpadding="0" cellspacing="0" style="padding:0px; margin:0px;">
                  <tr valign="top">
                    <td align="center"><img src="graphx/h_name.gif" border="0" alt="Name:" /></td>
                    <td><input class="contactInput" id="name" name="name" type="text" size="30" /></td>
                  </tr>
                  <tr valign="top">
                    <td align="center"><img src="graphx/h_email.gif" border="0" alt="Email:" /></td>
                    <td><input class="contactInput" id="email" name="email" type="text" size="30" /></td>
                  </tr>
                  <tr valign="top">
                    <td align="center"><img src="graphx/h_comments.gif" border="0" alt="Comments:" /></td>
                    <td><textarea id="message" name="message" cols="30" rows="15" wrap="off"  class="contactInput2"></textarea></td>
                  </tr>
                  <tr valign="top">
                    <td></td>
                    <td align="left"><input id="send" name="send" type="submit" value="Submit" ></td>
                  </tr>
               </table>
          </form>
 </div>
<!-- END CONTENT -->
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:09:46+00:00Added an answer on May 16, 2026 at 3:09 am

    Yes, there are ‘better’ ways of creating forms. You might want to look at how popular frameworks do it.

    Here’s example from Zend Framework
    http://www.framework.zend.com/manual/en/zend.form.quickstart.html

      $form = new Zend_Form();
      $form->setAction('/user/login')
           ->setMethod('post');
    
      // Create and configure username element:
      $username = $form->createElement('text', 'username');
      $username->addValidator('alnum')
               ->addValidator('regex', false, array('/^[a-z]+/'))
               ->addValidator('stringLength', false, array(6, 20))
               ->setRequired(true)
               ->addFilter('StringToLower');
    
      // Create and configure password element:
      $password = $form->createElement('password', 'password');
      $password->addValidator('StringLength', false, array(6))
               ->setRequired(true);
    
      // Add elements to form:
      $form->addElement($username)
           ->addElement($password)
           // use addElement() as a factory to create 'Login' button:
           ->addElement('submit', 'login', array('label' => 'Login'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.