Hello I'm trying to get back into coding and I've hit a problem that I need some help with. I've created a form with HTML5 so it has the built in required fields and i can get this to post to a database but I currently have the POST on a different page so that I can just have words saying Submit complete but currently you can just go to that submit page over and over and it will just send off blank fields to my database so I wanted to check the post as a whole to see if the whole thing is empty then not submit but I don't know if this is the best way to do it.
thanks if you need my current PHP just shout and ill put it on.
First of all validate your form fields with Javascript or Jquery validation for client side validation. Its very easy, you can use jquery validation plugin eg.
Jquery Form Validation
For Server side validation you can use php functions like isset($_POST['field_name']) and !empty($_POST['field_name'])
For PHP form validation please visit the link for reference : PHP Form Validation
Related
I am sorry for the stupid question, I realize that what I want to do must be extremely simple, but I can't find my way to do it.
I learned basic programing, mostly front end, and enough php to interact with databases and other basics. I can use jquery, javascrip, ajax, no problem in normal situations. But I am not fluent at all in using object-oriented php and I work on a Yii environment.
I have a contact form on the website I'm working on and it works perfectly sending the data to the database. Now I have to re-create the same form, and use it on a pop up box, but I have no idea how to do the php validation and saving to the database in that situation. I've always used Ajax and I tried it, but apparently you need special synthax with ajax on Yii that I am not familiar with.
So is there any way to have the php validation and saving being performed without ajax, (and without the form submitting that refreshes the page and closes the lightbox)?
"Popups": http://jqueryui.com/dialog/
ClientSide validation: http://jqueryvalidation.org/
PHP-Validation: Easiest Form validation library for PHP?
After everything I tried, because I don't know the Yii framework enough to use ajax in their synthax, I found a way to make my form work with simple jQ.
I have an empty onsubmit attribute on my form, that will change to "return false" if there are errors in the js validation, keeping the page from refresh and showing the errors. And if there aren't errors the form will submit the info to php validation then save to the database and all the php will be executed and the lightbox will re-open with the success message.
I have a bit of a problem achieving what I'm trying to do.
I'm doing a mailbox like page and I'd like to add a "Respond" button which will fill a form with some values.
I'm generating my page message by message in php. For each message I generate an input button with its own id and when I click on the button, I'd like to open a form in a new window, with the recipient and title prefilled and not changeable by the user, with another textarea that the user can fill with his message.
For that, I have a general template for a form containing 3 values (recipient, title and message). All are (for the moment) text or textarea values.
Is it possible to use one form to send a message to anyone, or do I have to generate a form for each message with pre filled values ? The last solution seems quite horrible to do.
I tried to find something that I could do with only javascript, since I want the form to be submitted asynchronously by Ajax.
I can make an onClick event and pass the values to that function, but in that case I won't have the values of the textarea the user will have entered.
Is there a way to do, for example, an entire form in Javascript with the values I'll pass through the onClick event, get the value of the textarea from the form that would have been populated with these values, and then send everything through Ajax ?
Well, here is what I did.
For each Respond button generated, I set an onClick event passing the fields I wanted to be pre-filled in my form to a JS function RespondMessage()
I also made a form at the bottom of my page that I hid with css.
This form contains as much hidden fields as I want pre-filled datas, and as much spans as I want to show infos.
When I call the RespondMessage function, I manually set the hidden fields in my form with the arguments I called the function with.
After that I fill my spans with the infos I want to show (for example, I set the recipient's name for my message like that).
Once all of that is done, your form is ready to be displayed. So after setting the fields in the form, I just pass the form from display:none to display:block, and do a lot of css tricks to make that smooth and beautiful.
So now you have your pre-filled form, you just need another function that will make an Ajax call to avoid reloading the page after each response, and you'll call it with the onClick event of your form's submission button.
I hope that this process will help someone.
I'm not quite sure that it's the best way to do it and I find it quite dirty and exploitable so you need a bit more server side checking than usual, but it does the job.
I don't provide code because it's mostly all really specific to the application you're setting up.
I am new to html, I would be really glad if you can help me with this.
I have a web page where there is a list and some other text inputs and buttons. This option list can be populated by clicking the "add" button in the page, this add button is to direct to another page and in that page there are some chekboxes, those which are checked are loaded back to the main page,(where I have the list) .
At the end data in the main page needs to be loaded to the database, (what is in the list and in the text inputs).
Since I'm new I just know little about php and html, I thought I should have a form within a another form(form to "add items", form to load to the database) and it is not possible in html. Can anyone suggest the best way to do this? Do I need to use javascript?
Why can't the extra inputs (the ones that would be in the second form) be part of the first form? I think the question will become clearer if you post a sample form so we can see the relationship between the two forms.
But overall, since you're ultimately only submitting one form, then maybe all the inputs belong together. If what you're calling the second form isn't supposed to be visible right away, you can still have it be part of the same form, but only reveal it when needed.
Again, some sample data would help to understand the exact context of your question.
in php if you use input name="somename[]"
for a number of input elems
you will get an array in $_POST['somename'] and access all the values.
I think what you're after - if I understand you correctly - is ajax. Ajax allows you to asynchronously send data to/from another script without leaving the current page. This is accomplished using JavaScript. In your case I think what you need to do is set an onclick event in JavaScript to a button:
<input type="button" onclick="javascriptFunction()">
You can read more about ajax here:
http://www.tizag.com/ajaxTutorial/ajaxform.php
I am trying to find a way that I can have a user fill out a small form on my site and then on submit link to an external form (that I have no control over) and populate the information that has already been entered.
Is this even possible? my initial though is using Javascript to append the information to the url but then how would i retrieve it? Maybe using an iframe?
any help would be appreciated!
EDIT:
I wanted to clarify. i would like tthe fields of the external form to autopoulate the information they entered on my site so that the visitor could enter the other info that I dont need. Can I do that with cURL?
It's possible in JavaScript. If you know what the output will be in 'external submit' you can filter it and print this out on your site. Than it's ajax related.
Another way is curl, with PHP. With some Regular expression you can filter out the information you need on your own site.
I am trying to do something really basic but can not seem to find a tutorial for it.
I have created a simple web form using HTML what I need todo is create a php file that will read the web form, open a new browser window (or display in same page) the contents of the web form, do toy guys have any tutorials on this?
Many thanks
Chris
I'm sure many will post different links to tutorials that they like, but I thought I would just give you the basic. The key parts to the form are the method and action. The Method attribute tells ths browser how to submit the data, either through GET or POST. The action attribute tells the browser where to submit the form. (In your case it will be, somepage.php) If you ever need the form to submit back to itself, you can here use explicitly type the page name or you can use use PHP to dynamically insert the page name. Finally, make sure that all your form fields use the name attribute, as this is how php will access the elements.
On the php side of things, your form variables will be stored in either $_GET or $_POST depending on how on method you used to submit your form. For example, assume you have a input element of type text with the name 'FirstName'. Within php you can access this by doing
<?php
var firstName = $_GET['FirstName'];
?>
This should be enough to get you started. Be sure to check out the php docs and the other tutorials listed on this page for a more details.
Please look at this tutorial: http://www.learnphp-tutorial.com/HtmlForms.cfm
And you can find many more tutorials if you search it on Google.
This should help : http://www.php-mysql-tutorial.com/wikis/php-tutorial/php-forms.aspx