SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Complicated Javascript Form

    I want to make a form that will ensure that all fields have a keyword. So, for example there will be a text area where the user must insert a keyword:

    [ Keyword ]

    Then there will be some other fields:

    [ Title ]
    [ Description ]
    [ Keyword, Keyword, Keyword ]
    [

    Content Paragraph One

    Content Paragraph Two

    Content Paragraph Three

    ] <- This one is a text area

    When the user hits the ssubmit button, the form should check that the keyword is in the title once, the keywords
    3 times, the description three times and the content 6 times. If it is not present, the form will take them back and say that X feild is lacking Y amount of kwywords.

    What is the best way to do this? Is there anyone that knows how to do this, because I don't know how. Javascript?



    Is there anyone that would code this for me? In return I will make you a search engine friendly template, that is cross browser friendly and fast loading. Or I will optimise your current index page for you. I have 18 months commercial experience doing this, where I was recently employed full time on location. ..but I don't know enough javascript to make this.

    MrLeN

  2. #2
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Germany
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may have a form
    Code:
    <form action="anmeldung_check.html" method="post">
    
      <table width="100%" align="top" border="0" cellpadding="0" cellspacing="0">
    
       <tr>
        <td class="tbl_anmeldung_capt">
         * Anrede
        </td>
        <td class="tpl_anmeldung_form">
         <input type="radio" name="form[Anrede]" value="Herr" checked> Herr&nbsp;&nbsp;
         <input type="radio" name="form[Anrede]" value="Frau"> Frau
        </td>
       </tr>
    
       <tr>
        <td class="tbl_anmeldung_capt">
         * Vorname
        </td>
        <td class="tpl_anmeldung_form">
         <input type="text" name="form[Vorname]" size="30">
        </td>
       </tr>
    
       <tr>
        <td class="tbl_anmeldung_capt">
         * Nachname
        </td>
        <td class="tpl_anmeldung_form">
         <input type="text" name="form[Nachname]" size="30">
        </td>
       </tr>
    
       <tr>
        <td class="tbl_anmeldung_capt">
         * E-Mail
        </td>
        <td class="tpl_anmeldung_form">
         <input type="text" name="form[Email]" size="40">
        </td>
       </tr>
    
       <tr height="20">
        <td class="tbl_anmeldung_capt"></td>
        <td class="tpl_anmeldung_form"></td>
       </tr>
    .............
    Now controll if everthing has been put in the form
    the file is called:anmeldung_check.html
    Code:
    header...........
    <?php
    
      $fields = array(
        Email     => 'E-Mail',
      
      Strasse   => 'Strasse (dienstlich)',
     
       PLZ       => 'PLZ (dienstlich)',
    
        Ort       => 'Ort (dienstlich)',
      
      Telefon   => 'Telefon (dienstlich)',
       
     Strasse_p => 'Strasse (privat)',
    
       PLZ_p     => 'PLZ (privat)',
    
        Ort_p     => 'Ort (privat)',
     
       Telefon_p => 'Telefon (privat)',
    
        Funktion   => 'Sonstige Angaben'
      );
    
     
    
     $fillfields = array('Anrede', 'Vorname', 'Nachname', 'Email',  'Strasse', 'PLZ', 'Ort');
    
    
    
      $failedfields = array();
      foreach ($fillfields as $fillfield) {
        if (!$form[$fillfield]) {
          if ($fields[$fillfield]) {
            array_push($failedfields, $fields[$fillfield]);
          } else {
            array_push($failedfields, $fillfield);
          }
        }
      }
    
    ?>
    
    
    <div id="lay100" class="lay100">
    
    <?php 
      if (count($failedfields) > 0) {
        print "Folgende Angaben fehlen:<br><br>\n";
        foreach ($failedfields as $f) {
          print "* " . $f . "<br>\n";
        }
        print "<br>Bitte gehen Sie zurück und füllen Sie das Formular vollständig aus.<br>\n";
      } 
      else {
        print "<h3>Title</h3>\n";
        print "<form action=\"anmeldung_send.html\" method=\"post\">\n";
        
        print "<table width=\"100%\" align=\"top\" border=\"0\">\n";
    
        foreach ($form as $field => $value) {
          print "   <tr>\n";
          print "    <td class=\"lay100a\" width=\"35%\">\n";
          if ($fields[$field]) {
            print "     <b>" . $fields[$field] . "</b>\n"; 
          } 
          else {
            print "     <b>" . $field . "</b>\n"; 
          }
          print "    </td>\n";
          print "    <td class=\"lay100b\">\n";
          print "     " . $value . "\n";
          print "     <input type=\"hidden\" name=\"form[" . $field . "]\" value=\"" . $value . "\">\n";
          print "    </td>\n";
          print "   </tr>\n";
        }
        print "</table><br>\n";
        print "<input type=\"submit\" value=\"Anmeldung versenden\">\n";
        print "</form>\n";
      }
    ?>
    
    <br><br><br><br>
    </div> 
    
     
    </body>
    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •