AnotherChance
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Suggest ResponseRight, I have managed to sort this out. The suggest was working all the time. It was displaying as a list below my footer and because my background colour was black I couldn’t see it. Now I need to find out how to style it.
Forum: Fixing WordPress
In reply to: Redirect User Login after checking postsRight, managed to sort this out. I changed my code to,
function redirect_user() { global $wpdb, $user; $check_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_author = $user->ID"); if(!$check_posts) { wp_redirect(site_url('/update-profile/')); } else { wp_redirect(site_url('/summary/')); } exit; } add_filter('login_redirect', 'redirect_user', 10, 3);According to Codex “The $current_user global may not be available at the time this filter is run. So you should use the $user global or the $user parameter passed to this filter.”
Forum: Fixing WordPress
In reply to: Creating URLsThanks, I think I understand that. Will then use: siteurl/profile/$username.
Forum: Fixing WordPress
In reply to: Creating URLsI have read that. The problem is that I am not using the wp_post table. I am using the wp_users and then after that I have custom table that stores profile data. I would like to create a url that is something like this siteurl/username/ and that would store the profile data.
Forum: Fixing WordPress
In reply to: jQuery, Ajax and PHP RequestThanks guys. I have eventually managed to sort this out. The action parameter definitely was the issue.
Forum: Fixing WordPress
In reply to: jQuery, Ajax and PHP RequestRight I have removed all the nice to haves and just left the bit to add data to the table. It appears that my action hooks aren’t working. According to the consol.log() the data is reaching the ajax request and according to the network it is posting the Data to admin-ajax.php and the status of this is 200 OK. The problem must then lie in the functions.php. In the add_action(‘wp_ajax_myAction’, ‘……’ ), what exactly is myAction referring to?
Forum: Fixing WordPress
In reply to: jQuery, Ajax and PHP RequestThanks for the response. I have managed to sort out the url problem but it is still not adding the data to the table. I now have a Uncaught TypeError: document.forms.testForm.submit is not a function in the console.
I have amended the code as follows.
js
jQuery(document).ready(function(){ jQuery('#testForm').submit(submit_testForm); }); function submit_testForm(){ jQuery.ajax({ url: '../wp-admin/admin-ajax.php', type: 'POST', data: $(this).serialize(), dataType: 'json', success: testForm_success }); return false; } function testForm_success(response){ jQuery('#my-hidden-field').val(response.my_hidden_field); document.forms['testForm'].submit(); }php, in the functions.php
function addUser(){ global $wpdb; $name = $_POST['firstName']; $lastname = $_POST['lastName']; $age = $_POST['age']; if(!empty($_POST)){ $wpdb -> insert('tset', array( 'First_Name' => $name, 'Last_Name' => $lastname, 'Age' => $age), array( '%s', '%s', '%d' )); $response = array('my_hidden_field'=> 'this is now filled in'); echo json_encode($response); }; die(); } add_action('wp_ajax_addUser', 'addUser');Forum: Fixing WordPress
In reply to: jQuery, Ajax and PHP RequestJust a quick question. I am using this ajax request to update a custom form. Does it make any difference as to how the scripts are enqueued? also do i reference the .js in the head even though I have enqueued the script?
Forum: Fixing WordPress
In reply to: jQuery, Ajax and PHP RequestThanks, I have done this. When I submit I get a 404 (Not Found) for the admin-ajax.php file. And that is coming from jquery.min.js:4
Forum: Fixing WordPress
In reply to: jQuery, Ajax and PHP RequestHi thanks for this. I have read the documentation and done a few tutorials but for some reason I am getting stuck at the ajaxurl. It keeps giving me, Uncaught ReferenceError: myAjax is not defined.
I am about to pull my hair out.
Forum: Hacks
In reply to: Ajax RequestPlease close this topic, I’m all over the place here. I am going to open a new one.
Forum: Hacks
In reply to: Ajax RequestThe problem I am having is that the data received by Ajax appears not to be supported by the handler. For instance the data received by Ajax is
firstName=NAME&lastName=SURNAME&age=42&myHiddenField=this+is+hidden
This format appears to be incorrect for this request as I tested it at jsonlint.com and when validated it came up with the following.
Error: Parse error on line 1
firstName = NAME &
^
Expecting ‘STRING’, ‘NUMBER’, ‘NULL’, ‘TRUE’, ‘FALSE’, ‘{‘, ‘[‘, got ‘undefined’Please help.
Forum: Hacks
In reply to: Ajax RequestGood afternoon, I would like to update thia question.
Below is the code for my form.<?php /* * Template Name: Confirmation */ ?> <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="<?php bloginfo('stylesheet_directory'); ?>/tset.js"></script> </head> <body> <form method="get" name="testForm" id="testForm" action="https://www.paygate.co.za/paywebv2/process.trans"> <table> <tr> <td><label for="firstName">Name</label></td> <td><input type="text" id="firstName" name="firstName" /></td> </tr> <tr> <td><label for="lastName">Surname</label></td> <td><input type="text" id="lastName" name="lastName" /></td> </tr> <tr> <td><label for="age">Age</label> <td><input type="number" id="age" name="age" min="0" max="100" /></td> </tr> <tr> <td><input type="hidden" name="myHiddenField" id="myHiddenField" value="this is hidden" /></td> </tr> <tr> <td><button name="submit" id="submit">Update</button><td> </tr> </table> </form> </body> </html>here is the code for the php.
global $wpdb; $table = "tset"; $data = array( "First_Name" => $_POST["firstName"], "Last_Name" => $_POST["lastName"], "Age" => $_POST["age"], ); array( "%s", "%s", "%d", ); $wpdb -> insert($table, $data); $response = array("myHiddenField" => "this is now filled in"); echo json_encode($response);and here is the script.
$j = jQuery.noConflict(); $j(document).ready(function(){ $j('#testForm').submit(submit_testForm); }); function submit_testForm() { $j.ajax({ url: "http://localhost/wordpress/wp-content/themes/responsive-mobile-child/tset.php", type: "POST", data: console.log($j('#testForm').serialize()), dataType: 'json', success: testForm_success }); return false; } function testForm_success() { $j("#myHiddenField").val(response.my_hidden_field); document.forms["testForm"].submit();Forum: Fixing WordPress
In reply to: $post_idI finally got this resolved. The following code returned the $post_id of the last post for the logged in user.
$last = wp_get_resent_posts(array( 'numberposts' => '1', 'post_type' => 'post', 'post_status' => 'pending', 'author' => $user_id)); $REFERENCE = $LAST['0']['ID'];Forum: Fixing WordPress
In reply to: $post_idwp_insert_post() is a wordpress function that I use when inserting data into wp_posts table from custom forms. it does work as it redirects to the desired page once the post is created.