Forums

[resolved] HOOKS; not quite sure what to hook on to ? (6 posts)

  1. linxlad
    Member
    Posted 1 year ago #

    Hey

    So I am currently developing my first wordpress Plugin and i am stumped.

    i need to insert some form data posted from the about page to a custom hanlderform.php in my plugins folder. It won't run the function that actually inserts the data into the table. i assume this is because i am running it outside the WordPress framework. So my question is this how do I get it inside the framework of WordPress what do I hook onto with my add_action() function?

    Thanks guys

    Nathan

    At current i either have no error and it does nothing or if i try adding an add_action() function it states it is undifined.

    handlerform.php
    [code]

    <?php
    
    // values sent from form
    $contestname=$_POST['contestname'];
    $emailaddr=$_POST['emailaddr'];
    $floa=$_POST['floa'];
    $postcode=$_POST['postalcode'];
    $courseone=$_POST['coi1'];
    $coursetwo=$_POST['coi2'];
    
    	//validate form data
    	if ($contestname == "") {
    		echo "You have not entered your Name!";
    		}
    	elseif ($emailaddr == "") {
    		echo "You have not entered an Email Address!";
    		}
    	elseif ($floa == "") {
    		echo "You have not entered your First line of address!";
    		}
    	elseif ($postcode == "") {
    		echo "You have not entered your Postal Code!";
    		}
    	else
    	{
    	//eccho form data  (FOR TESTING)
    	 echo "$contestname<br />";
    	 echo "$emailaddr<br />";
    	 echo "$floa<br />";
    	 echo "$postcode<br />";
    	 echo "$courseone<br />";
    	 echo "$coursetwo<br /><br />";
    	}
    
    	//store form data into an array
    	$form_details = array("$contestname", "$emailaddr", "$floa", "$postcode", "$courseone", "$coursetwo");
    
    	//print array (FOR TESTING)
    	print_r($form_details);  
    
    	function insert_data() {
    
    	global $wpdb;
    
    	echo 'Hello 1';//testing
    
    	/*$wpdb->insert( '$table_name', array( 'column1' => 'value1', 'column2' => 123 ), array( '%s', '%d' ) )*/
    
    	$table_name = $wpdb->prefix . "data_captcha";
    
    	$wpdb->query( $wpdb->prepare( "
    	INSERT INTO wp_data_captcha
    	( name, email, floa, postcode, course1, course2 )
    	VALUES ( %s, %s, %s, %s, %s, %s )",
    	$contestname, $emailaddr, $floa, $postcode, $courseone, $coursetwo ) );
    
    	echo 'Hello 2';//testing
    
    	$wpdb->show_errors();
    	$wpdb->hide_errors();
    
    	}
    
    ?>

    [/code]

  2. linxlad
    Member
    Posted 1 year ago #

    By the way I am running 3.0.

  3. linxlad
    Member
    Posted 1 year ago #

    BUMP am really stuck :/

  4. linxlad
    Member
    Posted 1 year ago #

    BUMP

  5. prasad.nevase
    Member
    Posted 1 year ago #

    Hey,

    What i will suggest is rather than diving into plugin development you should better use WordPress's hooks from its hooks liabrary, e.g. wp_head() hook.
    You will find this in the <head></head> section of your themes header.php file. Now you must be having question in your mind that what does it do there?
    And the answer is: WordPress core checks whether there is any function hooked to this hook and executes the function at page load time. The one that I mentioned i.e. wp_head() is used to enque the scripts which goes in <head></head> section.
    Well this was the first step to know what does hooks do and used for in wordpress. But there are the scenarios where we may have to define custom hooks.

    Now talking about the problem you have mentioned I can give two suggestions...
    1) You can simply give 'handlerform.php' name in action attribute of your form and the rest of the code will execute if it is correct.
    2) Or if the need is such that this code needs to be hooked then,
    Go through this link and you will get idea about custom hooks.
    http://digwp.com/2009/09/wordpress-action-hooks/

  6. linxlad
    Member
    Posted 1 year ago #

    Thanks :) You have been most helpful I will check out these suggestions :)

Topic Closed

This topic has been closed to new replies.

About this Topic