SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast dfysh's Avatar
    Join Date
    Jun 2004
    Location
    Maple Ridge,BC,CANADA
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Submitting a for with no submit button

    Good Day All,

    I looked through the posts, but could not find anything that fit with the situation I am fighting with right now.

    I have a page which is dynamically created. In a portion of the page which is created dynamically, I have a form with two groups of radio buttons (2 per group).

    The form is designed to allow a user to approve something (billing sheet in this case). The approver clicks on a user name (in the form) and views some info. The approver than returns to the approval page and either approves or disapproves the info using the radio buttons (there are two seperate approvers, hence two groups of buttons).

    What I want to do is update a MySQL database table based on the radio button that was selected (approve) or send an email to a user (disapprove). The form is setup to post but I can not figure out how to get the info submitted.

    I thought the easiest way was to use the onClick event for the radio buttons but how do I trigger a page refresh and get the PHP running to either update a DB table or send an email?

    Any thoughts that anyone has would be much appreciated.

    When you have a moment...

    Best Regards

    Darcy

  2. #2
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <form action="continue.php" method="post">
      <input type="radio" name="myField" value="db" onclick="if (this.checked) { this.form.submit(); }"> DB<br>
      <input type="radio" name="myField" value="email" onclick="if (this.checked) { this.form.submit(); }"> E-mail<br>
    </form>
    PHP Code:
    switch ($_POST["myField"]) {
      case 
    "db":
        
    // do something..
      
    case "email":
        
    // mail..
      
    default:
        
    // field not set or it's empty


  3. #3
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must note however that having form submission attached to a radio button's event will not let the customer review his decision, which in my opinion is bad practice. Having a submit button on a visible form is a good idea.

    Sorccu's idea is good but make sure the browser has js enabled or it won't work.

  4. #4
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't you just make a hidden submit button (hide it using CSS) and then the enter button should work?

    Edit: Errr, yeah, ignore me, radio buttons.. cough.

  5. #5
    SitePoint Enthusiast dfysh's Avatar
    Join Date
    Jun 2004
    Location
    Maple Ridge,BC,CANADA
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BigDuke & Sorccu,

    Thank You for the input. I decided to do the approval a bit differently based on BigDuke's comments, however I have another iteresting situation which I have not been able to resolve yet and is similar to what I want to do with radio buttons...

    I see this all of the time: select from a drop down and the item selected from dropdown1 determines the contents of dropdown2. I have two drop downs on a form. The form captures client information, two pieces of which are a Fee Payor and Fee Payor Contact. The FP and FPC are in two seperate drop downs. In the FP dropdown, I have the Fee Payors which have one or more Contacts associated with them. If the user selects FP1 than the contents of dropdown2 should be FPC1A, FPC1B, FPC1C, and so on.

    The problem I am having is one of refreshing the page after dropdown1 is selected (changed). I have attempted several different solutions which I have found on the forums, but none of them seem to produce the desired results; namely no JavaScript more than Sorccu's solution.

    Would the solution proposed by Sorccu work in this situation? Looking at the code it seems that it would but I am still pretty new to PHP so I want to be sure before I spend too much time on it. I think I have spent about 10 hours on this problem (off and on) with nothing to show for it.

    Based on Sorccu's solution I would presume that I would change the onClick event to onChange and submit the form with the contents on the first dropdown. From there it should be a simple matter of just using that value to query that DB to get the related FPC and than populate the second dropdown.

    I am interested on how this might be done exclusively with PHP in the event that there is a browser that does not have JS enabled.

    If you, or anyone else, has any other insight into this problem that would be very helpful as well.

    Best Regards

    Darcy

  6. #6
    SitePoint Member Siddhartha's Avatar
    Join Date
    Mar 2004
    Location
    Bulgaria
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with bigduke and I strongly recommend to escape any automatic submition of forms!
    This makes the user very confused. And doesnt allow him to correct mistaken choices!

    Anyway
    for the "NOJS" problem i propose you to add in the form section:
    HTML Code:
    <form action="continue.php" method="post">
    ...
    <noscript><input type="submit" name="ok" value="Change"></noscript>
    </form>
    the submit button will appear only when js is disabled in the browser.

    Tip: never name your input controls "submit" - it will overwrite the javascript submit() method of the form!
    I am interested on how this might be done exclusively with PHP in the event that there is a browser that does not have JS enabled.
    i cant understand how you want php knows what does the user with the page he views?!
    CSS

  7. #7
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am interested on how this might be done exclusively with PHP in the event that there is a browser that does not have JS enabled.
    PHP being a server side script, any processing requires a separate request to the server as a result the page just has to be refreshed to update the content if any changes were to take place.
    But yes updation of one select box upon selection of another can be handled using php.


Bookmarks

Posting Permissions

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