Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Location
    Orlando, FL
    Posts
    159
    Thanks
    4
    Thanked 8 Times in 8 Posts

    Form Issue with a <button>

    I am having a problem with a form on my site. There are two (2) buttons: 1 submit button and 1 <button>. The submit button submits the entire form to a function for error checking. The <button> button is used to pull the information from a field, put it into an array, and then display that array in a field below the <button> button.
    I tried putting a form into the form and making the <button> button a second submit button, thinking when that submit button is hit, it would just do the action I told it to do. However, it submitted the whole form. I need the <button> button to pull the information from a field from the form and display it in the same form.
    I do no want to use javascript right now because since some people can't/don't have javascript enabled, I want to make it work in PHP first. Is there a way to make what I want to work, work?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What you want to do requires Javascript. There's no way around that. PHP cannot do it alone; once PHP is done parsing the script and generates the HTML for the page, and sends the HTML off to the client's browser, it's done and can't do anything more. At that point, it's all up to the client browser (and thus, Javascript) to do any further manipulation to the HTML, DOM, or form values. The page must be reloaded otherwise.

    One way to bypass a reload is to use AJAX, but AJAX is Javascript so that wouldn't fulfill your requirements to not use Javascript.

  • #3
    Regular Coder
    Join Date
    Mar 2010
    Location
    Orlando, FL
    Posts
    159
    Thanks
    4
    Thanked 8 Times in 8 Posts
    The thing is, I plan to implement javascript later. But for the folks who don't have javascript enabled, I need to give them an alternative method. I understand that the page will need to refresh for the script to work. I was just wondering if there was a way to use POST with a <button> command. Would it have to be a SESSION variable?

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Uh... you don't use POST with a form object... you use it with a form. So sure, you can use POST with a form that uses a button. But I don't think that's what you meant to ask. So you don't mind refreshing? You'll pull the details on the current form, use them to get other information, then want all that to display back on the form?

  • #5
    Regular Coder
    Join Date
    Mar 2010
    Location
    Orlando, FL
    Posts
    159
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Correct. The only reason I am doing this in PHP is for the people who don't/can't have javascript enabled. I understand the only way to do this is to have the page refresh. I want a button to pull the information from a text box and display it on the form, beneath the text box from whence it was pulled.
    But the issue comes from the fact I already have a submit button for the form, so having two submit buttons won't work. I tried.
    What I'm attempting to do is allow the user to input a list of ingredients for a recipe form. I want the ingredients to be displayed below the text box whenever the user hits the 'ADD' button. But the 'ADD' button shouldn't submit the entire form, just what's in the ingredient text box. Once the user has listed all the ingredients for the recipe, then they submit the form via the submit button.

  • #6
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    I am also interested in this type of technique.

    Keleth, when I was talking about my cascading menus, if I remember correctly you were telling me that submitting the form 3 times was not really viable. The same thing is happening here with this OP.

    I can relate to this to the way facebook inserts information into their databases when you post a status update. The window section of page expands and makes room for the new post, data is inserted in the database, but the page does not reload. And as far as I know, PHP is used by facebook for the majority of their scripting.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    wojo: two submit buttons do work, as long as they have different names.

    What you should do IMO, is give the final submit button a name like final_submit, and the one to pull the details as detail_submit. In your PHP, have an if that tests if 'details_submit' is set, if it is, pull the details, store the form data into a session, and then go back a page, with something like a get variable set or a session variable that holds the state. If that particular variable is set, go ahead and print out the form data along with the newly pulled details. If 'final_submit' is set, instead proceed with the form. Thats the best way I think. The individual button names are of course, up to you.

    ajetrumpet, I didn't mention anything about 3 pulls being not viable. If you're avoiding javascript, its how it has to be done, and I see no problem with that.

    That being said, don't be afraid of Javascript I say. I've been avoiding JS like crazy on a few sites, and when I actually did an analysis of my visitors, I found a majority of them supported Javascript. So you're dead right to have PHP backup code for those who don't, but don't be afraid of Javascript because of those who can't support it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •