Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing a plugin which has a front end form that is generated by a shortcode. I'm struggling with processing the form submission in any way. Many tutorials describe placing form processing code at the top of a template file. But as a plugin I don't have a template file.

This is what I have at the moment. The shortcode just calls this function:

function get_testimonial_submission_form () {
?>
<form action="" id="testimonialPostForm" method="POST">

    <fieldset>
        <label for="testimonialclientname"><?php _e('Name:', 'rhl-testimonial') ?></label>
        <input type="text" name="testimonialclientname" id="testimonialclientname" />
    </fieldset>

    <fieldset>
        <input type="hidden" name="submitted" id="submitted" value="true" />
        <button type="submit"><?php _e('Submit Feedback', 'rhl-testimonial') ?></button>
    </fieldset>

</form>

<span class="error">Result is <?php echo $testResult; ?></span>
<div class="clearfix"></div>

<?php
}

And for form processing, I'm using this test code:

function testimonial_submission_form(){
    if($_POST['testimonialclientname'] == ''){
        $testResult = 'Yes';
     } else {
        $testResult = 'No';
    }
}

add_action( 'init', 'testimonial_submission_form' );

Currently after submitting the form, $testResult is empty.

share|improve this question
1  
In both of your functions, $testResult is a local variable, see variable scope in php docs. –  Milo May 16 '13 at 15:46
    
Ah cr... Yeah that was all I needed! If you want, paste that as an answer for the points. –  Cormac May 16 '13 at 18:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.