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

1 form with 2 buttons to go to 2 different pages

Engaged ,
Jan 23, 2012 Jan 23, 2012

Hi. I have 1 form I'm using on a page for adding some information. I have an Add button at the bottom that goes to an action page that inserts the data into an Access Database and displays what was inserted. I want to use the same form, but I want to have another button that goes to a different page, but still inserts the data into the database. How do I do this? Below is what I have for the beginning of the form and the button I click on to add it to the database. I won't put all the stuff inside the form so I keep this concise.

<cfform name="AddECNumber" action="add_new_ec_number_action.cfm" method="post">

<input type="button" value="Add" onclick="verify();">

Andy

4.5K
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

Community Expert , Jan 24, 2012 Jan 24, 2012

jamie61880 wrote:

Hi. I have 1 form I'm using on a page for adding some information. I have an Add button at the bottom that goes to an action page that inserts the data into an Access Database and displays what was inserted. I want to use the same form, but I want to have another button that goes to a different page, but still inserts the data into the database. How do I do this? Below is what I have for the beginning of the form and the button I click on to add it to the database. I won't put a

...
Translate
LEGEND ,
Jan 23, 2012 Jan 23, 2012

Instead of two buttons, consider a dropdown or radio buttons.  It will be easier to code and probably clearer to your users.

If you take that route, insert the record and base your display on what option the user chose.

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
Community Beginner ,
Jan 23, 2012 Jan 23, 2012

Normally it would be easier to put all ur codes in one page.

If u do it, then the code would appear as such:

<cfif IsDefined("form.nameofbutton")>

/*

ur coding for add in database here

*/

<cflocation url="http:///"> <!---Here if there is no problem in ur addition in database, this will re-direct ur actual page to another page u mention in the url--->

</cfif>

Like u've said, u want it concise,

then put this code <cflocation> after the addition code.

When u click on the button, this will check for js first, then this will insert into ur database and then redirect u to the page u want.

Hope it helps u to advance.

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
Community Expert ,
Jan 24, 2012 Jan 24, 2012

jamie61880 wrote:

Hi. I have 1 form I'm using on a page for adding some information. I have an Add button at the bottom that goes to an action page that inserts the data into an Access Database and displays what was inserted. I want to use the same form, but I want to have another button that goes to a different page, but still inserts the data into the database. How do I do this? Below is what I have for the beginning of the form and the button I click on to add it to the database. I won't put all the stuff inside the form so I keep this concise.

<cfform name="AddECNumber" action="add_new_ec_number_action.cfm" method="post">

<input type="button" value="Add" onclick="verify();">

<script type="text/javascript">

function verify()

{

   document.myform.action ="add_new_ec_number_action.cfm";

   document.myform.submit();

}

function sendIt()

{

   document.myform.action ="some_other_action_page.cfm";

   document.myform.submit();

}

</script>

<cfform name="myform" method="post">

<cfinput type="text" name="txt"><br>

<cfinput type="button" name="submitBtn" onclick="verify()" value="Add"><br>

<cfinput type="button" name="submitBtn" onclick="sendIt()" value="Insert">

</cfform>

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 ,
Jan 24, 2012 Jan 24, 2012

BKBK,

     Thank you. This works great! I do have one more question though, now. Once the 2nd button is clicked, I would like it to go to an existing page I already have set up. This page is called "add_item_existing_eco.cfm". Normally, to get to this page, the user would have clicked a link to get here. Then this page just adds an item to the ECO.

     But now, I want the page with the form I talked about above to go to this page also, once the form is submitted. So I could add the Inserting code to the "add_item_existing_eco.cfm" page and display the info, but how am I going to prevent the info. from when a link is clicked, to not insert more data.

    I would need an If Statement that says if the "Add new Item Button" was clicked from the Add ECO page, then just insert the data and display the info. Elseif the info. came from a link, then just display the data. How can I say If the "Add new Item Button" was clicked from the Add ECO page? Does this make sense? Or should I just create a new page for when this "Add new Item Button" is clicked?

Andy

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
Community Expert ,
Jan 25, 2012 Jan 25, 2012

jamie61880 wrote:

BKBK,

     Thank you. This works great! I do have one more question though, now. Once the 2nd button is clicked, I would like it to go to an existing page I already have set up. This page is called "add_item_existing_eco.cfm". Normally, to get to this page, the user would have clicked a link to get here. Then this page just adds an item to the ECO.

     But now, I want the page with the form I talked about above to go to this page also, once the form is submitted. So I could add the Inserting code to the "add_item_existing_eco.cfm" page and display the info, but how am I going to prevent the info. from when a link is clicked, to not insert more data.

    I would need an If Statement that says if the "Add new Item Button" was clicked from the Add ECO page, then just insert the data and display the info. Elseif the info. came from a link, then just display the data. How can I say If the "Add new Item Button" was clicked from the Add ECO page? Does this make sense? Or should I just create a new page for when this "Add new Item Button" is clicked?

Yes, the question is clear. There are 2 possible scenarios:

1) From now onwards, an insert will only be done by means of the form button. Coming to the action page by means of a link will no longer lead to an insert.

Form page:

<script type="text/javascript">

function verify()

{

   document.myform.action ="add_new_ec_number_action.cfm";

   document.myform.submit();

}

function sendIt()

{

   document.myform.action ="add_item_existing_eco.cfm";

   document.myform.submit();

}

</script>

<cfform name="myform" method="post">

<cfinput type="text" name="txt"><br>

<cfinput type="button" name="submitBtn" onclick="verify()" value="Add"><br>

<cfinput type="button" name="submitBtn" onclick="sendIt()" value="Insert">

<cfinput type="hidden" name="isUpdated" value="yes">

</cfform>

Page add_item_existing_eco.cfm:

<cfif isDefined("form.isUpdated") and form.isUpdated>

<!--- Insert the data --->       

</cfif>

<!--- Display the info --->

2) An insert can be triggered by the link or by the form-button, which ever arrived first at the page dd_item_existing_eco.cfm.

I do believe the best solution in this scenario is to use the database. Start, for example, by determining which column in the database table can be used to verify that an insert has occurred. A datetime column is ideal for this purpose.

Then add a query, like the following, to verify whether an insert has already occurred in a specific time.

<!--- Number of inserts done in the past 6 hours (Assumption: doneDate registers datetime of each insert) --->

<cfquery name="verifyInsert" datasource="myDSN">

    select count(*) as numberOfInserts

    from myTBL

    where doneDate > #createODBCDatetime(dateAdd("h",-6,now()))#

</cfquery>

<cfif verifyInsert.numberOfInserts EQ 0><!--- No insert has yet occurred --->

<!--- Code to do insert --->

</cfif>

<!--- In all cases, display info --->

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 ,
Feb 01, 2012 Feb 01, 2012

BKBK,

      I finally got all of this working correctly now. Thank you very much. I was just wondering if you could help me with something similar to this? I have a Login Page that goes to a validate.cfm page in order to know if the user exists or not to be able to log them in. Up until now, we've just been logging into one thing called "RFQ LOG". Once you click the login button, it would go to the validate.cfm page and then do a cflocation url to a company search page.

      Now that I have created another database for an "ECO Register", we have 2 different places to log into. I have the login information only pointing to one database table called Users. What I would like is to have 2 different login buttons (RFQ Login and ECO Register Login), that would both go to the validate.cfm page to see if the user exists, and then to do the cflocation to different pages depending on which button the user chose. Why can I not have 2 buttons go to the same validate.cfm page and then go to their respective pages? Here's what I have on the login screen and the validate.cfm pages below. Since I'm doing a hidden field for each button and saying they are both yes, the buttons don't go anywhere.

This is on the login screen:

<SCRIPT LANGUAGE="JavaScript">

function rfqlogin()

{

document.foo.action ="validate.cfm";

document.foo.submit();

}

</script>

<SCRIPT LANGUAGE="JavaScript">

function ecologin()

{

document.foo.action ="validate.cfm";

document.foo.submit();

}

</script>

<cfform name="foo"  method="post">

<cfinput type="button" name="submitBtn" onclick="rfqlogin()" value="RFQ Login"> 

<cfinput type="button" name="submitBtn" onclick="ecologin()" value="ECO Register Login">

<cfinput type="hidden" name="rfqlogin" value="yes">

<cfinput type="hidden" name="ecologin" value="yes">

This is on the validate.cfm page:

<cfif isDefined("form.rfqlogin") and form.rfqlogin>

<cflocation url = "../RFQLOG/company_search.cfm" addToken = "No">

<cfelseif isDefined("form.ecologin") and form.ecologin>

<cflocation url="../ECO_Register/add_new_ec_number.cfm" addtoken="No">

</cfif>

Thanks for your help.

Andy

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
Community Expert ,
Feb 03, 2012 Feb 03, 2012

It is indeed bizarre! I discovered that it works when I change the field names from rfqlogin and ecologin to rfq_login and eco_login, respectively. I have not looked into this, but do suspect it's a bug.

In any case, the following logic isn't watertight:

<cfinput type="hidden" name="rfqlogin" value="yes">

<cfinput type="hidden" name="ecologin" value="yes">

Whichever button is clicked, the value "Yes" will be posted for form.rfqlogin as well as for form.ecologin. My suggestion follows:

<script type="text/javascript">

function rfqlogin()

{

document.foo.rfq_login.value="yes";

document.foo.eco_login.value="no"

document.foo.action ="validate.cfm";

document.foo.submit();

}

function ecologin()

{

document.foo.eco_login.value="yes";

document.foo.rfq_login.value="no";

document.foo.action ="validate.cfm";

document.foo.submit();

}

</script>

 

This is on the login screen:

<cfform name="foo" method="post">

<cfinput type="button" name="submitBtn" onclick="rfqlogin()" value="RFQ Login">

<cfinput type="button" name="submitBtn" onclick="ecologin()" value="ECO Register Login">

<cfinput type="hidden" name="rfq_login">

<cfinput type="hidden" name="eco_login">

</cfform>

validate.cfm page:

<cfif isDefined("form.rfq_login") and form.rfq_login>

<cflocation url = "../RFQLOG/company_search.cfm" addToken = "No">

<cfelseif isDefined("form.eco_login") and form.eco_login>

<cflocation url="../ECO_Register/add_new_ec_number.cfm" addtoken="No">

</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 ,
Feb 03, 2012 Feb 03, 2012

BKBK,

     You are awesome!!!! Thank you very much. This works perfect!

Andy

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
Community Expert ,
Feb 04, 2012 Feb 04, 2012
LATEST

!

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