multiple forms in a single page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    multiple forms in a single page

    hii guys,
    i am working on a site where in guests can say whether the answer / review was useful for them ... there will be many review / answers in a single page .. so how to go on with yes/no for each answer/review ..i have donw ith some code.1st form works .the rest doesnot ..
    Code:
     $sqlreview = "select * from mobile_user_reviews where property1 = '". $brand ."' and property2 = '". $model ."' ";
                    $resultreview = mysql_query($sqlreview);
                    if(mysql_num_rows($resultreview) > 0)
                    {
    
                            $myresult .= "<b>Reviews</b>";
                            $myresult .= "<ul>";
                        
                    while($row = mysql_fetch_array($resultreview))
                    {
                            $myresult .= "<form name='useful' method = 'POST' action ='" .$_SERVER['PHP_SELF'] ."'>";
                            $helpful = gettotalhelp ($row['id']);
                            $helpfulcount = gettotalhelpcount ($row['id']);
                            $myresult .= "<input type='hidden' name='model' value='".$model."'>";
                            $myresult .= "<input type='hidden' name='brand' value='".$brand."'>";
                            $myresult .= "<li>";
                            $myresult .= "$helpfulcount of $helpful people found the following review helpful:<br/> ";
                            $myresult .= getuserrealname($row['userid']).' : '.$row['review'] .' , '.date("dS, F, Y h:i a",$row['reviewedon']);
                            $myresult .= "<br/>";
                            $myresult .= "&nbsp; Was this review helpful to you? &nbsp; <input type ='radio' id='Yes' name='Yes' value='Yes'> YES
                                            &nbsp; <input type ='radio' id='No' name='No' value='No'>NO&nbsp;<input type='submit' name='submit' value='submit'>";
                            $myresult .= "</li>";
                            $myresult .= "<br/>";
                            $myresult .= "</form>";
                    }
                            $myresult .= "</ul>";

    if the code is not worth working on !!plzz tell me a way to work on it ...
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    When you say the first form works, do you mean you get only one form printed? If that's the case I suspect something is funny with your MySQL query. Check that out without all the form stuff to make sure that $resultreview is what you expect. Just echo the mysql_num_rows( $resultreview) and make sure it's more than one.

    I think I understand your logic of why you are making a massive variable, but I think that a better way would be to make a function. If you made a function like:
    Code:
    function display_forms() {
    echo "[indent]<form name='useful' method='post'...[/indent]
    "; }
    And then when you want to display your list:
    Code:
    ...
    <?php display_forms(); ?>
    ...

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      the result from the mysql is getting printed properly bcos i print the reviews of the user for guests to read . when i click on 2nd submit the url is without the url variables passed .

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        I'm not sure i understand. Your form's method is post, so what URL variables are you talking about? It should be get if you plan to be sending the form through the URL?

        Regardless, another problem is your form name. It is the same for each form, so you end up with a whole lot of forms called the same name on your page and you lose the point of naming them.

        You hidden values are also $model and $brand. They will not change and will be the same for each form. If you want them to change, I think they should be $row['model'] and $row['brand'].

        Not sure if those will solve your problem, but get back to me on them and I'll have a deeper look if you still have a problem.

        Comment

        • pradeepjain
          Contributor
          • Jul 2007
          • 563

          #5
          brand and model remain the same always ..its the review that change in each form .

          what i meant by url is that .when i land on the review page its url is like

          .xyz is for every website, everywhere.® We offer the most flexible and affordable domain names to create choice for the next generation of internet users.

          when i click on submit of 1st form it still remains in same page url .

          but when i click on 2nd form submit the url gets changed to
          http://xyz.com/rating1/read_reviews.php i dono y!!:(

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            Again, because your method is post you will not submit variables in the URL. Try changing your form method to "get".

            *And if your landing URL has $_GET variables, you will need to resubmit them in the form, which might be your $brand and $model variables, but as long as you have defined them previously like:
            Code:
            $brand = $_GET['brand'];
            $model = $_GET['model'];

            Comment

            • pradeepjain
              Contributor
              • Jul 2007
              • 563

              #7
              i tried GET method .. and gave incremental names to forms . then also nothing is happening on click of 2nd form submit .

              on submit i am giving like ...

              print_r($_POST)
              and also
              print_r($_GET)

              but only on 1st form submit the value is getting printed .. but on 2nd form submit nothing is getting printed .

              Is there any way of doing this ...say using jquery/ajax ....without page refresh ....

              Comment

              • pradeepjain
                Contributor
                • Jul 2007
                • 563

                #8
                hey the form is working fine now !!!! how do i connect the form submit to jquery ..

                Comment

                • TheServant
                  Recognized Expert Top Contributor
                  • Feb 2008
                  • 1168

                  #9
                  Tonnes of google articles. Glad you have it working. How did you fix your original problem?

                  Comment

                  Working...