We launched new forums in March 2019β€”join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    I made a for in a chunk that post the fields to a snippet i adapted from a php script

    the chunk:
    <form enctype="multipart/form-data" name="contactForm" action="[~19~]" method="POST">
    			<div align="left">
    			<input type="hidden" name="required" value="Bedrijfsnaam,Contactpersoon,Telefoon,Email,subject"> 
    			<input type="hidden" name="recipient" value="[email protected]"> 
    					<font face="Verdana, Arial, Helvetica, sans-serif"><input type="hidden" name="required" value="Bedrijfsnaam,Contactpersoon,Telefoon,Email,subject"> 
    				
    				<!-- De namen van de velden die veplicht ingevuld moeten worden gescheiden door komma's --><!-- De bovenstaande hidden fields moeten verplicht in het fomrulier worden opgenomen --></font>
    					<table width="386" border="0" cellspacing="2" cellpadding="0" height="237">
    						<tr>
    							<td colspan="3"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif"><span class="bold">Uw</span></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="bold"> gegevens zijn:</span></font><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif"><img src="../../phpscript/afbeeldingen/spacer.gif" alt="" height="8" width="180" border="0"><span class="top">(*=verplicht)</span></font></td>
    						</tr>
    						<tr>
    							<td width="100"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">bedrijf</font></td>
    							<td width="268"><input type="text" name="Bedrijfsnaam" size="42" tabindex="1" border="0"></td>
    							<td><span class="rood">*</span></td>
    					</tr>
    						<tr>
    							<td width="100"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">contactpersoon</font></td>
    							<td valign="middle" width="268"><input type="text" name="Contactpersoon" size="27" tabindex="2" border="0"><img src="../../phpscript/afbeeldingen/spacer.gif" alt="" height="10" width="7" border="0"><font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">m</font><img src="../../phpscript/afbeeldingen/spacer.gif" alt="" height="10" width="4" border="0"><input type="radio" name="m/v" value="man" checked border="0"><img src="../../phpscript/afbeeldingen/spacer.gif" alt="" height="10" width="4" border="0"><img src="../../phpscript/afbeeldingen/spacer.gif" alt="" height="10" width="4" border="0"><font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">v</font><img src="../../phpscript/afbeeldingen/spacer.gif" alt="" height="10" width="4" border="0"><input type="radio" name="m/v" value="vrouw" border="0"></td>
    							<td><span class="rood">*</span></td>
    					</tr>
    						<tr>
    							<td width="100"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">telefoon</font></td>
    							<td width="268"><input type="text" name="Telefoon" size="42" tabindex="3" border="0"></td>
    							<td><span class="rood">*</span></td>
    					</tr>
    						<tr>
    							<td width="100"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">email</font></td>
    							<td width="268"><input type="text" name="Email" size="42" tabindex="4" border="0"></td>
    							<td><span class="rood">*</span></td>
    					</tr>
    						<tr>
    							<td width="100"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">onderwerp</font></td>
    							<td width="268"><input type="text" name="subject" size="42" tabindex="5" border="0"></td>
    							<td><span class="rood">*</span></td>
    						</tr>
    						<tr>
    							<td valign="top" width="100"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">bericht</font></td>
    							<td width="268"><textarea name="Bericht" rows="6" cols="50" tabindex="6"></textarea></td>
    							<td></td>
    						</tr>
    						<tr>
    							<td width="100"></td>
    							<td width="268"><input type="submit" value="verzenden" tabindex="7" border="0"></td>
    							<td></td>
    					</tr>
    				</table>
    			</form>
    


    the snippet:
    if ($REQUEST_METHOD=="POST") 
    
          $correct = "yes"; 
          $message = ""; 
    
          //Check required
          $check_required = split(",", $required); 
          for($i=0; $i<count($check_required); $i++) 
          { 
              if(strlen($$check_required[$i]) < 1) 
              { 
                 $form.=("Het veld <B>". $check_required[$i] ."</B> is niet ingevuld!<P>"); 
                  $correct = "no"; 
              } 
          } 
    
         //All fields ok? 
         if($correct == "yes") 
         { 
             while(list($fieldname) = each($HTTP_POST_VARS))  //see what field are posted 
             { 
                 if(($fieldname != "recipient") && ($fieldname != "subject") && ($fieldname != "required")) //Do not send required fields 
                 { 
                     $message = $message . "$fieldname:   "; 
                     $message = $message . $$fieldname; 
                     $message = $message . "\n\n"; 
                 } 
             } 
             mail("$recipient", "$subject", "$message", "From: $Email");  //mail the form. 
    
              $form.= ("<CENTER><br><br><br><br><I>Bedankt voor uw aanvraag.<br><br>
             We zullen zo spoedig mogelijk contact met u opnemen.<br>
             Wij wensen u nog een prettige dag.</I></CENTER>"); 
         } 
         else 
         { 
              $form.= ("<P><A href='#' onClick='history.back(1)'>Terug</A>"); 
         } 
     
    return $form;
    


    but its not working some how the posted fields are not found
    when i use the original php script than it works but it wil open in a blank window not in my template.

    original code:
    <body background="images/main.gif">
    	<?php 
    if ($REQUEST_METHOD=="POST") 
    { 
          $correct = "yes"; 
          $message = ""; 
    
          #Check voor verplichte velden 
          $check_required = split(",", $required); 
          for($i=0; $i<count($check_required); $i++) 
          { 
              if(strlen($$check_required[$i]) < 1) 
              { 
                  echo("Het veld <B>". $check_required[$i] ."</B> is niet ingevuld!<P>"); 
                  $correct = "no"; 
              } 
          } 
    
         #Als alle velden ingevuld zijn 
         if($correct == "yes") 
         { 
             while(list($fieldname) = each($HTTP_POST_VARS))  //Kijken welke velden er allemaal in het formulier voorkomen 
             { 
                 if(($fieldname != "recipient") && ($fieldname != "subject") && ($fieldname != "required")) //Verplichte velden niet meesturen 
                 { 
                     $message = $message . "$fieldname:   "; 
                     $message = $message . $$fieldname; 
                     $message = $message . "\n\n"; 
                 } 
             } 
             mail("$recipient", "$subject", "$message", "From: $Email");  //mail het formulier door. 
    
             echo("<CENTER><br><br><br><br><I>Bedankt voor uw aanvraag.<br><br>
             We zullen zo spoedig mogelijk contact met u opnemen.<br>
             Wij wensen u nog een prettige dag.</I></CENTER>"); 
         } 
         else 
         { 
             echo("<P><A href='#' onClick='history.back(1)'>Terug</A>"); 
         } 
    } 
    
    ?>
    </body>
    


    Am I missing somthing?
    in converting php to snippet?

    hope that some one can helop me out here
      follow me on twitter: @dimmy01
      • 28042 β˜† A M B β˜†
      • 24,524 Posts
      Have you tried taking a look at the contact form snippet that comes with MODx and adapting that? It would not be difficult to change that "all fields are required" to your checking of the values returned against the hidden input field. The nice thing about it is that it’s all on one snippet, so it all works on the same page.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 7455
        • 2,204 Posts
        I did look at that script, looks a bit complex to just mess about
        and i like the idea of designing the form in dreamweaver and have the snippet handel the form

        I use the sendanyform snippet (hxxp://www.etomite.org/browsesnippets.html?int_snipid=151&lst_category=3) from etosite alot but that does not have requierd fields options, I am just not taht good in php to edit that script so that it works, I can copy a lot and alter a bit but this is just not my league (yet)
          follow me on twitter: @dimmy01