Form and Validation/CSS Issue - php

I have a form located here:
http://f14.co/auto-search/Test/
You'll see in the code that there is a form element about halfway down:
</div>
<form method="post" class="form-horizontal" id="final_form" action="send_mail.php">
<input type="hidden" name="template" id="template" value="Buyers" />
<div class="modal-body" >
<div id="lead_info_1">
<div class="input select">
<div class=""></div>
<div class="span-4 step-2-dropdown append-bottom control-group">
<select class="span3 required" name="minPrice" id="minPrice">
About 1/4 of the way down there is a checkbox that I need to be inside the form to work with send_mail.php:
<div class="sold"></div>
<div class="form">
<h2>Search for your dream home<br />
and save now!</h2>
<legend>Which Areas are you interested in?</legend>
<div class="areas row-fluid" style="text-align:left !important;">
<div class='span5' style='margin-left:0px !important;'>
<label>
<input type="checkbox" name="arrayValue[]" id="area[0]" value="test" style='margin-top:-5px !important;'> test</label>
</div>
</div>
<input type="button" onclick="jQuery('#myModal').modal('show')" value="CONTINUE" />
However, if I move the form element above the checkboxes, the error checking (the form turns red if values aren't filled out), goes away.
Anyone know how to preserve the error checking? I can't for the life of me figure out what I'm doing wrong. Not sure if this is a page code problem or a CSS issue.

Related

How can I use multiple input type file in one html form?

Recently I need to use multiple input type file in one form. But when I post the form its returning null. Like I have nothing on $_POST. I have also add the enctype="multipart/form-data". I am stacked for last 2 days. Googled for many times. But still didn't get any solution. Please help me to out of this.
<form enctype="multipart/form-data" action="/admin/process_post/savepost" method="POST">
<div class="uk-grid uk-grid-small" data-uk-grid-margin="">
<div class="uk-width-medium-7-10">
<div class="md-card">
<div class="md-card-content">
<h3 class="heading_a uk-margin-medium-bottom">Add New Canvas</h3>
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-medium-1-1">
<div class="uk-form-row">
<label>Post Title</label>
<input type="text" name="post_title" id="post_title" class="md-input" />
</div>
<div class="uk-form-row">
<label>Post Description</label>
<textarea id="post_desc" name="post_desc" cols="30" rows="20"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="uk-width-medium-3-10">
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<p>
<input type="checkbox" name="post_status" id="post_status" checked data-md-icheck />
<label for="post_status" class="inline-label">Post Status</label>
</p>
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<label for="post_attachment" class="inline-label">Post Featured Image</label>
<input type="file" id="post_attachment" name="post_attachment">
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<label for="result_img" class="inline-label">Post result Image</label>
<input type="file" id="result_img" name="result_img" multiple="multiple">
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<button type="submit" class="uk-form-file md-btn md-btn-primary">Save Post</button>
</div>
</div>
</div>
</div>
</div>
</form>
I know this is a silly situation for a developer when they face problem like this.
Files can be gotten through $_FILES
When doing multiple uploads at same name, name it as array appending [] at end of name example: ( name="images[]" )
If upload continues to appear as empty, and you said in comment that with one file it's doing right, try to change at php.ini post_max_size and upload_max_filesize to a larger amount. Also check max_file_uploads - the number of files allowed for uploads per single request.
Your problem should be your form action, try to put an "/" on the end of it and see if it works:
<form enctype="multipart/form-data" action="/admin/process_post/savepost/" method="POST">
You need to change your file input name to an array
<input type="file" id="result_img" name="result_img[]">
Also try adding multiple
<input type="file" id="result_img" name="result_img[]" multiple>
To check for files you must use $_FILES instead of $_POST

Serialize array & put results into hidden text field?

I'm currently encountering a problem which is baffling me. There will be a lack of PHP mixed with HTML due to using a MVC Framework.
What i've got:
Form A on Page 1 with a submit button which directs user input from Form A to page 2 with a chunk of text for the user to read before continuing, a hidden text field which will contain a serialized array from Form A and a submit button to continue to the validation of user input.
My forms direct to the correct pages as required, the post array can be seralized providing I do not put it into a text field. The HTML from form A follows:
<form action="/RegisterInformation" method="POST">
<div class="row">
<div class="large-12 columns">
<input type="text" name="Username" placeholder="Username, ex: JohnDoe ">
</div>
</div>
<div class="row">
<div class="large-4 columns">
<input type="password" name="Password" placeholder="Password">
</div>
<div class="large-4 columns">
<input type="password" name="cpassword" placeholder="Confirm Password">
</div>
<div class="large-4 columns">
<input type="text" name="email" placeholder="Email, ex: JohnDoe#provider.com">
</div>
</div>
<div class="row">
<div class="large-12 columns">
<textarea name="Referral" placeholder="Where Did You Hear About Us?"></textarea>
</div>
</div>
<div class="row">
<div class="large-4 columns">
<input type="submit" name="submit" value="Continue" class="button">
</div>
</div>
</form>
The redirect to page 2:
<div class="row">
<div class=" large-12 columns">
<p>
<?php echo $data['PreregisterInformation']; ?>
</p>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<form action="/Continue" method="POST">
<input type="text" name="SubmitInfo" value="<?php echo serialize($_POST); ?>">
<input type="submit" name="submit" value="Continue" class="button">
</form>
</div>
</div>
With the current example, i've got the text field set to being visible, so I can see what's going on.. But this is where it gets strange.
What i'm getting is two different types of results.
The first, is that when I echo the serialized array outside a input field. I get the desired results:
a:6:{s:8:"Username";s:1:"s";s:8:"Password";s:1:"4";s:9:"cpassword";s:1:"4";s:5:"email";s:3:"asd";s:8:"Referral";s:3:"asd";s:6:"submit";s:8:"Continue";}
The second is when I use the following:
<input type="text" name="SubmitInfo" value="<?php echo serialize($_POST); ?>">
Which passes an invalid serialized array to page 3 breaking the whole process.
I assume it's not a HTML related error, but the new line break in the serialized array definition a:6. I have made an attempt to rectify this problem by removing the new line break with str_replace:
$Ser = serialize($_POST);
$Ser = nl2br($Ser);
$Ser = str_replace("<br>","00",$Ser);
echo $Ser;
which has proven not to work.
This is not a direct solution of your problem, but have you tried json_encode or avoiding the hidden field by storing the date into $_SESSION?

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 :)

HTML/PHP Form not working

I have a HTML Form that uses partial PHP to grab the value, the form is basically like an edit account details form.
The Problem
I cannot work out why the form is not working and when using notepad++ to edit my code if I click on the it shows the start to be a DIV which just confuses the matter even more... When submitting the form it takes you back to the form page with no message so I am lost for a reason..
Form Page
<form method="POST" action="dev.php">
<!-- Row -->
<div class="row-fluid">
<!-- Column -->
<div class="span6">
<!-- Group -->
<div class="control-group">
<label class="control-label" for="fname">First name</label>
<div class="controls">
<input type="text" name="fname" id="fname" value="<?php echo $user_fname; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="First name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
<!-- Group -->
<div class="control-group">
<label class="control-label" for="lname">Last name</label>
<div class="controls">
<input type="text" name="lname" id="lname" value="<?php echo $user_sname; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="Last name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
</div>
<!-- // Column END -->
<!-- Column -->
<div class="span6">
<!-- Group -->
<div class="control-group">
<label class="control-label" for="email">Email Address</label>
<div class="controls">
<input type="text" name="email" id="email" value="<?php echo $user_email; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="First name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
<!-- Group -->
<div class="control-group">
<label class="control-label" for="phonenumber" >Phone Number:</label>
<div class="controls">
<input type="text" name="phonenumber" id="phonenumber" value="<?php echo $user_number; ?>" class="span10" />
</div>
</div>
<!-- // Group END -->
</div>
<!-- // Column END -->
</div>
<!-- // Row END -->
<div class="separator line bottom"></div>
<!-- Group -->
<div class="control-group row-fluid">
<label class="control-label" for="bio">About me</label>
<div class="controls">
<textarea id="bio" name="bio" class="span12" rows="5"><?php echo $user_bio;?></textarea>
</div>
</div>
<!-- Form actions -->
<div class="form-actions" style="margin: 0;">
<button type="submit" id="accountdetails" name="accountdetails" class="btn btn-icon btn-primary glyphicons circle_ok"><i></i>Save changes</button>
</div>
</div>
</form>
<!-- // Form actions END -->
dev.php
if (isset($_POST['accountdetails'])) {
if (isset($_POST['fname']) || isset($_POST['lname']) || isset($_POST['email']) || isset($_POST['phonenumber']) || isset($_POST['bio'])) {
die ("HERE");
};
};
I probably need to drink more Coffee but I cannot for the life of me work out why it is not working.
Any help would be appreciated!
Thanks in advance.
EDIT
I put the name's in and this did not help, now the URL of the page shows this:
update.php?fname=Aaron&lname=Hatton&email=me%40aaronhatton.co.uk&phonenumber=0123456789&bio=+18+%7C+London+%7C+Taken&accountdetails=
any ideas?
One: do what Fred said (name attributes on your input tags).
Two: You're missing the </form> tag at the end.
Your form page seems correct, however, since the form updates the user data, look what the dev.php code is doing:
isset() function returns true if the value is set and you manual set the fields so it will evaluate to true.
and in your if statement you are ORing all the conditions so as soon as it finds 1 true condition, it will go into the if statement body and execute die which will do nothing.
so if you want to test, instead of using die, try echo "here" to see if a message is printed.
So I found out the form works perfect and there was some AJAX being used by another coder, removed and surprise surprise it works perfectly!
Damn co-workers!
Thanks to all that helped!

Html form posting, no data passed on [duplicate]

This question already has answers here:
Does form data still transfer if the input tag has no name?
(3 answers)
Closed 5 years ago.
I've been sitting with this problem for a while now, can't seem to figure out whats wrong with the code.
The problem is that no data gets posted from the form to the script.
<div class="mws-panel-body">
<form class="mws-form" action="blueprints/add" method="post" id="pForm">
<div class="mws-form-inline">
<div class="mws-form-row">
<label>Blueprint name</label>
<div class="mws-form-item small">
<input type="text" class="mws-autocomplete mws-textinput" id="pName" value="" />
<div>The name of the blueprint, search completion is enabled.</div>
</div>
</div>
<div class="mws-form-row">
<label>Hangar</label>
<div class="mws-form-item micro">
<select id="pHangar">
<option value="0" selected>Personal</option>
<option value="1">Corporation</option>
</select>
<div>Indicates who the blueprint belongs to.</div>
</div>
</div>
<div class="mws-form-row">
<label>State</label>
<div class="mws-form-item micro">
<select id="pState">
<option value="1" selected>Original</option>
<option value="0">Copy</option>
</select>
<div>The state of the blueprint, be it original or a copy.</div>
</div>
</div>
<div class="mws-form-row">
<label>Productions runs</label>
<div class="mws-form-item small">
<input type="text" class="mws-textinput" id="pRuns" value="0" />
<div>The number of production runs left on copy.</div>
</div>
</div>
<div class="mws-form-row">
<label>Material efficiency</label>
<div class="mws-form-item small">
<input type="text" class="mws-textinput" id="pME" value="0" />
<div>The current material efficiency level of the blueprint.</div>
</div>
</div>
<div class="mws-form-row">
<label>Production efficiency</label>
<div class="mws-form-item small">
<input type="text" class="mws-textinput" id="pPE" value="0" />
<div>The current production efficiency level of the blueprint.</div>
</div>
</div>
</div>
<div class="mws-button-row">
<input type="submit" value="Add blueprint" class="mws-button blue" />
<input type="reset" value="Reset" class="mws-button gray" />
</div>
</form>
</div>
It seems to be a problem with the form itself, as if the form is set to get, it just enters the script with a question-mark only, blueprints/add?, meaning no data gets passed on at all.
Any pointers or suggestions will be appreciated.
My platform is PHP if that helps.
You should be using the name attribute of input to send the data to a PHP post script. Example:
Form:
<form action="add.php" method="post">
<input type="text" name="firstname" />
</form>
Script (add.php):
<?php
//print the $_POST['firstname'] variable
echo $_POST['firstname'];
?>
You need to add the name attribute to your input and select elements
<input type="text" name="myinput">
Php will then build your $_POST array with those names.

Categories