Search code examples
phpsimplemodal

Passing a Value from PHP to the SimpleModal Contact Form


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.


Solution

  • 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