简体   繁体   中英

How to create contact us form in iphone

I have create a contact us form there are three textfields(name,email,phone no) in form and 1 textview(message) and 1 actionbutton in my form. I have put all the validations on form but my problem is that when someone fill my form and press the action button then all information in the form should send on my personal mail id. Kindly write the code for me to submit the mail

#import "ViewController.h"

@implementation ViewController
@synthesize name, phone_no,email,message,mylabel;

-(IBAction)submit:(id)sender

{
    NSString *ename = [[NSString alloc] initWithString:name.text];
    NSString *ephone = [[NSString alloc] initWithString:phone_no.text];
    NSString *eemail = [[NSString alloc] initWithString:email.text];
    NSString *emessage = [[NSString alloc] initWithString:message.text];
    if([ename isEqualToString:@""] && [ephone isEqualToString:@""] && [eemail isEqualToString:@""] && [emessage isEqualToString:@""] ) 
    {
        mylabel.text = @"enter all the field";
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Enter all fields" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([ename isEqualToString:@""])
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Must Enter your name" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([ephone isEqualToString:@""])
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Must Enter your Phone" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([eemail isEqualToString:@""] )
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Must Enter your email" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([emessage isEqualToString:@""] || emessage.length < 30)
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"your message lenght not less then 100" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else 
    {
        mylabel.text = @"login success";
    }

    [ename release];
    [ephone release];
    [eemail release];
    [emessage release];
    [alert release];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
 replacementText:(NSString *)text
{
    // Any new character added is passed in as the "text" parameter
    if ([text isEqualToString:@"\n"]) {
        // Be sure to test for equality using the "isEqualToString" message
        [textView resignFirstResponder];

        // Return FALSE so that the final '\n' character doesn't get added
        return FALSE;
    }
    // For any other character return TRUE so that the text gets added to the view
    return TRUE;
}

- (IBAction)textFieldShouldReturn:(id) sender
{
    [name resignFirstResponder];
    [phone_no resignFirstResponder];
    [email resignFirstResponder];
}

- (IBAction)fields:(id) sender
{
    [sender resignFirstResponder];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
@END

Hello here frame work for creating the custom form and you can customize for your requirement below is the link for the custom form creating.

1) QuickDialog

2) IBAForms

May this help lot to development.

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setToRecipients:[In Array your email Id]]; // to add your default email id.

    NSString *emailBody = @"add your text in emailBody";  
    [picker setMessageBody:emailBody isHTML:YES];
    [self presentModalViewController:picker animated:YES];
    [picker release];

After your all condition check you can open MFMailComposeViewController using this code and do not forget to delegate MFMailComposeViewController in header file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM