0

What is the simplest way to pass a value from the "index" page to the SimpleModal Demo Contact Form? For example, if a user is logged in and their email address is stored in the variable $email, what is the most straightforward way to have that info available in the Demo Contact Form?

Thank you.

skaffman
  • 398,947
  • 96
  • 818
  • 769
RandallK
  • 75
  • 2
  • 5
  • I'd be happy to provide some code...I just you to clarify what you are trying to do a bit more. Also, 'email' is one of the POST values, so you probably want to a different variable name if you are using it for different purposes... – Eric Martin Jul 15 '10 at 19:51
  • Specifically, I want to use the form as 'send this page to a friend'. So values like $page_title or $article_id would be what I'm looking to pass so I can include them in the email that is being sent as either text, or to build a clickable URL in the email. Thanks very much for your support. – RandallK Jul 15 '10 at 19:59

1 Answers1

0

Assuming the values you want are NOT in the form, here's a way to do it.

Update contact.js in the onShow: function:

...
}, function () {
    $('#contact-container .contact-loading').fadeIn(200, function () {

        var pt = PAGE_TITLE,
            aid = ARTILE_ID;

        $.ajax({
            url: 'data/contact.php',
            data: $('#contact-container form').serialize() + '&action=send&page_title=' + pt + '&article_id=' + aid,
            type: 'post',
            cache: false,
            dataType: 'html',
            success: function (data) {
                $('#contact-container .contact-loading').fadeOut(200, function () {
                    $('#contact-container .contact-title').html('Thank you!');
                    msg.html(data).fadeIn(200);
                });
            },
            error: contact.error
        });
    });
});
...

Then update contact.php in the function smcf_send() function

...
// Set and wordwrap message body
$pt = isset($_POST["page_title"]) ? $_POST["page_title"] : "";
$aid = isset($_POST["article_id"]) ? $_POST["article_id"] : "";

$body = "From: $name\n\n";
$body .= "Page Title: $pt\n";
$body .= "Article ID: $aid\n\n";
$body .= "Message: $message";
$body = wordwrap($body, 70);
...

Obviously you can play around with the details, but that should get you going.

-Eric

Eric Martin
  • 2,841
  • 2
  • 23
  • 23
  • Thanks a million, will definitely get me going. – RandallK Jul 15 '10 at 21:17
  • For anyone else who might come along and try this, there is a small typo in the first code. There is a + missing before aid (took me awhile to figure out why it wouldn't work!) But aside from that, it works awesome! Thanks again for making this great code available, and supporting it so quickly. – RandallK Jul 15 '10 at 22:30
  • Sorry about the typo; it is fixed now. – Eric Martin Jul 19 '10 at 13:35