×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

foms in php problem
2

foms in php problem

foms in php problem

(OP)
Why does this show me the fields required message?

CODE

$urlstr = filter_input(INPUT_POST, 'urlstr');
$shippingcost = filter_input(INPUT_POST, 'shipping');

if (!empty($urlstr) && !empty($shippingcost))
{
   .....do code
}
elseif(isset($_POST['Submit'])) 
{
	echo "both fields required<br>";
}
else
{
   display form at astart...
} 

RE: foms in php problem

Where is INPUT_POST defined and how?

Bye, Olaf.

RE: foms in php problem

Hi

Quote (Olaf)

Where is INPUT_POST defined and how?
In the filter extension.

( Me playing the wise guy. But I also had to look it up first... )

Feherke.
feherke.ga

RE: foms in php problem

Quote:

Why does this show me the fields required message?

Because you check for them being empty before you check for the form being submitted.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: foms in php problem

(OP)
So the code is correct its just the structure

RE: foms in php problem

Thanks, Feherke, I should have looked it up myself.

Well, assume the form is not submitted, then the elements are empty, so elseif runs, should detect no submit, so the last branch creating the form should run. I would check for submit first, too, though.

Bye, Olaf.

RE: foms in php problem

The ideal order of server-side form verification should be;


check for submit -> check for 'bot' submit -> check values -> process data

then should any step fail you can exit with an appropriate error code or message without trying to process unnecessarily or process erroneous data.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: foms in php problem

(OP)
What is wrong with this please? have two fields and both must have value but im getting lost, I have the submit button and the values think about and the form to display

CODE

$urlstr = filter_input(INPUT_POST, 'urlstr');
$shipcost = filter_input(INPUT_POST, 'shipcost');

if(!empty($urlstr) && !empty($shippingcost))
{
	echo $urlstr;
}
 elseif(isset($_POST['submit']) && empty($urlstr))
{
		echo "Enter url";
} 
else
{
?>
	 <form action="import.php" method="post">
	 <br><input type="text" name="shipcost" size=28 value="Enter Shipping Cost ie: 4.50" onclick="this.value=''"><br>
	 <br><input type="text" name="urlstr" size=180 value="Enter URL from Address bar top of the browser" onclick="this.value=''"><br>
	 
	  <input type="Submit">
	 </form>
	<?php
}
?> 

RE: foms in php problem

(OP)
even this don't work, just keeps going back to the form

CODE

$urlstr = filter_input(INPUT_POST, 'urlstr');
$shipcost = filter_input(INPUT_POST, 'shipcost');

if(isset($_POST['submit']))
{
	if(!empty($urlstr) && !empty($shipcost))
	{
		echo $urlstr;
	}
	 else
	{
			echo "Both fields must be entered";
	} 
}
else
{
?>
	 <form action="import.php" method="post">
	 <br><input type="text" name="shipcost" size=28 value="Enter Shipping Cost ie: 4.50" onclick="this.value=''"><br>
	 <br><input type="text" name="urlstr" size=180 value="Enter URL from Address bar top of the browser" onclick="this.value=''"><br>
	 
	  <input type="Submit">
	 </form>
	<?php
}
?> 

RE: foms in php problem

CODE

var_dump($_POST); 
See whether you spot s 'submit' element in that array dump.
Not?
Simple reason: $_POST['submit'] is never set, because you didn't give th Submit button the NAME 'submit'. The associative $_POST array only contains named form elements with their name as the element name.

Bye, Olaf.

RE: foms in php problem

(OP)
you mean like this?

<input type="Submit" name="submit">

RE: foms in php problem

(OP)
form elements, yup! consider this solved.

RE: foms in php problem

(OP)
....mmmh.. what does this var_dump say about my button?

CODE

array(3) { ["shippingcost"]=> string(0) "" ["urlstr"]=> string(0) "" ["submit"]=> string(12) "Submit Query" } 

RE: foms in php problem

Quote:

....mmmh.. what does this var_dump say about my button?

It says you have 3 values. 2 of which are empty (shippingcost, and urlstr), and a third one named "submit" that has a 12 character value of "Submit Query".



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: foms in php problem

Quote:

....mmmh.. what does this var_dump say about my button?

var_dump($_POST) is not about your button, it's about the whole $_POST array. You have three input controls, so you have three array elements.
Submit Query is your submit button caption, obviously.

If you don't know that $_POST contains the other inputs, too, you haven't understood your own filter_input() calls.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close