SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist WebMachine's Avatar
    Join Date
    Jun 2007
    Location
    Ontario, Canada
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php, jquery and forms

    I have a multi-part form that give the user the choice of two options for a section of step 2 using form buttons. The option chosen is revealed using jquery. I am trying to pick up on the choice of option using php (and ultimately store it in my database) but it is not picking up the button value at all.

    My variables are carried from step to step using sessions with the following code:
    PHP Code:
    // process the $_POST variables and save them in the $_SESSION array  
    foreach ($_POST as $key => $value) {
        
    // assign to temporary variable and strip whitespace if not an array
        
    $temp is_array($value) ? $value trim($value);
        
    // assign to a variable of the same name as $key
        
    $_SESSION[$key] = $temp;
    }
    ?> 
    I have no issues picking up the values of the other form elements.

    The jquery I used is
    Code:
    // script used to hide or show the form for option one
    	$(document).ready(function() {
    		$('.optionOneForm').hide();
    		$('<input type="button" name="ad_option" class="revealer" value="Choose Option 1" />')
    		.insertBefore('.optionOneForm');
    		$('.revealer').click(function(){
    			$('.revealer').hide("medium", "swing");
    			$('.options').hide("medium", "swing");
    			$(this).next().fadeIn("slow", "swing");
    		});
    		$('.return').click(function() {
    			$('.optionOneForm').hide();
    			$('.revealer').show("medium", "swing");
    			$('.options').show("medium", "swing");
    		});
    	});
    With minor changes, this is the same code I used for option 2. (In this post I keep getting a button instead of the actual code for the button ... ??)
    Can anyone see why I can't get the value of my 'ad_option' ?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You are not showing all the code involved so we have to guess.

    My guess #1 is you are using JS to submit the form through jQuery and the form value is not being picked up because while you assign a name=ad_option there is no corresponding id=ad_option so JQuery is not able to find it.

    Just give the form a straight forward submit button, disable the JS and get the form working so you know for sure the HTML form element data is being passed to PHP in exactly the format you want, then, progressively add JS to do the fancy show/hiding.

  3. #3
    SitePoint Evangelist WebMachine's Avatar
    Join Date
    Jun 2007
    Location
    Ontario, Canada
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I was so late responding ... a weekend got in the way. I can't give you all the code, but I will try what you suggested. Thank you.


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
  •