tags:

views:

3314

answers:

4

I have reframed my Question:

I have a drop down box which is populated with a list of users.

 <a href="#" class="Share<?=$r['Form']['id'];?>">Share</a>
    <form action="/FormBuilder/index.php/forms/share/<?=$r['Form']['id']?>/<?=$userid?>" method="post" id="shareform<?=$r['Form']['id'];?>" class="shareform">
            <p>Select the users with whom you want to share the Form</p>
            <select id="userList" name="userList" multiple>
                    <?php foreach($users as $user){  ?>
                            <option value=<?=$user['User']['id'];?>><?=$user['User']['name'];?></option>        
                    <?php }?>
            </select> 
            <input type="submit" class="button" value="Share"/>
    </form>

When I select the user and give submit, the Form's access field in the database is updated to "Shared".

Now I need to display the Form name that has been shared in the home page of the user whom I selected. This is the code for displaying the Form names that have been marked as "shared".

 <?php if (!empty($formsShared)){   
 foreach ($formsShared as $shared): 
  echo $shared['Form']['name']; 
 endforeach; 
 }
 else{
  echo "There are no shared Forms !"; 
 }?>

I need to get the selected values in the drop down box, so that I can have another for loop to display the Shared form only in the selected users home page. How do I get the option:value?

+2  A: 

I don't think this is possible within the page. You need to submit in the form or pass it via an xhr post/get.

Then you could asses it in PHP via the regular parameters.

seth
+2  A: 

Any time you want to get data from JavaScript back into PHP, you are looking at a request+response.

XHR would be the way to go. You obviously aren't obligated to send back anything if all you're doing is receiving information or updating say...session state.

Omega
XHR? Who calls it that?
Mark
+3  A: 

You will want to send them a PHP script using AJAX.

$.post("file.php", { data: selected_value[i] } );

and in your PHP script:

$data = $_POST['data'];

If the drop down is just one part of the form, then you create a hidden form field, with the value as *selected_value[i]*.

+1  A: 

hello everybody

                       You will want to send them a PHP script using AJAX.
                       $.post("file.php", { data: selected_value[i] } );
                       and in your PHP script:
                       $data = $_POST['data'];

with this script, give me a simple example valid.

thank you...

abibol