/    Sign up×
Community /Pin to ProfileBookmark

prevent form fields from clearing after submit

i have form fields in ajax . after submitting i need the values remain constant ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@hastxApr 08.2013 — Hold the form values in an array with blank values. Then if the page has been posted load those values into the placeholders in the array.

[code=php]
$frm_vals = array(
'name'=>'',
'addy'=>'',
'phone'=>''
);

if($_POST){
foreach($frm_vals as $key=>$val){
$frm_vals[$key] = $_POST[$key];
}
}
[/code]


Now you have form values for the inputs...if the page has been posted then the values will be filled, or else they will be blank...you inputs would look like

[code=php]
echo "<input name="name" value="".$frm_vals['name']."">";
[/code]


if using ajax you could do the same thing by returning the array values as JSON instead of hard-coding the form with PHP.
×

Success!

Help @mohanapriya spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...