Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

<method="post"...>

Guest
Mar 01, 2009 Mar 01, 2009
does ANYONE have a simple explanation on how to SIMPLY post form data to a remote mysql database via CF8. Just looking for the basic syntax so i can collect (one column table) email addresses from site visitors..

thanks a million !!!
TOPICS
Getting started
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 02, 2009 Mar 02, 2009
your code:
<cfinput type="text" name="" validateat="onSubmit" validate="email"
required="yes" maxlength="45" typeahead="no"
showautosuggestloadingicon="true'>

you should give your field a proper NAME, and then reference that name
in your INSERT query. CF uses the NAME attribute to get filed values -
so always provide a valid** NAME to your form controls (**valid =
conforms to CF variable naming rules).

<cfif structkeyexists(form, 'submit') AND len(trim(form.email_address))>
<!--- form has been...
Translate
LEGEND ,
Mar 02, 2009 Mar 02, 2009
You don't post data to databases. You post data to cold fusion pages that query databases. The tag you want to use is <cfquery>. Usage is described in the cfml reference manual. If you don't have one, the internet does.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 02, 2009 Mar 02, 2009
Thanks for the quick reply and directon Dan! As you probably guessed, i am a few days into CF8, a 'newbie' if you will.... I was able to get a reference guide this morning from the bookstore and put together the following:

Can someone let me know if this is correct and why my MySQL database is not being updated with the data. I have datasource and table setup correctly.. Please explain any steps, this is the first CF8 I have ever written... :)

thanks !!!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2009 Mar 02, 2009
your code:
<cfinput type="text" name="" validateat="onSubmit" validate="email"
required="yes" maxlength="45" typeahead="no"
showautosuggestloadingicon="true'>

you should give your field a proper NAME, and then reference that name
in your INSERT query. CF uses the NAME attribute to get filed values -
so always provide a valid** NAME to your form controls (**valid =
conforms to CF variable naming rules).

<cfif structkeyexists(form, 'submit') AND len(trim(form.email_address))>
<!--- form has been submitted and email_address field is not empty:
insert into db --->
<CFQUERY NAME="insertFormData" DATASOURCE="blueskeleton">
INSERT INTO emails (emailAddress)
VALUES ('#form.email_address#')
</CFQUERY>
<!--- do whatever you need to do now that the email has been inserted
into db --->
</cfif>

...
<cfinput type="text" name="email_address" validateat="onSubmit"
validate="email" required="yes" maxlength="45">
...

also, your query was missing an opening ' in front of the inserted value...
also, in your <cfform> tag you seem to be missing = in the NAME attribute...
also, you have a stray ' after ID in your submit button code...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 05, 2009 Apr 05, 2009
LATEST

Azadi Saryev,


please see the code below and advise if this is correct.  As you probably know, i am very new at this, so any detailed explanations would be helpful.


this is at the very top of my .cfm page (website homepage)

( the name of the table and column are 'Emails' )

<cfif structkeyexists(form, 'submit') AND len(trim(form.Emails))>

<CFQUERY NAME="insertFormData" DATASOURCE="blueskeleton">
INSERT INTO Emails (Emails)
VALUES ('#form.Emails#')
</CFQUERY>

</cfif>


webpage code here.....

      <!--- form for email addresses --->

            <cfform> <strong>

            <center>

              Monthly Newsletter

            </center>

            </strong> <small> <em>

            <center>

              enter your email below

            </center>

            </em></small>

            <center>

              <cfinput type="text" name="Emails" autosuggest="true" maxlength="35" typeahead="no" showautosuggestloadingicon="true">

              <cfinput type="button" name="Submit" value="Submit">

            </center>

            </cfform>

    <!--- form ends here --->


web page ends here....

thanks!

jon

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2009 Mar 02, 2009
Your code looks ok. What indication do you have that the record is not being inserted?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 05, 2009 Apr 05, 2009

still alittle confused on my first cfm attempt.  please quickly review the code below and advise why this is not working. 

I have 2 files, my homepage, which is my index.cfm file and the component, which is Emails.cfc .... I am just trying to collect email addresses from visitors to my site on the homepage.

index.cfm code:

<cfif IsDefined("form.Emails")>

  <cfinvoke

      component="blueskeleton.cfc.Emails"

      method="insertEmails">

  <cfinvokeargument name="formData" value="#form#"/>

  </cfinvoke>

</cfif>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<!--- my webpage code is here ..  my index.cfm  --->

   <!--- form for email addresses --->

            <cfform> <strong>

            <center>

              Monthly Newsletter

            </center>

            </strong> <small> <em>

            <center>

              enter your email below

            </center>

            </em></small>

            <center>

              <cfinput type="text" name="Emails" autosuggest="true" maxlength="35" typeahead="no" showautosuggestloadingicon="true">

              <cfinput type="button" name="Submit" value="Submit">

            </center>

            </cfform>

            <!--- form ends here --->

<!--- web page ends --->

and here is the Emails.cfc file code..

<cfcomponent>

<cffunction>

<cffunction name="insertEmails" access="public" returntype="void">

  <cfargument name="formData" type="struct" required="yes">

  <cfquery datasource="blueskeleton">

    INSERT INTO Emails

        (Emails)

        VALUES

        ('#formData.Emails#')

    </cfquery>

</cffunction>

</cfcomponent>

It does not work because when i hit submit, the page does nothing and no email is added to my MySQL database.  I have the database setup correctly, i am confident it is something that i am doing incorrectly with the code above...


thanks fora any help with this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources