• Alright,
    I am new to WordPress so please forgive my ignorance, I am used to hand-coding EVERYTHING My new job is forcing WordPress on me and I am hoping to find it amazing…but with this huge problem is making it hard.

    I have this site which has a form, on submission I want to validate and display error messages and pre-populate the form with the submitted values upon return.

    The issue is that I can not use php…I am completely confused how anyone does this without php.

    Here’s a sample:`
    <form method=”post” action=”formtest.php” onsubmit=”return validateForm()”>
    <p>1. Do you spend at least 10% of your time executing on your written plan to grow your business? <?php echo $error[1]; ?><br/>
    <input type=”radio” value=”1″ name=”q1″ document.write(q[1][2])Always<br/>
    <input type=”radio” value=”2″ name=”q1″ <?php echo $q[1][2]; ?> />Most of the time<br/>
    <input type=”radio” value=”3″ name=”q1″ <?php echo $q[1][3]; ?> />Sometimes<br/>
    <input type=”radio” value=”4″ name=”q1″ <?php echo $q[1][4]; ?> />Not very often<br/>
    <input type=”radio” value=”4″ name=”q1″ <?php echo $q[1][5]; ?> />Never</p>

    <p>2. Do you receive meaningful, accurate, and timely financial reports every month by the 10 <?php echo $error[2]; ?><br/>
    <input type=”radio” value=”1″ name=”q2″ <?php echo $q[2][1]; ?> />Always<br/>
    <input type=”radio” value=”2″ name=”q2″ <?php echo $q[2][2]; ?> />Most of the time<br/>
    <input type=”radio” value=”3″ name=”q2″ <?php echo $q[2][3]; ?> />Sometimes<br/>
    <input type=”radio” value=”4″ name=”q2″ <?php echo $q[2][4]; ?> />Not very often<br/>
    <input type=”radio” value=”4″ name=”q2″ <?php echo $q[2][5]; ?> />Never</p>

    <p>3. Do you receive meaningful, accurate, and timely financial reports every month by the 12 <?php echo $error[3]; ?><br/>
    <input type=”radio” value=”1″ name=”q3″ <?php echo $q[3][1]; ?> />Always<br/>
    <input type=”radio” value=”2″ name=”q3″ <?php echo $q[3][2]; ?> />Most of the time<br/>
    <input type=”radio” value=”3″ name=”q3″ <?php echo $q[3][3]; ?> />Sometimes<br/>
    <input type=”radio” value=”4″ name=”q3″ <?php echo $q[3][4]; ?> />Not very often<br/>
    <input type=”radio” value=”4″ name=”q3″ <?php echo $q[3][5]; ?> />Never</p>

    <p>4. Do you understand those financial reports and consistently use the information they provide to assist you in managing the business and making good decisions? <?php echo $error[4]; ?><br/>
    <input type=”radio” value=”1″ name=”q4″ <?php echo $q[4][1]; ?> />Always<br/>
    <input type=”radio” value=”2″ name=”q4″ <?php echo $q[4][2]; ?> />Most of the time<br/>
    <input type=”radio” value=”3″ name=”q4″ <?php echo $q[4][3]; ?> />Sometimes<br/>
    <input type=”radio” value=”4″ name=”q4″ <?php echo $q[4][4]; ?> />Not very often<br/>
    <input type=”radio” value=”4″ name=”q4″ <?php echo $q[4][5]; ?> />Never</p>

    <p>Your Name (required) <?php echo $error[21]; ?><br />
    <input type=”text” name=”clientName” size=”40″ value=”<?php echo $clientName; ?>” /></p>

    <p>Your Company (required) <?php echo $error[22]; ?><br />
    <input type=”text” name=”clientCompany” size=”40″ value=”<?php echo $clientCompany; ?>” /></p>

    <p>Your Title (required) <?php echo $error[23]; ?><br />
    <input type=”text” name=”clientTitle” size=”40″ value=”<?php echo $clientTitle; ?>” /></p>

    <p>Your Phone (required) <?php echo $error[24]; ?><br />
    <input type=”text” name=”clientPhone” size=”40″ value=”<?php echo $clientPhone; ?>” /></p>

    <p>Your Email (required) <?php echo $error[25]; ?><br />
    <input type=”text” name=”clientEmail” size=”40″ value=”<?php echo $clientEmail; ?>” /></p>

    <p>Comments<br />
    <textarea rows=”10″ cols=”40″ name=”clientComments”>
    <?php echo $clientComments; ?>
    </textarea></p>

    <p><input type=”submit” name=”submit” /></p>
    </form>`

    I have the code that runs in the header in the template file, but how do i output the values from the validation….I’m completely lost as to how this works.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hey TanNerD21,

    First off welcome to WordPress you will find it amazing to use. One of the great powers of WordPress is the community plugins, there are literally millions of them out there.

    It also happens that there are a few that deal with forms and form submission. Have you tried to use any of them? I personally use “Contact Form 7” on several of my websites and find it very useful.

    Don’t be fooled by the name it is much more than just a contact form, its a WordPress form builder. Search for it under the plugin menu.

    Hope this helps.

    Thread Starter TanNerD21

    (@tannerd21)

    Hey Levi,

    Yeah I actually was directed to use that originally from my work. It worked great except that it doesn’t have the ability to require an answer to my radio buttons. So, if the user leaves them blank, the form still submits. And pre-populating them the first time around is not an option for this form.
    That’s why I was going about creating my own, and how I came to this problem.

    Any suggestions from there?

    Have you tried using jQuery to validate your form? Alternatively it looks like you are creating a small survey, have you tried Polldaddy I don’t personal use it but I have seen some great plugins that integrate it unto your website.

    Just a quick thought, if you know how to program another option it build your own community plugin that douse what you need. This might be a little problematic if you are doing it for a company as there may be IP issues.

    Thread Starter TanNerD21

    (@tannerd21)

    I will have javascript validation as well, but I always do php as a backup (in case javascript is turned off).

    I have actually been working on plugins myself for the past…week and a half haha (how long I’ve used wordpress). Will add this to the list of plugins that need to be made, I am trying to build my own library in my off time so that I don’t have to worry about IP issues.

    Thanks for your help, I will check out the polldaddy plugin. I think I found a really crappy workaround for now, so I am gonna implement that and search for a better answer when I have time.

    Another way is to use php form builder for creating and managing forms on your website

    i know this is old, but you can use Contact Form 7’s hook
    wpcf7_before_send_mail to perform additional processing before sending mail, like:

    add_action( 'wpcf7_before_send_mail', 'YOUR_CALLBACK_FN_NAME' );

    then you’d have something like:

    /**
     * pre-processing
     * @param $cf7 reference to contact-form stuff
     */
    function YOUR_CALLBACK_FN_NAME(&$cf7){
       //do something with post data
       $cf7->posted_data ...
    
       //force extra javascript callbacks, stop mail from being sent
       if( /* something failed */):
          $cf7->additional_settings .= "\n".'on_sent_ok: \'if(window.console && console.warn){ console.warn("Failure alert"); }\'';
          $cf7->skip_mail = true;
       endif;
    
       //add stuff to email body
       $cf7->mail['body'] .= 'Custom message etc etc';
    }

    There’s probably a better way to change the success/failure message too. Do a print_r on $cf7 to see what else is available in the callback.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Confused as to how to pre populate forms without php’ is closed to new replies.