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

Send a textbox value to an object

New Here ,
Jun 08, 2009 Jun 08, 2009

I have an object in ColdFusion that post message to twitter. It works when I write my message in “  “ like line below.
<cfset  twitterObj.postToTwitter "My Message" />


But I need to have a textbox, and type my message in textbox. I’m not sure how can write my textbox value here instead of this message, every think I tried give me an error. Can anybody help?

1.9K
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
Engaged ,
Jun 09, 2009 Jun 09, 2009

Consider how HTML works.  If we leave JavaScript out of the picture for simplicity, the user types his information into an input-box and then presses some kind of a submit-button.  Both the input-box and the button must therefore be contained in a <cfform>.  The web browser will package-up the entered data into (probably) POST data and send it to whatever URL is designated as the target of the form.  This target, then, will be the same or a different ColdFusion .cfm page.

This page, therefore, is "where you begin."  Whatever data the user has entered will be found as an appropriately-named variable in the POST data, along with the identity of the button that he just pushed.  This form must collect the data, validate it, and if it is valid send it to Twitter.  (You will use the same tag that you described, but the text comes from a POST variable.)  Then, it must either display some kind of HTML output, or use the <cflocation> tag to redirect to some other page which will do so.

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
New Here ,
Jun 09, 2009 Jun 09, 2009

Thanks for your reply, I did all that as I copy my code below, my problem is the syntax, I'm not sure what I should write here to access to the value of the text box.

<BODY>
     <form action="Form.cfm" method="post">
     <input type="text" name="twittMessage">
     <input type="Submit" name="SubmitForm" value="Submit to Twitter">
     <cfif IsDefined("Form.twittMessage")>
     <cfoutput>
     <cfset f = #Form.twittMessage#>
<br>
Your message postet to twitter:  #f#</cfoutput>
</cfif>


<!--- call the init() method  --->
<cfset twitterObj = createObject('component', 'twitterCFC').init('username','password') />


<!--- Post to twitter --->

//here *****


<cfset  twitterObj.postToTwitter ("This is my message that goes to twitter")/> // how I can get the value of textbox here for example I thought it's Form.twittMessage but it doesn’t work.

<!--- Get your timeline with friends --->
<cfset friendsTimeline = twitterObj.getFriendsTimeLine() />
<!--- OUTPUT:
<cfcontent type="text/xml"><cfoutput>#friendsTimeline#</cfoutput>
--->

<!--- Get the public timeline --->
<cfset publicTimeline =twitterObj.getPublicTimeline() />
<!--- OUTPUT:
<cfcontent type="text/xml"><cfoutput>#publicTimeline#</cfoutput>--->

</form>
</BODY>    

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
Valorous Hero ,
Jun 09, 2009 Jun 09, 2009
<BODY>

     <form action="Form.cfm" method="post">
     <input type="text" name="twittMessage">
     <input type="Submit" name="SubmitForm" value="Submit to Twitter">

^^^This part of the code runs both befor and after the form is submitted.^^^

     <cfif IsDefined("Form.twittMessage")>
     <cfoutput>

    <cfset f = #Form.twittMessage#>
<br>
Your message postet to twitter:  #f#</cfoutput>
</cfif>

^^^ THIS PART OF THE CODE runs only after the form is submitted.


<!--- call the init() method  --->
<cfset twitterObj = createObject('component', 'twitterCFC').init('username','password') />


<!--- Post to twitter --->



//here *****


<cfset  twitterObj.postToTwitter ("This is my message that goes to twitter")/> // how I can get the value of textbox here for example I thought it's Form.twittMessage but it doesn’t work.



<!--- Get your timeline with friends --->
<cfset friendsTimeline = twitterObj.getFriendsTimeLine() />
<!--- OUTPUT:
<cfcontent type="text/xml"><cfoutput>#friendsTimeline#</cfoutput>
--->

<!--- Get the public timeline --->
<cfset publicTimeline =twitterObj.getPublicTimeline() />
<!--- OUTPUT:
<cfcontent type="text/xml"><cfoutput>#publicTimeline#</cfoutput>--->

</form>
</BODY>    

^^^ This part of the code again runs both befor and after the form is submitted ^^^

Does that make sense why you may be having a problem.

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
New Here ,
Jun 09, 2009 Jun 09, 2009

So how I can get the textbox value?

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
Valorous Hero ,
Jun 09, 2009 Jun 09, 2009

You get the text box value AFTER a form has been submitted so one would use form.textboxname in the section of one's code that runs only after a form is submitted.  NOT in a section of one's code that runs both before and after a form is submitted, because this section of one's code is going to try and use the variable form.textboxname before it exists and it is going to throw an error.

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
New Here ,
Jun 09, 2009 Jun 09, 2009

Thanks Lan, It was really helpful and worked. I made a separate page for my action form use #Form.texboxname#". Thanks again.

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
Valorous Hero ,
Jun 09, 2009 Jun 09, 2009
LATEST

That is one solution.

If you care you could have also just fixed the original code:

<!--- This if block encloses logic to be run after the form is submitted --->

<cfif IsDefined("Form.twittMessage")>

<cfoutput>

    <cfset f = #Form.twittMessage#>
    <br>
    Your message postet to twitter:  #f#

</cfoutput>

<!--- Move this closing /cfif tag to enclose the rest of the logic that should only run after the form is submitted --->
</cfif>

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
Engaged ,
Jun 09, 2009 Jun 09, 2009

Please don't expect this forum to teach you how HTML form-submission works.  Whether you do it by "Googling it" or by reading tea-leaves, you're going to have to put forth a little bit of mental effort here.  There are ga-zillions of tutorials on this subject, and the only way that you're going to get a handle on what is going on is to study a few of them.  Everything that you'll read in any tutorial will apply, "ColdFusion or not."

If I were teaching a class tonight, I would put this on my pop-quiz:  (note to my students: "at ease, no pop-quiz this week...")

14.     In the space below, using no more than six sentences, explain what happens when the following scenario occurs:  (a) a web-site displays an input form, then (b) the user fills out that form and presses a "Submit" button, then (c) the web-site processes the input and sends back a response.  (The "scenario" you are to describe consists of steps (a) through (c) taken together.)

I mean it... in your own words, what t'hell actually happens?  You've got two computers here (the user's, and the web-server), and they are talking to each other.  What do they actually say to each other at each step?  Go find that answer.  (Elsewhere.)  Understand it thoroughly.  Then, come back and reconsider your ColdFusion-specific question.  "The little light-bulb will come on, and when it does, it will stay on."

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