WordPress.org

Forums

I have a page with an HTML form. How do I process it with PHP? (11 posts)

  1. dstars5
    Member
    Posted 1 year ago #

    Hey guys,

    So I have a page setup on my site to input some information. Now, the general way I know to do this is to process it on the same page or a different page with PHP. But as far as I can tell, PHP isn't supported by wordpress?

    I need the form information to be emailed to me when it is submitted. Is there a way to use PHP? Or is there a way to process and send the information without PHP?

    Thanks!

  2. graphical_force
    Member
    Posted 1 year ago #

    WordPress is built using php. This can help you with how themes are put together. http://codex.wordpress.org/Theme_Development

  3. dstars5
    Member
    Posted 1 year ago #

    Sorry, I am very new to wordpress. Are you saying I can create a php file as a part of the theme, then use that to process the info?

  4. graphical_force
    Member
    Posted 1 year ago #

    What I am saying is that WordPress uses themes which is referenced in the link that I sent already. Where ever you want your form which you want built using php, you can use in the theme since the theme is built in php.

  5. djmorigeau
    Member
    Posted 1 year ago #

    Yes, that is correct. You could build a PHP file to process your form fields and call the PHP file from your form from within WordPress.

    Example:

    <form name="wpform" action="formprocessor.php" method="get">
    Username: <input type="text" name="user">
    <input type="submit" value="Submit">
    </form>

    in the example above formprocessor.php could be placed in your WordPress theme files and then called from the form that you have built into your page.

    Or you could use a plugin to build your form such as Ninja Forms (http://ninjaforms.com/). There are many other form building plugins for WordPress if you search for them, if you choose not to build your own.

  6. dstars5
    Member
    Posted 1 year ago #

    I can't find anything on actually creating forms with any of the plugins, so I figured this would be easier. Thank you for the help!

  7. WPyogi
    Forum Moderator
    Posted 1 year ago #

    Try Contact Form 7 - there's tons of helpful info on how to use it:

    http://contactform7.com/docs/

  8. vinsprinter
    Member
    Posted 1 year ago #

    Hi Everybody, Happy New Year and all that!

    I am having the same problem in WordPress. Here is my form code. The form is just one <div> from the home page. The file is saved as .php

    <div class="form">

    <form name="newsletterform" method="post" action="process.php">
    <table>
    <tr>
    <td><label name="name">Name:</label></td>
    <td><input type="text" name="name" maxlength="45" maxsize="30" /></td>
    </tr>
    <tr>
    <td><label for email="email" id="email" name="email">Email*:</label></td>
    <td><input type="text" name="email" maxlength = "45" maxsize="30" /></td>
    </tr>
    <tr>
    <td><input type="reset" name="reset" value="Reset" /></td>
    <td><input type="submit" name="submit" value="Submit" /></td>
    </tr>
    </table>

    </form>

    </div><!-- form div ends here --> `

    This file is saved to my theme Twentythirteen folder. I have also created a process.php file and saved that there also. Problem is that I am getting this error when I submit the form. Here is the process.php page.

    <?php /* Template Name: process.php */ ?>

    <?php 
    
    if(isset($_POST['submit'])) {
    
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    
    	$server = mysqli_connect('localhost', 'root', '', 'saint_stanislaus') or die("The Server Cannot Be Reached at this Time!");
    	//$dbc = mysqli_select_db($server, 'newsletter') or die("There is a problem accessing the databse!");
    
    	$query = mysqli_query($server, "INSERT INTO subscribers (name, email) VALUES('$name','$email')");
    
    	$name = strip_tags($name);
    	$email = strip_tags($email);
    
    	if(empty($name) || empty($email)) {
    
    			echo "All Fields Must Be Filled In!";
    
    		} else {
    
    			echo "You have been successfully subscribed";
    
    			}
    
    }
    
    mysqli_close($server);
    
    ?>

    I have created a page in my admin area called process and instead of using the default I use the template page /*Template Name: process.php*/

    But all I get is this error.

    Not Found

    The requested URL /saint_stanislaus/process.php was not found on this server.

    Any Suggestions?

  9. Evan Herman
    Member
    Posted 1 year ago #

    Hi vinsprinter,

    I would start your own help thread, and possibly even post it in Wp-Advanced section.

    Evan

  10. malcoreilly
    Member
    Posted 1 year ago #

    I know this thread is a little old, but I think its the same question that I have. If I want to stick with my own HTML form (actually a WP page), then i think I need a php form handler script, to send submissions to email. Do I upload that php script to the WP theme folder? Where exactly? My child theme?

    Secondly, am I right that if I code in HTML5, I might not need to do as much form validation through the PHP script?

    thanks for your help!
    malc

  11. ajasra
    Member
    Posted 11 months ago #

    @vinsprinter,
    where are you keeping the process.php file ?
    if you have your process.php in the custom theme directory under wp-content>themes...then you got add a little wp function preceding process.php in the first line of the form.

    `<div class="form">

    <form name="newsletterform" method="post" action="<?php echo get_template_directory_uri(); ?>/process.php">
    <table>
    <tr>
    <td><label name="name">Name:</label></td>
    <td><input type="text" name="name" maxlength="45" maxsize="30" /></td>
    </tr>
    <tr>
    <td><label for email="email" id="email" name="email">Email*:</label></td>
    <td><input type="text" name="email" maxlength = "45" maxsize="30" /></td>
    </tr>
    <tr>
    <td><input type="reset" name="reset" value="Reset" /></td>
    <td><input type="submit" name="submit" value="Submit" /></td>
    </tr>
    </table>

    </form>

    </div><!-- form div ends here --> `

    this should do the trick if you have the file in your theme directory, which i guess is true..

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags