Jump to content

LazyDragon

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by LazyDragon

  1. dsonesuk is BIG. The best member on whole forum! Thank You very much again my friend for speding time to help me solve my problem! :)

  2. Oh my dear friend I get user_ID result in mail!!! Thank u very much!!!One more thing is my step form is not getting after submit to redirection and idk whyI mean the line in jQuery handler: window.location.href = "www.redirectionplace.com"; it should be executed edit:Sorry it was just code freeze!THANK YOU ONCE AGAIN! YOU ARE BIG
  3. I have enqueued js steps and validation libraries, js handler and php handler. So my (simplified) custom form page looks pretty much like: <form id="example-form" action="#"> <div> <h3>Verification</h3> <section> <p>Please upload following documents:</p> <div id="dynamicInput" style="float: left; padding: 0px; margin: 0px;"> <label for="idpass">Scan or photo of your ID or passport</label> <input type="file" name="idpass" id="idpass" class="required" style="width:250px;" /> </div> <div style="clear:both;"> <label for="adrprf">Proof of Adress</label> <input type="file" name="adrprf" id="adrprf" class="required" style="width:250px;" /> </div> </section>...etc My jQuery handler jQuery(function ($) {var form = $("#example-form");form.validate({ errorPlacement: function errorPlacement(error, element) { element.before(error); }, rules: { confirm: { equalTo: "#password" } }});$("input[name='idpass']").each(function () { $(this).rules('add', { required: true, accept: "image/jpeg, image/pjpeg, image/png, image/bmp" })});$("input[name='idpass2']").each(function () { $(this).rules('add', { accept: "image/jpeg, image/pjpeg, image/png, image/bmp" })});$("input[name='adrprf']").each(function () { $(this).rules('add', { required: true, accept: "image/jpeg, image/pjpeg, image/png, image/bmp" })});form.children("div").steps({ headerTag: "h3", bodyTag: "section", transitionEffect: "slideLeft", onStepChanging: function (event, currentIndex, newIndex) { form.validate().settings.ignore = ":disabled,:hidden"; return form.valid(); }, onFinishing: function (event, currentIndex) { form.validate().settings.ignore = ":disabled"; return form.valid(); }, onFinished: function (event, currentIndex) { var proceed = true; var m_data = new FormData(); m_data.append( 'idpass', $('input[name=idpass]')[0].files[0]); m_data.append( 'adrprf', $('input[name=adrprf]')[0].files[0]); m_data.append( 'fb', $('input[name=fb]').val()); if ($("#idpass2").val()) { m_data.append( 'idpass2', $('input[name=idpass2]')[0].files[0]); }; $.ajax({ url: '../wp-content/themes/x/anewpartner.php', data: m_data, processData: false, contentType: false, type: 'POST', dataType:'json', success: function(response){ //load json data from server and output message if(response.type == 'error'){ output = '<div class="error">'+response.text+'</div>'; }else{ window.location.href = "www.redirectionplace.com"; } $("#example-form #contact_results").hide().html(output).slideDown(); } }); }});}); and PHP <?php if($_POST){ $to_email = "email@email.com"; $from_email = "email@email.com"; //check if its an ajax request, exit if not if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { $output = json_encode(array( //create JSON data 'type'=>'error', 'text' => 'Sorry Request must be Ajax POST' )); die($output); //exit script outputting json data } //Sanitize input data using PHP filter_var(). $fb = filter_var($_POST["fb"], FILTER_SANITIZE_STRING); $id = filter_var($_POST["id"], FILTER_SANITIZE_STRING); $subject = "Subject"; //additional php validation if(strlen($fb)<1){ // If length is less than 4 it will output JSON error. $output = json_encode(array('type'=>'error', 'text' => 'Add facebook profile')); die($output); } else { //email body $message_body = "Facebook: ".$fb."n UserID: ".$id; ### Attachment Preparation ### $file_attached = false; $file2_attached = false; $file3_attached = false; if(isset($_FILES['idpass'])) //check uploaded file { //get file details we need $file_tmp_name = $_FILES['idpass']['tmp_name']; $file_name = $_FILES['idpass']['name']; $file_size = $_FILES['idpass']['size']; $file_type = $_FILES['idpass']['type']; $file_error = $_FILES['idpass']['error']; //exit script and output error if we encounter any if($file_error>0) { $mymsg = array( 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder" ); $output = json_encode(array('type'=>'error', 'text' => $mymsg[$file_error])); die($output); } //read from the uploaded file & base64_encode content for the mail $handle = fopen($file_tmp_name, "r"); $content = fread($handle, $file_size); fclose($handle); $encoded_content = chunk_split(base64_encode($content)); //now we know we have the file for attachment, set $file_attached to true $file_attached = true; } if(isset($_FILES['adrprf'])) //check uploaded file { //get file details we need $file2_tmp_name = $_FILES['adrprf']['tmp_name']; $file2_name = $_FILES['adrprf']['name']; $file2_size = $_FILES['adrprf']['size']; $file2_type = $_FILES['adrprf']['type']; $file_error = $_FILES['adrprf']['error']; //exit script and output error if we encounter any if($file_error>0) { $mymsg = array( 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder" ); $output = json_encode(array('type'=>'error', 'text' => $mymsg[$file_error])); die($output); } //read from the uploaded file & base64_encode content for the mail $handle = fopen($file2_tmp_name, "r"); $content = fread($handle, $file2_size); fclose($handle); $encoded_content2 = chunk_split(base64_encode($content)); //now we know we have the file for attachment, set $file_attached to true $file2_attached = true; } if(isset($_FILES['idpass2'])) //check uploaded file { //get file details we need $file3_tmp_name = $_FILES['idpass2']['tmp_name']; $file3_name = $_FILES['idpass2']['name']; $file3_size = $_FILES['idpass2']['size']; $file3_type = $_FILES['idpass2']['type']; $file_error = $_FILES['idpass2']['error']; //exit script and output error if we encounter any if($file_error>0) { $mymsg = array( 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder" ); $output = json_encode(array('type'=>'error', 'text' => $mymsg[$file_error])); die($output); } //read from the uploaded file & base64_encode content for the mail $handle = fopen($file3_tmp_name, "r"); $content = fread($handle, $file3_size); fclose($handle); $encoded_content3 = chunk_split(base64_encode($content)); //now we know we have the file for attachment, set $file_attached to true $file3_attached = true; } if($file_attached && $file2_attached) //continue if we have the file { $boundary = md5("sanwebe"); //header $headers = "MIME-Version: 1.0rn"; $headers .= "From:".$from_email."rn"; $headers .= "Content-Type: multipart/mixed; boundary = $boundaryrnrn"; //plain text $body = "--$boundaryrn"; $body .= "Content-Type: text/plain; charset=ISO-8859-1rn"; $body .= "Content-Transfer-Encoding: base64rnrn"; $body .= chunk_split(base64_encode($message_body)); //attachment $body .= "--$boundaryrn"; $body .="Content-Type: $file_type; name="$file_name"rn"; $body .="Content-Disposition: attachment; filename="$file_name"rn"; $body .="Content-Transfer-Encoding: base64rn"; $body .="X-Attachment-Id: ".rand(1000,99999)."rnrn"; $body .= $encoded_content; //attachment $body .= "--$boundaryrn"; $body .="Content-Type: $file2_type; name="$file2_name"rn"; $body .="Content-Disposition: attachment; filename="$file2_name"rn"; $body .="Content-Transfer-Encoding: base64rn"; $body .="X-Attachment-Id: ".rand(1000,99999)."rnrn"; $body .= $encoded_content2; //attachment $body .= "--$boundaryrn"; $body .="Content-Type: $file2_type; name="$file3_name"rn"; $body .="Content-Disposition: attachment; filename="$file3_name"rn"; $body .="Content-Transfer-Encoding: base64rn"; $body .="X-Attachment-Id: ".rand(1000,99999)."rnrn"; $body .= $encoded_content3; }else{ //proceed with PHP email. $headers = "From:".$from_email."rn". 'X-Mailer: PHP/' . phpversion(); $body = $message_body; } $send_mail = mail($to_email, $subject, $body, $headers); if(!$send_mail) { //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens) $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.')); die($output); }else{ $output = json_encode(array('type'=>'message', 'text' => 'Hey! Your application has been sent and it's waiting for approve.')); die($output); } }} I just want to get user Id with this form also
  4. It needs to be included in handler php file or hook it to the page I need with new theme function like this: function nameOfFunction() { if(is_page(940)){ wp_enqueue_script( 'attachingHeader', 'PATHTOFILE'); }}add_action( 'wp_enqueue_scripts', 'nameOfFunction' ); ? edit I've included wpLoad as in example above, after adding $user_ID = get_current_user_id(); to php handler file - it just doesn't work without any visible errors - I mean the form, doesn't proceed on final step (it's jQuery custom step form) anyways usually was error like user_ID is not defined or so..
  5. It is. It's just the X Theme from Themeco and I guess it works just a little different then standar template. Anyways support of themeco refuses help in obtaining user id edit: or not. It's even the same thing - mine is just very blank template without sidebars or footers but its the same function type that loads content get_template_part( 'loop', 'page' ); and x_get_view( x_get_stack(), 'wp', 'page' ); Anyways it doesn't work
  6. I've change template1 code to <?php// =============================================================================// PAGE.PHP// -----------------------------------------------------------------------------// Handles output of individual pages.//// Content is output based on which Stack has been selected in the Customizer.// To view and/or edit the markup of your Stack's pages, first go to "views"// inside the "framework" subdirectory. Once inside, find your Stack's folder// and look for a file called "wp-page.php," where you'll be able to find the// appropriate output.// =============================================================================?> <div id="container"> <div id="content" role="main"><?phpx_get_view( x_get_stack(), 'wp', 'page' ); $user_ID = get_current_user_id();echo '<p>xxxx User ID:'.$user_ID.' xxxx</p>'; ?> </div><!-- #content --> </div><!-- #container --> Used this template to create new page but nothing happened...
  7. Well as you've said already it's surely my mistake of directory locations etc. I just couldn't get this user id on my custom form which was made by interface (add page) and is handled by included files handler of php and js...Trying make this function is a result of hardcore web farming about how to do this anyways as it just didn't want to work...I don't understand this slug system and where is the place I can add result this function (like user id) to the result of form user filled in. editCould you please provide any lecture that will clarify the problem of mine?
  8. Hello!I'm having trouble with getting an user id on wordpress. I'd appreciate if anyone can take a look what could be wrong with methods I'm trying?getuserid.php - file in which I'm trying to make functions to obtain current user id including: user.php and pluggable.php from wp-includes The function reference:https://codex.wordpress.org/Function_Reference/get_current_user_id I'm adding code to my getuserid.php $user_ID = get_current_user_id(); and getting: Uncaught ReferenceError: get_current_user_id is not defined What's wrong? I'm having user.php included
  9. Hello!I have simple form, sending email to me with data on finish, including one image attachment. Let me show You part of my code that is responsible for getting and sending data: Sample Structure .... <div> <label for="file_attach">Upload a screenshot from your HM2/PT4</label> <input type="file" name="file_attach" id="file_attach" class="required" /> </div> </div></section><h3>Another step</h3><section> <div class="leftside"> <div> <label for="maingoal">What is your main goal?</label> <textarea name="maingoal" id="maingoal" class="required" cols="50" rows="5"> </textarea> </div>... Javascript handler (It's only the part that is executing after submitting corretly filled form) onFinished: function (event, currentIndex){ var proceed = true; var m_data = new FormData(); m_data.append( 'firstName', $('input[name=firstName]').val()); m_data.append( 'file_attach', $('input[name=file_attach]')[0].files[0]); m_data.append( 'maingoal', $('textarea[name=maingoal]').val()); //getting values from fields $.ajax({ url: 'PHPHANDLER.php', data: m_data, processData: false, contentType: false, type: 'POST', dataType:'json', success: function(response){ //load json data from server and output message if(response.type == 'error'){ output = '<div class="error">'+response.text+'</div>'; }else{ //success redirect } } $("#example-form #contact_results").hide().html(output).slideDown(); } }); } And PHP file that is used by this javascript to send a message: //check if its an ajax request, exit if notif(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { $output = json_encode(array( //create JSON data 'type'=>'error', 'text' => 'Sorry Request must be Ajax POST' )); die($output); //exit script outputting json data}$firstName = filter_var($_POST["firstName"], FILTER_SANITIZE_STRING);$maingoal = filter_var($_POST["maingoal"], FILTER_SANITIZE_STRING);//additional simple php validationif(strlen($firstName)<2){ // If length is less than 4 it will output JSON error. $output = json_encode(array('type'=>'error', 'text' => 'First name is too short or empty!')); die($output);}else{//email body$message_body = "it doesn't matter";### Attachment Preparation ###$file_attached = false;if(isset($_FILES['file_attach'])) //check uploaded file{ //get file details we need $file_tmp_name = $_FILES['file_attach']['tmp_name']; $file_name = $_FILES['file_attach']['name']; $file_size = $_FILES['file_attach']['size']; $file_type = $_FILES['file_attach']['type']; $file_error = $_FILES['file_attach']['error']; //exit script and output error if we encounter any if($file_error>0) { $mymsg = array( 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder" ); $output = json_encode(array('type'=>'error', 'text' => $mymsg[$file_error])); die($output); } //read from the uploaded file & base64_encode content for the mail $handle = fopen($file_tmp_name, "r"); $content = fread($handle, $file_size); fclose($handle); $encoded_content = chunk_split(base64_encode($content)); //now we know we have the file for attachment, set $file_attached to true $file_attached = true; } if($file_attached) //continue if we have the file{ $boundary = md5("sanwebe"); //header $headers = "MIME-Version: 1.0rn"; $headers .= "From:".$from_email."rn"; $headers .= "Reply-To: ".$email."" . "rn"; $headers .= "Content-Type: multipart/mixed; boundary = $boundaryrnrn"; //plain text $body = "--$boundaryrn"; $body .= "Content-Type: text/plain; charset=ISO-8859-1rn"; $body .= "Content-Transfer-Encoding: base64rnrn"; $body .= chunk_split(base64_encode($message_body)); //attachment $body .= "--$boundaryrn"; $body .="Content-Type: $file_type; name="$file_name"rn"; $body .="Content-Disposition: attachment; filename="$file_name"rn"; $body .="Content-Transfer-Encoding: base64rn"; $body .="X-Attachment-Id: ".rand(1000,99999)."rnrn"; $body .= $encoded_content; }else{ //proceed with PHP email. $headers = "From:".$from_email."rn". 'Reply-To: '.$email.'' . "n" . 'X-Mailer: PHP/' . phpversion(); $body = $message_body;}$send_mail = mail($to_email, $subject, $body, $headers); if(!$send_mail){ //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens) $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.')); die($output);}else{ $output = json_encode(array('type'=>'message', 'text' => 'Hey '.$firstName .'! Your application has been sent and it's waiting for approve.')); die($output); }} This all code is doing job for me with sending user data and one image.I was trying a couple of modifications but couldn't get this to work for more attachments. Any1 please help me rebuild it to my needs
  10. Yay, it helped! Made groups groups: { bday: "gsday gsmonth gsyear"}, Added simple rule under errorPlacement: function(error, element) if (element.attr("name") == "gsday" || element.attr("name") == "gsmonth" || element.attr("name") == "gsyear" ) { error.insertAfter("#birthDate");} else { error.insertAfter(element);} ...aaand my message is showing after label of id #birthDate as it should - if any of fields are empty Thank you for your help!
  11. Hey!I'm having problem with adding one 'Please add date of birth' message if any date-select-box is empty... How do I achieve it?HTML CODE (Simplified part of my form) <form id="example-form" action="#"> <div> <h3>Personal Info</h3> <section> <div class="leftside"> <label for="firstName">First Name *</label> <input id="firstName" name="firstName" type="text" class="required"> <div> <label for="birthDate">Date of Birth *</label> <div style="float: left; padding: 2px;"> <select id="gsmonth" name="gsmonth"> <option value="">-</option> <option value="1">January</option> //[more options] </select> </div> <div style="float: left; padding: 2px;"> <select id="gsday" name="gsday"> <option value="">-</option> <option value="1">1</option> //[more options] </div> <div style="float: left; padding: 2px;"> <select id="gsyear" name="gsyear"> <option value="">-</option> <option value="2000">2000</option> //[more options] </div> </div> <div id="rightside"> //[...] </div> </section> //[title and another section]</form> If I'd add a "required" class to those select fields, for each empty select displaying "This field is requied" that is destroying design of fields (Means 3 empty fields = 3 messages). I'd like to make jQuery rule that will display one error message if any of those fields are missing and show it under label "birthDate".I have jQuery Steps, JQuery Validation and JQuery Additional Methods (just to control files upload) plugin added. For now simple rules like this was enough to control other select fields: $( "#residence" ).rules( "add", { required: true, messages: { required: "Please select your country of residence. ",}}); Please help me with handling of this messages
×
×
  • Create New...