Help with a Form...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chrisjc
    Contributor
    • Nov 2006
    • 375

    Help with a Form...

    I am currently working on a form I need a few things from this form. First of all here is the link to what I have so far... ( http://www.triplesource.net/php/Decal%20Offer.html ) And posted below is the code for ( submit.php ) Now the first part of the form is just a HTML page with an action pointing to ( SUBMIT.php )

    Now a problem I am having is one the e-mailing... the whole form to me... but also befor that I think I should say I have * as in indicator to the user that those fields must be filled in... how ever my code doesnt not stop them with an error message because I am not sure how to set up the right ( IF statment.)

    Another issue on this form is I do not nor have I ever had someone upload a photo... I put the (BROWSE) box in place.. but I need to make it so they can only pick a GIF,JPG,TIF,PDF ,PSD, and so on any image format... that is one issue... 2nd with that is that I want the image to be displayed on the (submit.php) page and show them also once they have hit submit I am wanting the form infomation to be sent to my e-mail adress with the picture as well.. would you please be able to help me with this.???

    I am very new to php/MySQL I also have another very big question but I will save it for another threed another project.... That I am trying to pull off... Thank you!

    Code:
    <html>
    
    <head>
    <title>Free Windshield Decal Offer</title>
    <script language="JavaScript">
    <!--
    function FP_preloadImgs() {//v1.0
     var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
     for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
    }
    
    function FP_swapImg() {//v1.0
     var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
     n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
     elm.$src=elm.src; elm.src=args[n+1]; } }
    }
    
    function FP_getObjectByID(id,o) {//v1.0
     var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
     else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
     if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
     for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
     f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
     for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
     return null;
    }
    // -->
    </script>
    </head>
    
    <body onload="FP_preloadImgs(/*url*/'Images/button14.gif',/*url*/'Images/button15.gif')">
    <?php
    $headers  = "From: MySite@mycom.com";
    $to       = "you@yoursite.com";
    $subj     = "Here is your html";
    $body     = "This form needs to be sent to my e-mail!!!";
    if (!mail($to, $subj, $body, $headers))
      echo 'Error';
    else
      echo 'Message sent';
    ?>
    
    <div align="center">
    	<table border="0" id="table1">
    		<tr>
    			<td width="727" colspan="2">
    			<p align="center"><b><font size="2" face="Tahoma">Thank you, Your 
    			Application will be processed in 24 to 48 hours.</font></b><hr size="1" color="#C0C0C0"></td>
    		</tr>
    		<tr>
    			<td width="727" colspan="2" align="center"><b>
    			<font face="Tahoma" size="2">You submitted the following 
    			information:</font></b></td>
    		</tr>
    		<tr>
    			<td width="367" height="21" align="center">
    			<p align="right"><b><font face="Tahoma" size="2">
    			Select Vehicle Type:</font></b></td>
    			<td align="left">
    			<p align="left">&nbsp[PHP];<?php echo htmlspecialchars($_POST['Select']); ?></td>
    		</tr>
    		<tr>
    			<td width="367" align="center">
    			<p align="right"><b><font face="Tahoma" size="2">Street:</font></b></td>
    			<td align="left">
    			<p align="left">&nbsp[PHP];<?php echo ($_POST['Mailing']); ?></td>
    		</tr>
    		<tr>
    			<td width="367" align="center">
    			<p align="right"><b><font size="2" face="Tahoma">City:</font></b></td>
    			<td width="360" align="left">
    			&nbsp;&nbsp[PHP];<?php echo ($_POST['City']); ?></td>		</tr>
    		<tr>
    			<td width="367" align="center">
    			<p align="right"><b><font size="2" face="Tahoma">State:</font></b></td>
    			<td width="360" align="left">
    			&nbsp;&nbsp;[PHP]<?php echo ($_POST['State']); ?></td>		</tr>
    		<tr>
    			<td width="367" align="center">
    			<p align="right"><b><font size="2" face="Tahoma">Zip/Postal Code:</font></b></td>
    			<td width="360" align="left">
    			&nbsp;&nbsp[PHP];<?php echo ($_POST['Zip']); ?></td>	</tr>
    		<tr>
    			<td width="367" align="center">
    			<p align="right"><b><font face="Tahoma" size="2">
    			E-Mail Address:</font></b></td>
    			<td width="360" align="left">
    			<p align="left">
    			&nbsp[PHP];<?php echo ($_POST['E-mail']); ?> </td>	</tr>
    		<tr>
    			<td width="367" align="center">
    			<p align="right"><b><font face="Tahoma" size="2">
    			Copy of your aFe 
    			purchase invoice:</font></b></td>
    			<td align="left">
    			<p align="left">&nbsp;<?php echo ($_POST['FileToUpload']); ?></td>
    		</tr>
    		<tr>
    			<td width="367" valign="top" align="center">
    			<p align="right"><b><font face="Tahoma" size="2">Testimonial:</font></b></td>
    			<td width="360" align="left">
    			<p align="left">&nbsp;<?[PHP]php echo ($_POST['Testimonial']); ?><p align="left">&nbsp;<p align="left">&nbsp;<p align="left">&nbsp;</td>
    		</tr>
    		<tr>
    			<td width="367" valign="top" align="center">
    			<p align="right"><b><font face="Tahoma" size="2">Questions/Comments:</font></b></td>
    			<td width="360" align="left">
    			<p align="left">
    			&nbsp[PHP];<?php echo ($_POST['Questions']); ?><p align="left">			&nbsp;<p align="left">
    			&nbsp;<p align="left">
    			&nbsp;</td>
    		</tr>
    		<tr>
    			<td width="727" colspan="2" align="center">
    			<hr size="1" color="#C0C0C0"></td>
    		</tr>
    		<tr>
    			<td colspan="2">
    			<p align="center"><a href="http://afefilters.com/">
    			<img border="0" id="img1" src="Images/button13.gif" height="20" width="100" alt="Home page" onmouseover="FP_swapImg(1,0,/*id*/'img1',/*url*/'Images/button14.gif')" onmouseout="FP_swapImg(0,0,/*id*/'img1',/*url*/'Images/button13.gif')" onmousedown="FP_swapImg(1,0,/*id*/'img1',/*url*/'Images/button15.gif')" onmouseup="FP_swapImg(0,0,/*id*/'img1',/*url*/'Images/button14.gif')" fp-style="fp-btn: Simple Line 1; fp-font-style: Bold; fp-transparent: 1" fp-title="Home page"></a></p>
    		</tr>	</table>
    </div>
    
    </body>
    
    </html>
    Last edited by ronverdonk; Nov 9 '06, 10:37 AM. Reason: You can store all code within one set of code tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Since I cannot see, in your code shown, where the <form> statement begins and ends, I visited the link you gave. There the <form> can be seen. Now this is going to be a long reply:

    If you want to verify and cleanse all fields the user typed in, the easiest way to handle that is to start your script with a check whether the routine was called for the first time or due to a form submit. You can determine that by e.g. having a hidden field in your form such as with name 'submitted' and check the existence of that field in the $_POST array. If it is not present, the form was not submitted i.e. this is the first time your script was called. When field 'submitted' is in the $_POST array, it means that the form was submitted and you have to check the filled in fields.

    So first you make it possible to determine if a form was submitted or not, by inserting the following hidden field statement right after the <form action=....> statement.
    Code:
    <input type="hidden" name="submitted" value="1" />
    Then you check, at the start of your script, if the script was called the first time or as a result of a submit. At the start of your script you insert the following:
    [php]
    <?php
    // check if form was submitted
    if (isset($_POST['submitted'])) {
    $errors=array() ;
    // it was submitted so here you do your field checking
    // let's do E-mail as an example
    // verify (a) filled in, (b) that is is an email address
    if (!isset($_POST['E-mailmai']) OR
    !ereg ('(^[0-9a-zA-Z_\.-]{1,}@([0-9a-zA-Z_\-]{1,}\.)+[0-9a-zA-Z_\-]{2,}$)', $_POST['email']) )
    // email address incorrect, add msg to error array
    $errors[] = "Invalid email address";
    else
    // email address okay, cleanse and save it
    $email = stip_tags(trim( $_POST['E-mail']));
    //
    // more checking and validation ....
    //
    // .......

    // at the end of your checking, see if any errors are set
    if ($errors)
    // if so, display the $errors array
    // do not exit so the form is re-displayed
    }
    else {
    // there are no errrors, send the email and exit
    //
    // here is your email build and send code
    //
    exit;
    }
    } // End of submit check

    // from here on the form is displayed (again)
    <html>
    etc......
    [/php]
    Still to be coded: the display of all previously filled in fields in the case where the form is re-displayed. You don't want your users to fill in every field again in case of an error.

    Let's, again, take the email <input> field as an example. The statement that requests the input must be changed, so it displays the content of variable $email (the var in which the email addess was saved). Like this
    Code:
    <input name="E-mail" size="36" style="float: left" value="<? echo $email ?>"></td>
    Good luck with your form.

    Ronald :cool:

    Comment

    Working...