Why the file upload is not functioning in following form? - php

I'm using smarty and PHP for my website. Following is my form code from smarty template.
<form id="manage_reply_enquiry" name="manage_reply_enquiry" method="post" action="{$control_url}modules/enquiries/reply_to_enquiry.php" enctype="multipart/form-data">
<ul>
<li>
<label>{'To Name'|signal_on_error:$error_msg:'contact_name'} :</label>
<div class="form-element">
<input type="text" name="contact_full_name" id="contact_full_name" value="{$data.contact_full_name|capitalize}" class="">
</div>
</li>
<li>
<label>{'To Email'|signal_on_error:$error_msg:'email'} :</label>
<div class="form-element">
<input type="text" name="contact_email_id" id="contact_email_id" value="{$data.contact_email_id}" class="">
</div>
</li>
<li>
<label>{'Reply'|signal_on_error:$error_msg:'reply'} :</label>
<div class="form-element">
<textarea name="reply" id="reply" cols="60" rows="12">{$data.reply}</textarea>
</div>
</li>
<li>
<label>{'Upload File'|signal_on_error:$error_msg:'reply_file_name'} :</label>
<div class="form-element">
<p class=""><input type="file" id="reply_file_name" name="reply_file_name" /></p>
<div class="input-info"> <span class="required">Note* (Image size should be less then 1 mb and alowed format types are CSV, XLS)</span></div>
</div>
</li>
<input type="hidden" name="contact_id" value="{$data.contact_id}" />
<input type="hidden" name="from_date" value="{$from_date}" />
<input type="hidden" name="to_date" value="{$to_date}" />
<input type="hidden" name="op" value="{$op}" />
<li>
<label></label>
<div class="form-element">
<input type="submit" name="submit" id="submit" class="c-btn" value="Send">
<input type="button" name="cancel" id="cancel" class="c-btn" value="Cancel" onclick="javascript:window.location.href='{$control_url}modules/enquiries/view_contact_us.php?page={$page}&from_date={$from_date}&to_date={$to_date}'">
</div>
</li>
</ul>
</form>
If I print the Posted data in the reply_to_enquiry.php file, I'm getting following data:
Array
(
[contact_full_name] => ABCD
[contact_email_id] => abcd#gmail.com
[reply] => How are you now?
[contact_id] => 59
[from_date] => 10/09/2000
[to_date] => 10/09/2013
[op] => view
[submit] => Send
)
Can you tell me why I'm not able to get the value from file control named reply_file_name from the form? I couldn't get why this is happening. Can anyone help me in this regard? Thanks in advance.

When you do an upload in PHP, the informations relative to the uploaded file are in the $_FILES variable.
Here a minimal upload script. (don't use it in production environment)
<?php
if(isset($_FILES['reply_file_name'])){
$target = "some/path/".basename($_FILES['reply_file_name']['name']) ;
print_r($_FILES);
if(move_uploaded_file($_FILES['reply_file_name']['tmp_name'],$target)) echo "OK!";//$chmod o+rw some/path
}
?>

Related

PHP index is not recognized (post method)

I am very new to php and am still in the learning phase. I typed a small script 1 to 1 and had to find out that the index from my HTML file is not recognized in php. In the given video the "GET" method is used, but it should actually work exactly the same way. It is just a test script. Nevertheless, an answer would be helpful.
Here are my scripts:
HTML:
<form id="register-form" action="Memeon.php" method="post">
<img class="register_avatar" src="pictures/login_register_avatar.png" oncontextmenu="return false;">
<h2>Welcome to Memeon</h2>
<div class="reg-input-div one">
<div class="i">
<i class="fas fa-user"></i>
</div>
<div>
<h5>Username</h5>
<input id="reg_un" class="reg-input" name="username" type="text" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>
</div>
<div class="reg-input-div two">
<div class="i">
<i class="fas fa-at"></i>
</div>
<div>
<h5>Email-Adress</h5>
<input id="reg_ea" class="reg-input" name="email" type="email" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>
</div>
<div class="reg-input-div three">
<div class="i">
<i class="fas fa-lock"></i>
</div>
<div>
<h5>Password</h5>
<input id="reg_pw" class="reg-input" name="password" type="password" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>
</div>
<a id="rl_l1" href="#">2-Factor-Authentication</a>
<a id="rl_l2" href="#">Forgot Password?</a>
<input type="submit" onclick="setRegisterInfo()" class="register_btn" value="Sign in">
</form>
PHP:
<?php
echo "Hallo ". $_POST["username"];
?><br>
Der sehnlichst erwünschte Newsletter wird gesendet an <?php echo $_POST["email"]; ?>
Both are in the same folder. With a submit button I get to the PHP page. An error always appears there.
Maybe it haves to be with something in your "setRegisterInfo()" function (is it implemented ? if so, you should post it here too :) ) in the "onclick" attribute of the submit input at the very end. If that function breaks, the form won't be submitted.
<input type="submit" onclick="setRegisterInfo()" class="register_btn" value="Sign in">
Try again without that function.
<input type="submit" class="register_btn" value="Sign in">

How I can make appear a custom widget (WordPress)

In my WordPress website, I added a custom widget with help of this plugin: https://wordpress.org/plugins/custom-post-type-widgets/
I want to show that widget on my archive page with PHP.
I went to https://codex.wordpress.org/Function_Reference/the_widge but didn't get what I use to make that widget appear in website. I still do not understand how to use it or what name, class, etc. I should use in website to make it appear.
It's created by an option in theme so not getting how to get it's class or ID
but in Appearance->widget code is listed below.
<div class="widgets-holder-wrap closed">
<div id="sidebar-18" class="widgets-sortables"> <div class="sidebar-name">
<div class="sidebar-name-arrow"><br /></div>
<h2>Custom Post Type - course <span class="spinner"></span></h2>
</div>
<div class="sidebar-description">
<p class="description">course</p>
</div>
<div id='widget-61_custom-post-type-categories-4' class='widget'> <div class="widget-top">
<div class="widget-title-action">
<button type="button" class="widget-action hide-if-no-js" aria-expanded="false">
<span class="screen-reader-text">Edit widget: Categories (Custom Post Type)</span>
<span class="toggle-indicator" aria-hidden="true"></span>
</button>
<a class="widget-control-edit hide-if-js" href="/wp-admin/widgets.php?editwidget=custom-post-type-categories-4&sidebar=sidebar-18&key=0">
<span class="edit">Edit</span>
<span class="add">Add</span>
<span class="screen-reader-text">Categories (Custom Post Type)</span>
</a>
</div>
<div class="widget-title"><h3>Categories (Custom Post Type)<span class="in-widget-title"></span></h3></div>
</div>
<div class="widget-inside">
<form method="post"> <div class="widget-content"> <p><label for="widget-custom-post-type-categories-4-title">Title:</label>
<input class="widefat" id="widget-custom-post-type-categories-4-title" name="widget-custom-post-type-categories[4][title]" type="text" value="asdf" /></p>
<p><label for="widget-custom-post-type-categories-4-taxonomy">Taxonomy:</label><select class="widefat" id="widget-custom-post-type-categories-4-taxonomy" name="widget-custom-post-type-categories[4][taxonomy]"><option value="category">Categories category</option><option value="employees_category">Employees Categories employees_category</option><option value="faq_category">Faq Categories faq_category</option><option value="news_category">News Categories news_category</option><option value="portfolio_category">Portfolio Categories portfolio_category</option><option value="testimonial_category">Testimonial Categories testimonial_category</option><option value="photo_album_category">Photo Album Categories photo_album_category</option><option value="wp_cc_tax_country">Country wp_cc_tax_country</option><option value="course-category" selected='selected'>Course Categories course-category</option><option value="expert-field">Expert fields expert-field</option><option value="internship-category">Internship Categories internship-category</option><option value="country-cost">Countries for Cost country-cost</option><option value="application-basket">Applications Baskets application-basket</option><option value="scholarship-category">Scholarship categories scholarship-category</option><option value="entry-requirement">Entry Requirements entry-requirement</option><option value="awarding-level">Awarding levels awarding-level</option><option value="intake">Intakes intake</option><option value="study-mode">Study Modes study-mode</option><option value="status">Statuses status</option><option value="course-keyword-taxonomy">Course Keywords course-keyword-taxonomy</option></select></p>
<p><input type="checkbox" class="checkbox" id="widget-custom-post-type-categories-4-dropdown" name="widget-custom-post-type-categories[4][dropdown]" />
<label for="widget-custom-post-type-categories-4-dropdown">Display as dropdown</label><br />
<input type="checkbox" class="checkbox" id="widget-custom-post-type-categories-4-count" name="widget-custom-post-type-categories[4][count]" checked='checked' />
<label for="widget-custom-post-type-categories-4-count">Show post counts</label><br />
<input type="checkbox" class="checkbox" id="widget-custom-post-type-categories-4-hierarchical" name="widget-custom-post-type-categories[4][hierarchical]" checked='checked' />
<label for="widget-custom-post-type-categories-4-hierarchical">Show hierarchy</label></p>
</div> <input type="hidden" name="widget-id" class="widget-id" value="custom-post-type-categories-4" />
<input type="hidden" name="id_base" class="id_base" value="custom-post-type-categories" />
<input type="hidden" name="widget-width" class="widget-width" value="250" />
<input type="hidden" name="widget-height" class="widget-height" value="200" />
<input type="hidden" name="widget_number" class="widget_number" value="4" />
<input type="hidden" name="multi_number" class="multi_number" value="" />
<input type="hidden" name="add_new" class="add_new" value="" />
<div class="widget-control-actions">
<div class="alignleft">
<button type="button" class="button-link button-link-delete widget-control-remove">Delete</button> |
<button type="button" class="button-link widget-control-close">Close</button>
</div>
<div class="alignright">
<input type="submit" name="savewidget" id="widget-custom-post-type-categories-4-savewidget" class="button button-primary widget-control-save right" value="Save" /> <span class="spinner"></span>
</div>
<br class="clear" />
</div>
</form> </div>

two javascript forms on one page

I cant get the two forms to play with each other.. - meaning I have one form that sends an email - and another that is using a search function. The email form is working ok. Validates just fine, but when I click on the search button, it doesn't do anything. ( the search form is working fine if I remove the email form )
What am I missing ??.. ugh..
I've been working on this, but my brain is fried. I am sure it is something simple.
Any help from you guys would be much appreciated.
<form method="post" action="contact.php" name="contactform" id="contactform">
<div class="full-lenght">
<div class="to-left">Name<br>
<span class="small-required">Required</span> </div>
<div class="to-right">
<input name="name" type="text" id="name" value="" class="contact-field" />
</div>
</div>
<div class="clear"></div>
<div class="full-lenght">
<div class="to-left">Email<br>
<span class="small-required">Required</span> </div>
<div class="to-right">
<input name="email" type="text" id="email" value="" class="contact-field" />
</div>
</div>
<div class="clear"></div>
<div class="full-lenght">
<div class="to-left">Phone<br>
<span class="small-required">Required</span> </div>
<div class="to-right">
<input name="phone" type="text" id="phone" value="" class="contact-field" />
</div>
</div>
<div class="clear"></div>
<div class="full-lenght">
<div class="to-left">Message<br>
<span class="small-required">Required</span> </div>
<div class="to-right">
<textarea name="comments" rows="3" id="comments" class="contact-message"></textarea>
</div>
</div>
<div class="clear"></div>
<div class="clear"></div>
<div class="human">3 + 1 = ?<br>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" />
<input name="e" type="submit" class="contact-button" id="submit" value="Submit" />
</div>
</form>
<div class="search">
<form class="form" action="search_results.php" method="get">
<input name="q" type="text" class="search_field" value="Search.." onfocus="if (this.value=='Search..') this.value='';">
<a onclick=" document.forms[0].submit();return false" href="#"><img class="search_button" title="Search Button" src="images/search_button.jpg" alt="" width="24" height="24"></a> <br>
<br>
</form>
</div>
This is the code. The second form starts in search div. The first one is an email form with ajax validation.
try this,
in the second form
<form class="form" id="searchform" action="search_results.php" method="get">
<input name="q" type="text" class="search_field" value="Search.." onfocus="if (this.value=='Search..') this.value='';" />
<a onclick=" document.getElementById('searchform').submit();return false" href="#"><img class="search_button" title="Search Button" src="images/search_button.jpg" alt="" width="24" height="24"/></a> <br/>
<br/>
</form>
This doesn't have anything to do with PHP, but does have everything to do with JavaScript.
Change:
<a onclick=" document.forms[0].submit();return false" href="#">
to:
<a onclick="document.forms[1].submit();" href="#">
You're using legacy DOM notation in your JavaScript, which is OK but outdated. When you have forms[0] you're referring to the first form in the DOM which isn't the search form (the contact form is), forms[1] is the search form. Clicking the icon will fail without the change, but you could type in the box and hit enter and it will work, since the JavaScript you have won't be triggered (no click). I also see no need to keep the return false statement in there.
<form class="form" action="search_results.php" method="get">
<input name="q" type="text" class="search_field" value="Search.." onfocus="if (this.value=='Search..') this.value='';">
<input type="submit" value='Search'> <br>
<br>
This problem you used anchor tag as button form and it doesn't work for submitting form so you can either replace anchor tag with input tag "submit type" as you see in code or you can use JavaScript to make anchor tag when you click on it, it fires a submitting form.
Enjoy :)

How to call a jQuery function on click event in the following scenario?

I'm using PHP, Smarty and jQuery for my website. There is a functionality of showing and hiding an element on a form. The HTML as well as code from jQuery function is as below:
HTML Code:
<div class="c-mega-accord">
<ol class="fnAccordion">
<li>
<a class="fnTrigger" href="#">Practice Sheet Basic Details <span></span></a>
<div class="fnAccContent">
<div class="c-grad-box">
<div class="form-wrapper">
{if $error_msg}<div class="error-info">{$error_msg.error_msgs}</div>{/if}
<form name="manage_practice_sheet" id="manage_practice_sheet" action="practice_sheet.php" method="post">
<input type="hidden" name="op" id="op" value="{$op}" />
<input type="hidden" name="sheet_type" id="sheet_type" value="{$sheet_type}" />
<input type="hidden" name="form_submitted" id="form_submitted" value="yes" />
<input type="hidden" name="practice_sheet_id" id="practice_sheet_id" value="{$practice_sheet_id}" />
<input type="hidden" name="hidden_practice_sheet_category_id" id="hidden_practice_sheet_category_id" value="{$practice_sheet_category_id}" />
<input type="hidden" name="practice_sheet_id" id="practice_sheet_id" value="{$practice_sheet_id}" />
<p class="form-info fl-right">* Mandatory fields</p>
<ul>
<li>
<label>{'Category'|signal_on_error:$error_msg:'practice_sheet_category_id'}<span class="reqd">*</span></label>
<div class="form-element">
<select name="practice_sheet_category_id" id="practice_sheet_category_id" <!--onChange="get_subcategory_by_category('{$control_url}modules/category/manage_category.php', this.value, 'get_subcategory_by_category', '#practice_sheet_sub_category_id');"--> >
<option value="">Select</option>
{if $all_parent_categories}
{foreach from=$all_parent_categories item="parent_category"}
<option value="{$parent_category.category_id}" {if $data.practice_sheet_category_id==$parent_category.category_id || $practice_sheet_category_id==$parent_category.category_id} selected="selected"{/if}>{$parent_category.category_name}</option>
{/foreach}
{/if}
</select>
</div>
</li>
<li>
<label>{'Practice Sheet Name'|signal_on_error:$error_msg:'practice_sheet_name'}<span class="reqd">*</span></label>
<div class="form-element">
<input class="" type="text" name="practice_sheet_name" id="practice_sheet_name" value="{$data.practice_sheet_name}" maxlength="50">
</div>
</li>
<li>
<label>Display Date</label>
<div class="form-element">
<input type="text" class="cal fl-left" id="frmDate" name="frmDate" value="{if $data.practice_sheet_display_date !='0' && $data.practice_sheet_display_date !=''}{$data.practice_sheet_display_date}{/if}">
</div>
</li>
<li>
<label>Practice Sheet For</label>
<div class="form-element">
<input class="" type="text" name="practice_sheet_for" id="practice_sheet_for" value="{$data.practice_sheet_for}" maxlength="50">
</div>
</li>
<li>
<label></label>
<div class="form-element">
<!--<input type="submit" value="{$submit_value}" class="c-btn" id="saveAddMore" name="submit">
<input type="button" value="{$cancel_value}" class="c-gray-btn" id="done" name="done" onclick="javascript:window.location.href='{$control_url}modules/practice_sheet/practice_sheet.php?op={$query_string}'"><br/>-->
<span class="c-btn c-continus-btn"><input type="button" name="continus" id="continus" value="Continue" id="" name=""></span>
<span class="c-gray-btn c-cancel-btn"><input type="button" value="Cancel" id="" name=""></span>
</div>
</li>
</ul>
</form>
</div>
</div>
</div>
</li>
<li>
<a class="fnTrigger" href="#">Select Category <span></span></a>
<div class="fnAccContent">
<div class="c-grad-box">
</div>
</div>
</li>
</ol>
</div>
jQUery Code:
function accordion(){
var li = $(".fnAccordion > li");
li.eq(0).addClass("active");
li.children('.fnAccContent').not(':first').hide();
$(".fnAccordion .fnTrigger").click(function(e){
e.preventDefault();
var numLi = $(this).parent('li').siblings();
if(numLi.length > 0){
$(this).parent('li').siblings().removeClass("active");
var curState = $(this).parent().find(".fnAccContent").css("display");
if(curState == "none"){
$(".fnAccContent").slideUp();
$(this).parent().addClass("active");
$(this).parent().find(".fnAccContent").slideDown();
}
}else{
$(this).parent('li').toggleClass("active");
$(this).parent().find(".fnAccContent").slideToggle();
}
})
}
$(document).ready(function(){
accordion();
})
Now the functionality of hide/show is working fine when I click on following two elements:
<a class="fnTrigger" href="#">Practice Sheet Basic Details <span></span></a>
<a class="fnTrigger" href="#">Select Category <span></span></a>
Actually I want to make this functionality work on Continue button(following is the HTML code snippet for it):
<input type="button" name="continus" id="continus" value="Continue" id="" name="">
I tried to make it work on Continue button by applying the class fnTrigger but it didn't work. Can you help me in this regard? Thanks in advance.
If you want the function to be triggered when both the classes are present,
you use
$(".fnAccordion .fnTrigger").click(function(){
//Your code here
});
If you want the function to get triggered when element of either class is clicked, use a "," to separate the classes.
$(".fnAccordion, .fnTrigger").click(function(){
//Your code here
});
Your check only checks for the fnTrigger class INSIDE an element with the class fnAccordion
$(".fnAccordion .fnTrigger").click(function(e){});
Is your button inside the element with the class fnAccordion?

submit form data into iframe via post [file upload]

UGH.
Hi.
I have a form. I'd like to know how/if I could submit this form to an iFrame that has the page that will handle the file upload/naming.
If I try even something simple like post an input/text to the form, nothing happens (the handler is set to echo the $_POST). I have tried setting the iframe name/id et. al. and setting the form target to the respective iframe name/id. When I hit submit, the iframe just sits there like a dummy. WTF am I doing wrong?
Thx.
<form action="/clients/testAddTrans/<?=$clientID?>" id="reportEdit" class="EditName" method="POST" target="transFrame">
<div class="inputDiv">
<span class="inputLabel">Description:</span>
<span class="textInput">
<input type="text" id="transDesc" name="transDesc" value="" size="40" class=""/>
</span>
</div>
<div class="inputDiv">
<span class="inputLabel">Date:</span>
<span class="textInput">
<input type="text" id="date" name="transDate" value="" size="40" class=""/>
</span>
</div>
<div class="inputDiv">
<span class="inputLabel">File:</span>
<span class="textInput">
<input type="file" id="file" name="transFile" value="" size="40" class=""/>
</span>
</div>
<input name="name_id" type="hidden" value="<?=$itemid?>" />
<input type="submit" value="Submit" name="submit"/>
<input type="button" class="secondaryAction" onclick="hideOverDiv()" value="Close"/>
<div id="overDivNotice" class="overDivNotice" style="display:none"></div>
<iframe action="/clients/testAddTrans/<?=$clid?>" id="transFrame" name="transFrame" style=""></iframe>
</form>
Generated html via firebug:
<div class="content" id="overDivContent"><div class="inputDivContainer">
<fieldset class="inputOverDiv" id="tfa_Names">
<legend><b>Add Transmittal:</b></legend>
<div class="data"><form target="transFrame" method="POST" class="EditName" id="reportEdit" action="/clients/testAddTrans/fsdf1556"><div class="inputDiv"><span class="inputLabel">Description:</span><span class="textInput"><input type="text" class="" size="40" value="" name="transDesc" id="transDesc"/></span></div><div class="inputDiv"><span class="inputLabel">Date:</span><span class="textInput"><input type="text" class="" size="40" value="" name="transDate" id="date"/></span></div><div class="inputDiv"><span class="inputLabel">File:</span><span class="textInput"><input type="file" class="" size="40" value="" name="transFile" id="file"/></span></div><input type="hidden" value="121" name="name_id"/>
</form><br/>
<div align="center" class="actions" id="overDivActions">
<input type="submit" name="submit" value="Submit"/>
<input type="button" value="Close" onclick="hideOverDiv()" class="secondaryAction"/>
</div>
<div style="display: none;" class="overDivNotice" id="overDivNotice">
</div></div>
<iframe style="" name="transFrame" id="transFrame">tyh</iframe>
</fieldset>
</div></div>
I don't know why it is putting the </form> tag where it is.. It is supposed to be after the iframe, but whatever. Does that even matter? Is the iframe supposed to be inside the form?
Nice, I was wrong.. I found the problem.
First use html for write html;
With the code below works:
for 'testSubmitiFrame.html':
<form target="transFrame" method="POST" class="EditName" id="reportEdit" action="testSubmitiFrame.php">
<div class="content" id="overDivContent">
<div class="inputDivContainer">
<fieldset class="inputOverDiv" id="tfa_Names">
<legend><b>Add Transmittal:</b></legend>
<div class="data">
<div class="inputDiv">
<span class="inputLabel">Description:</span>
<span class="textInput"><input type="text" class="" size="40" value="" name="transDesc" id="transDesc"/></span>
</div>
<div class="inputDiv">
<span class="inputLabel">Date:</span>
<span class="textInput"><input type="text" class="" size="40" value="" name="transDate" id="date"/></span>
</div>
<div class="inputDiv">
<span class="inputLabel">File:</span>
<span class="textInput"><input type="file" class="" size="40" value="" name="transFile" id="file"/></span>
</div>
<input type="hidden" value="121" name="name_id"/>
<br/>
<div align="center" class="actions" id="overDivActions">
<input type="submit" name="submit" value="Submit"/>
<input type="button" value="Close" onclick="hideOverDiv()" class="secondaryAction"/>
</div>
<div style="display: none;" class="overDivNotice" id="overDivNotice"></div>
</div>
</fieldset>
</div>
</div>
</form>
<iframe style="" name="transFrame" id="transFrame">tyh</iframe>
for 'testSubmitiFrame.php':
<?php
var_dump($_POST);
?>
Your problem is html syntax. This works.
Apparently, a div or stupid fieldset tag being out of place was preventing the thing from working. I really gotta start checking my code before bothering you nice people.
Thanks anyway.
Your logic appears valid, can you setup a test page?
This page will do what you want, so you may want to look through it and see what may be different from what you are already doing:
http://www.anyexample.com/programming/php/php_ajax_example__asynchronous_file_upload.xml
Is the action in the html the php file that will do the processing?
I think it's because of these two lines:
echo "</div>";
echo "</div><br>
You're closing <div> with no opening tags. This is making Firefox close the <form> early - your submit button isn't inside your form, which is why it's not working.
The position of the iframe inside or outside the form doesn't matter - just make sure the rest of the HTML is valid and it should work.

Categories