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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've been creating iPhone apps for a while now, using basic transformations (rotations, scale,
I've been creating a checklist webapp using JQuery, and so far it has been
I'm not thinking too clearly right now and possibly overlooking something simple. I've been
I have been creating an image gallery with jQuery, all is done. The images
Right now, I use a combination of Python and R for all of my
I've been struggling with this for 7 days now. Your insights will be greatly
I have been busy with the cakePHP framework for a couple of months now
again. Right now I'm having issues with some pretty basic functionality in PHP. I
So, I'm starting a C++ class right now, and I've configured NetBeans (which I
Surprisingly I've been unable to find anyone else really doing this, but surely someone

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.