0

Seasoned dev, but new to wordpress development - becoming a fan very quickly.

I'm knocking up my first wordpress plugin (custom contact form for client, none of the plugins can do the jazz I need).

I can't work out how to submit the form and grab the data. Heres what I've got so far:

function cafesignup_function() {

    $x = parse_url($_SERVER['HTTP_REFERER']);
    $pageRef = basename($x['path']);

    if(isset($_POST['submit']))
    {
        $name = $_POST['companyName'];
        $demolp_output = $name;

    } else {


    $greeetingText = "<h1>" . getTitle($pageRef) . " Quote Form</h1>";

    $demolp_output = "<div class='mtool ccupform'></div> <div class='greeting-text'><p>" . $greeetingText . "</p></div><div class='maintext'> <div class='errortext'> </div><small>Fields with a * are required fields.</small>";
    $demolp_output .= "<form name='quoteForm' id='quoteForm' method='post' action='/request-a-quote' >";
    $demolp_output .= "<p>Contact Name*<br />";
    $demolp_output .= "<input type='text' class='validate bjp-contact' name='companyName' id='cafeCompanyName' value='' size='40' class=''></p>";

    $demolp_output .= "<p>Business name if Applicable<br />";
    $demolp_output .= "<input type='text' class='validate bjp-contact' id='cafeFirstname' value='' size='40' class=''></p>";

    $demolp_output .= "<p>Telephone including STD*<br />";
    $demolp_output .= "<input type='text' class='validate bjp-contact' id='cafeSurname' value='' size='40' class=''></p>";

    $demolp_output .= "<p>Email Address*<br />";
    $demolp_output .= "<input type='text' class='validate vemail bjp-contact' id='cafeEmailAddress' value='' size='40' class=''></p>";

    $demolp_output .= "<p> <div class='pull-right'><span onclick='clear();' id='cafeAdd2' class='btnN'>Clear</span> &NonBreakingSpace;<span onclick='addUser();' id='cafeAdd2' class='btnY'>Submit</span></center></p>";

    $demolp_output .= "</div>";

    $demolp_output .= "</form>";

    }

    return $demolp_output;
}

When I submit that (using jquery for the submit, as below) it fires the submit, but it shows the fro again (also I can't work out what to put as the action on the form to reuse the plugin elsewhere).

function addUser(){
    var emailvalidates = true;
jQuery( ".validate" ).each(function() {
    if(jQuery(this).val() == ""){
        validates = false;
        alert("missing fields");
    } else {
        $('#quoteForm').submit();
    }
});

}
0

var_dump() your $_POST, there will never be a ['submit']. You don't have something like:

<input name="submit" type="submit" />

That is basic HTML ;)

And read more about MVC and putting your HTML-Code in another file. Putting them in strings is something you won't like in the future! It becomes unreadable and unmaintainable some day.

  • I'm doing the submit through javascript. It's a one job script, theres no reason for me to breakout the markup. – TMB87 Oct 10 '14 at 10:37
  • Okay. Let me do it for you: ob_start(); require 'cafesignup_function.phtml'; $demolp_output = ob_get_clean(); Cheers! – LeMike Oct 10 '14 at 11:10
0

I think this article can help you make a page settings in Wordpress:

http://code.tutsplus.com/tutorials/create-a-settings-page-for-your-wordpress-theme--wp-20091

Hope that helps.

  • Not particularly...as I'm not looking to create a wordpress settings page. I'm trying to catch the submit of a form.. – TMB87 Oct 10 '14 at 10:40
  • Yeah, there is a good topic about create form in admin page and I thought it can help you. Anyway, did you try to use hook 'admin_init' ? I think this way can get data that form submitted: add_action( 'admin_init', 'cafesignup_function' ); – taido Oct 10 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.