1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple (apparently) coldfusion email form.

Discussion in 'Programming' started by angrypenguin, Nov 6, 2006.

  1. #1
    Hi all, I'm trying to create a really simple form that will accept name, email, and comments from a form and email the results to me. I can't see why the following code won't work. Can anyone help me?

    Index.cfm

    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="comments_background">
    <tr>
    <td><cfform action="http://localhost:8500/cfide/commentssite/action.cfm" method="post" name="comments_form" class="blog_main_body" id="comments_form">
    <p>Name:<br />
    <cfinput name="name" type="text" id="name" size="50" maxlength="100" required="yes"/>
    </p>
    <p>Email address (Optional):<br />
    <label>
    <cfinput name="email" type="text" id="email" size="50" maxlength="100" />
    </label>
    </p>
    <label></label>
    <p>Comments:
    <label>
    <br />
    <cftextarea name="comments" cols="50" rows="5" id="comments" required="yes"></cftextarea>
    </label>
    </p>
    <p>
    <label>
    <input name="submit" type="submit" id="submit" value="Submit" />
    </label>
    <label>
    <input name="reset" type="reset" id="reset" value="Reset" />
    </label>
    </p>
    </cfform> </td>
    </tr>
    </table>



    action.cfm

    <cfquery name = "comments" datasource="comments">
    SELECT NAME,EMAIL,COMMENTS
    FROM COMMENTS
    INSERT INTO COMMENTS (name,email,comments)
    Values ('#comments.name#','#comments.email#','#comments.comments#')
    </cfquery>

    <CFMAIL TO= "email@andyjessop.co.uk"

    FROM= #comments.email#
    SUBJECT= "Comments about website">
    Thank you for sending in your comments.
    </CFMAIL>
     
    angrypenguin, Nov 6, 2006 IP
  2. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    hmm interesting

    Question - why do you have your index.cfm in the cfide folder? Don't do that, put it somewhere else.

    Index.cfm looks good
    Action.cfm needs some changes - consider this instead:

    <cfif IsDefined("Form.email")>
    <cfquery name = "InsertComments" datasource="comments">
    INSERT INTO COMMENTS (name,email,comments)
    Values ('#Form.name#','#Form.email#','#Form.comments#')
    </cfquery>

    <CFMAIL TO= "email@andyjessop.co.uk"
    FROM= #Form.email#
    SUBJECT= "Comments about website">
    Thank you for sending in your comments.
    </CFMAIL>
    <!--- I'm not sure why you are doing this but here is the query you had --->
    <cfquery name = "Getcomments" datasource="comments">
    SELECT NAME,EMAIL,COMMENTS
    FROM COMMENTS
    </cfquery>
    <cfdump var="#GetComments#">
    </cfif>


    If per chance your comments table has a lot of records you can do with you dumping it. I only added the dump so that you can see that it was inserted into the DB.

    Also, you may need to check to see if you have a mail server defined in the ColdFusion Administrator. If not, you will need to explicitly state what the server is.

    PS: Look up the documentation on the cfmail tag.


    Hope I helped

    DaTropics!
     
    datropics, Nov 6, 2006 IP