0

I have searched and tested different solutions all day without luck. In the below code I want (when clicked) to set a session on the "open" links I echo in the foreach loop. I tried using AJAX but I am new to AJAX and could not make it work. I know how to do it using GET but it is too risky, so i welcome your suggestion and preferably examples.

$task_array = array_combine($task_id_unique, $task_status);
                foreach ($task_array as $card_nr => $card_status) { 
                ?>  
                    <table>
                      <tr>
                        <th>card nr.</th>       
                        <th>Status</th>       
                        </tr>
                        <td><?php 
                                        echo $card_nr;?></td>
                        <td>       
                   <?php 
                            if ($card_status == true) {     
                                    echo "<a href=workcard.php>Open</a>";
                            }
                            else echo "Done ". $card_nr;?></td>
                    </table>
3
  • A google search gives you plenty of answers. Commented Jan 12, 2015 at 14:53
  • ... @slime I would never post a question here without doing research on the web. Unfortunately the searches (and testing) did not solve my problem. Commented Jan 12, 2015 at 14:56
  • Why did this question deserve a downvote - please explain? Commented Jan 12, 2015 at 14:57

3 Answers 3

1

What have you tried and what doesn't work, because this looks like what you need...

HTML:

<a href="home.php?a=register">Register Now!</a>

PHP:

if(isset($_GET['a'])){

    $_SESSION['link']= 'whatever';

 }

And if you need to do it without a page refresh, then use AJAX.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, I know how to do it with GET and it works, but due to security reasons I do not want to use GET.
The ajax answers that the others posted will do what you asked; using POST instead of GET.
0

You should use ajax on click of link:

$.ajax({
      url: 'test.php',
      dataType: 'json',
      type: 'post',
      data: {name: "value", name2: "value2" /* ... */},
      success: function (data) {

      }

     });

in your test.php, $_POST['name'] is equal to "value". and there you can do everything you want.

Comments

0

first, add html class on "Open" link and custom html5 attribute to store your card data. for example data-card.

<a href="#" class="your-class" data-card="card_nr_value">Open</a>

next, create Onclick event for a link to send an ajax request.

$( document ).ready(function() {
    $(".your-class").click(function() {
        var card_nr = $(this).attr('data-card');
        $.ajax({
            url: "workcard.php",
            type: "POST",
            data: "card=" + card_nr
        }).done(function() {
            // do something
        });
        return false;
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.