Update values in textbox on Submit?? PHP - php

I have a PHP web page. Initially, the values in the text box are retrieved from a LDAP directory based on the user login information. The user makes any required changes in the values and on clicking submit the values in the text box get updated and also the values in the Directory get updated as well( I have got this part done). I am new to PHP and I am trying to figure out how to update the values in the text box on submit.

With PHP you can only do changes on submit when you do a AJAX call to the server. However, you can do changes using only PHP after submitting it on the server side.
Updating in the browser directly "onsubmit" is not possible without the help of JavaScript.

You want to take the values the user has submitted and redisplay them in your text field.
Something like
<input type="text" name="phone_num" id="phone_num" value="<?php (isset($_POST['phone_num']) ? $_POST['phone_num'] : $valueFromLDAPDir) ?>" />

Related

make data no-editable but remain readable on a click of button in php mysql

I am a beginner and successfully connected a php page with mysql. the page displays fields for users to edit/enter data. Now I want to provide users a button at the click of this button, the user can no longer edit the data but can see without any difficulty.
I dont want to use locking table since there may be other data from other pages that has to be edited.
Add the attribute readonly="readonly" to all your input elements, or disable your form by adding the disabled="disabled" attribute to your form element.

Passing post data from one form to second form in CodeIgniter

I have a simple lead collection form that asks for the user's zip code on the first page, and then based on which state that zip code is in it sends them to the second page of my form with the zip code already populated, or to another site. In my pre-CodeIgniter days this was a very simple thing to do, but I'm not sure how to send the zip code data from my routing script to the second page of my form and not have it mess with CI's form validation. The second page of my form currently looks like this:
<input type="text" name="zip"value="<?php echo set_value('zip'); ?>" />
So if the user submits invalid data on the second page, the form reloads with all the data pre-populated (using CI's set_value function). But what needs to happen is something like...
IF the user comes from page 1 of the form, populate the zip code field using the data from form 1. ELSE, re-populate it after a failed form submit.
Is there some way for set_value to intelligently work in both situations? If not, do I need to use a different function? I'm also not sure how to pass the zip code data from my routing script to the controller for page 2 of the form.
I'd really appreciate any help. THANK YOU!!

Unable to pre populate form with url

I am trying to pre-populate a set of form fields by passing info via parameters in the URL. I have been able to do this with html forms before by simply adding the parameters to the URL, for example ?name=John. The variable I enter usually appears in the form field.
I am finding that this approach is not working on the latest form. I have been able to identify the parameter names but when I add them to the end of the URL they are not populated in to the form.
For example using website.co.uk/admin/usersearch.php?email=test#test.com I would expect the email field to be populated with test#test.com but the page refreshes and the form is still blank.
Is this because it is a .php form? Is there anyway round this? I only have the options to use the URL or javascript.
Thanks
Give your field value as <?php echo $_GET['email'];?>
Like this :
<input type="text" name="email" value="<?php echo $_GET['email'];?>" />
There is no such default procedure for pre-populating form fields built in to any web server. So, I'm not sure how you got it working earlier. Maybe the developer had actually coded it such that the form pre-population occurred.
For the new form, you could do as Prasanth suggested. However, since you require only JavaScript or HTML, refer to this prior question for further assistance: How to retrieve GET parameters from javascript?
Basically, what you'll be doing is getting the value of the field from the url and setting the field's value to it in the form using JavaScript.

Preserving data over multiple form submission

I am building a web service in which a user can login to a backend, submit a form and then other users will be able to see this information on the front-end of the web service.
The data is submitted to the PostgreSQL database fine BUT on the second submission of the form (users can go back to the form and update their information if neccessary) if there is a blank field in the form, the existing data in the form is overwritten with blank data.
How can I avoid this? I think it would be good to populate the form fields with data from the database and allow the user to edit the form like that but I am unsure how to implement this using PHP. At the moment a user would have to fill out the form in full over and over to prevent this kind of data loss.
Could someone give me an idea or point me in the right direction?
pre-fill the form fields with earlier entries from the DB
<input type="text" value="<?php echo $fname;?>" name="first_name" id="first_name" />

How to load database content using Select box without button & javaScript

I'm making an administrative page for a website, for editing front-end contents. I don't want to use JavaScript, I want to make it with raw PHP.
The thing is: The user will choose a page from the select box, and the contents according to the page will be loaded into two text boxes. Then the user will edit them on text boxes and update the contents using an update button.
(there is no submit button for the select box, I want 'onselect' data content load)
I need, the user will simply select a page, no button to be pressed then and the content will be loaded. I want not to deploy JavaScript for this. Is it possible using raw PHP? Any suggestion?
PHP is a server side programming language. You can't really affect the client side directly, only indirectly through forms etc.
If you accept your users may have to use the enter key, which will submit the form, you're fine.
But you can't have an action occurring on a select, without even using the enter key, without javascript.
Note that the requirement to not use javascript, especially for an administrative tool, doesn't make sense.
Yes, it's possible with raw PHP, but I do not recommend it.
You can put the select-box inside a
<form action="targetFile.php" method="GET">
To submit the form without a submit-button, you can use:
<select name="sel" onChange="this.form.submit()">
When the form is submitted, the browser loads the site "targetFile.php"
On this site, you can use php to set the text-box content:
<input type="text" value="
<?php
if($_GET['sel'] == 0) echo "content1";
else echo "content2";
?>
">
If you want to load the content dynamically (without realoading a site) you have to use Javascript and maybe Ajax.

Categories